@@ -21,16 +21,88 @@ suite("TableRangePrettyfier tests", () => {
2121 assert . equal ( textEdits . length , 0 ) ;
2222 } ) ;
2323
24- test ( "provideDocumentRangeFormattingEdits() table factory called with invalid table then logInfo() called" , ( ) => {
25- const tableText = `hello | world
26- -|-
27- new | line ` ;
24+ test ( "provideDocumentRangeFormattingEdits() invalid table with whole document being formatted => logInfo() not called" , ( ) => {
25+ const tableText = `row1
26+ row2
27+ row3 ` ;
2828 const mockTableFactory : typeMock . IMock < ITableFactory > = typeMock . Mock . ofType < ITableFactory > ( ) ;
2929 const mockLogger : typeMock . IMock < ILogger > = typeMock . Mock . ofType < ILogger > ( ) ;
3030 const trp = new TableRangePrettyfier ( mockTableFactory . object , mockLogger . object ) ;
3131
3232 const textDoc = new MockMarkdownTextDocument ( tableText ) ;
33- const range = textDoc . getRangeForLines ( 1 , 3 ) ;
33+ const range = textDoc . getRangeForLines ( 0 , 3 ) ;
34+ mockTableFactory
35+ . setup ( t => t . create ( textDoc . getText ( range ) ) )
36+ . returns ( ( ) => null )
37+ . verifiable ( Times . once ( ) ) ;
38+ mockLogger
39+ . setup ( t => t . logInfo ( It . isAnyString ( ) ) )
40+ . verifiable ( Times . never ( ) ) ;
41+
42+ const textEdits = trp . provideDocumentRangeFormattingEdits ( textDoc , range , null , null ) ;
43+
44+ mockTableFactory . verifyAll ( ) ;
45+ mockLogger . verifyAll ( ) ;
46+ } ) ;
47+
48+ test ( "provideDocumentRangeFormattingEdits() error thrown with whole document being formatted => logError() not called" , ( ) => {
49+ const tableText = `row1
50+ row2
51+ row3` ;
52+ const mockTableFactory : typeMock . IMock < ITableFactory > = typeMock . Mock . ofType < ITableFactory > ( ) ;
53+ const mockLogger : typeMock . IMock < ILogger > = typeMock . Mock . ofType < ILogger > ( ) ;
54+ const trp = new TableRangePrettyfier ( mockTableFactory . object , mockLogger . object ) ;
55+
56+ const textDoc = new MockMarkdownTextDocument ( tableText ) ;
57+ const range = textDoc . getRangeForLines ( 0 , 3 ) ;
58+ mockTableFactory
59+ . setup ( t => t . create ( textDoc . getText ( range ) ) )
60+ . throws ( new Error ( "expected error" ) )
61+ . verifiable ( Times . once ( ) ) ;
62+ mockLogger
63+ . setup ( t => t . logError ( It . isAny ( ) ) )
64+ . verifiable ( Times . never ( ) ) ;
65+
66+ const textEdits = trp . provideDocumentRangeFormattingEdits ( textDoc , range , null , null ) ;
67+
68+ mockTableFactory . verifyAll ( ) ;
69+ mockLogger . verifyAll ( ) ;
70+ } ) ;
71+
72+ test ( "provideDocumentRangeFormattingEdits() error thrown without whole document being formatted => logError() called" , ( ) => {
73+ const tableText = `row1
74+ row2
75+ row3` ;
76+ const mockTableFactory : typeMock . IMock < ITableFactory > = typeMock . Mock . ofType < ITableFactory > ( ) ;
77+ const mockLogger : typeMock . IMock < ILogger > = typeMock . Mock . ofType < ILogger > ( ) ;
78+ const trp = new TableRangePrettyfier ( mockTableFactory . object , mockLogger . object ) ;
79+
80+ const textDoc = new MockMarkdownTextDocument ( tableText ) ;
81+ const range = textDoc . getRangeForLines ( 2 , 3 ) ;
82+ mockTableFactory
83+ . setup ( t => t . create ( textDoc . getText ( range ) ) )
84+ . throws ( new Error ( "expected error" ) )
85+ . verifiable ( Times . once ( ) ) ;
86+ mockLogger
87+ . setup ( t => t . logError ( It . isAny ( ) ) )
88+ . verifiable ( Times . once ( ) ) ;
89+
90+ const textEdits = trp . provideDocumentRangeFormattingEdits ( textDoc , range , null , null ) ;
91+
92+ mockTableFactory . verifyAll ( ) ;
93+ mockLogger . verifyAll ( ) ;
94+ } ) ;
95+
96+ test ( "provideDocumentRangeFormattingEdits() invalid table with not the whole document being formatted => logInfo() called" , ( ) => {
97+ const tableText = `row1
98+ row2
99+ row3` ;
100+ const mockTableFactory : typeMock . IMock < ITableFactory > = typeMock . Mock . ofType < ITableFactory > ( ) ;
101+ const mockLogger : typeMock . IMock < ILogger > = typeMock . Mock . ofType < ILogger > ( ) ;
102+ const trp = new TableRangePrettyfier ( mockTableFactory . object , mockLogger . object ) ;
103+
104+ const textDoc = new MockMarkdownTextDocument ( tableText ) ;
105+ const range = textDoc . getRangeForLines ( 2 , 3 ) ;
34106 mockTableFactory
35107 . setup ( t => t . create ( textDoc . getText ( range ) ) )
36108 . returns ( ( ) => null )
@@ -46,9 +118,9 @@ suite("TableRangePrettyfier tests", () => {
46118 } ) ;
47119
48120 test ( "provideDocumentRangeFormattingEdits() table prettyPrint() called and logInfo() not called" , ( ) => {
49- const tableText = `hello | world
50- -|-
51- new | line ` ;
121+ const tableText = `row1
122+ row2
123+ row3 ` ;
52124 const mockTableFactory : typeMock . IMock < ITableFactory > = typeMock . Mock . ofType < ITableFactory > ( ) ;
53125 const mockLogger : typeMock . IMock < ILogger > = typeMock . Mock . ofType < ILogger > ( ) ;
54126 const mockTable : typeMock . IMock < ITable > = typeMock . Mock . ofType < ITable > ( ) ;
@@ -76,9 +148,9 @@ suite("TableRangePrettyfier tests", () => {
76148 } ) ;
77149
78150 test ( "provideDocumentRangeFormattingEdits() the result of the prettyPrint() is returned" , ( ) => {
79- const tableText = `hello | world
80- -|-
81- new | line ` ;
151+ const tableText = `row1
152+ row2
153+ row3 ` ;
82154 const mockTableFactory : typeMock . IMock < ITableFactory > = typeMock . Mock . ofType < ITableFactory > ( ) ;
83155 const mockLogger : typeMock . IMock < ILogger > = typeMock . Mock . ofType < ILogger > ( ) ;
84156 const mockTable : typeMock . IMock < ITable > = typeMock . Mock . ofType < ITable > ( ) ;
0 commit comments