@@ -20,20 +20,91 @@ suite("TableRangePrettyfier tests", () => {
2020
2121 assert . equal ( textEdits . length , 0 ) ;
2222 } ) ;
23- /*
23+
2424 test ( "provideDocumentRangeFormattingEdits() table factory called with invalid table then logInfo() called" , ( ) => {
25- const tableText = "hello world";
25+ const tableText = `
26+ hello | world
27+ -|-
28+ new | line
29+ ` ;
2630 const mockTableFactory : TypeMoq . IMock < ITableFactory > = TypeMoq . Mock . ofType < ITableFactory > ( ) ;
2731 const mockLogger : TypeMoq . IMock < ILogger > = TypeMoq . Mock . ofType < ILogger > ( ) ;
28- mockTableFactory.setup(t => t.create(tableText)).returns(null).verifiable(Times.once());
29- mockLogger.setup(t => t.logInfo(It.isAnyString())).verifiable(Times.once());
3032 const trp = new TableRangePrettyfier ( mockTableFactory . object , mockLogger . object ) ;
33+
3134 const textDoc = new mockVsCode . MockMarkdownTextDocument ( tableText ) ;
35+ const range = textDoc . getRangeForLines ( 1 , 4 ) ;
36+ mockTableFactory
37+ . setup ( t => t . create ( textDoc . getText ( range ) ) )
38+ . returns ( ( ) => null )
39+ . verifiable ( Times . once ( ) ) ;
40+ mockLogger
41+ . setup ( t => t . logInfo ( It . isAnyString ( ) ) )
42+ . verifiable ( Times . once ( ) ) ;
3243
33- const textEdits = trp.provideDocumentRangeFormattingEdits(textDoc, textDoc.getFullRange(), null, null);
44+ const textEdits = trp . provideDocumentRangeFormattingEdits ( textDoc , range , null , null ) ;
45+
46+ mockTableFactory . verifyAll ( ) ;
47+ mockLogger . verifyAll ( ) ;
48+ } ) ;
49+
50+ test ( "provideDocumentRangeFormattingEdits() table prettyPrint() called and logInfo() not called" , ( ) => {
51+ const tableText = `
52+ hello | world
53+ -|-
54+ new | line
55+ ` ;
56+ const mockTableFactory : TypeMoq . IMock < ITableFactory > = TypeMoq . Mock . ofType < ITableFactory > ( ) ;
57+ const mockLogger : TypeMoq . IMock < ILogger > = TypeMoq . Mock . ofType < ILogger > ( ) ;
58+ const mockTable : TypeMoq . IMock < ITable > = TypeMoq . Mock . ofType < ITable > ( ) ;
59+ const trp = new TableRangePrettyfier ( mockTableFactory . object , mockLogger . object ) ;
60+
61+ const textDoc = new mockVsCode . MockMarkdownTextDocument ( tableText ) ;
62+ const range = textDoc . getRangeForLines ( 1 , 4 ) ;
3463
64+ mockTable
65+ . setup ( t => t . prettyPrint ( ) )
66+ . verifiable ( Times . once ( ) ) ;
67+ mockTableFactory
68+ . setup ( t => t . create ( textDoc . getText ( range ) ) )
69+ . returns ( ( ) => mockTable . object )
70+ . verifiable ( Times . once ( ) ) ;
71+ mockLogger
72+ . setup ( t => t . logInfo ( It . isAnyString ( ) ) )
73+ . verifiable ( Times . never ( ) ) ;
74+
75+ const textEdits = trp . provideDocumentRangeFormattingEdits ( textDoc , range , null , null ) ;
76+
77+ mockTable . verifyAll ( ) ;
3578 mockTableFactory . verifyAll ( ) ;
3679 mockLogger . verifyAll ( ) ;
3780 } ) ;
38- */
81+
82+ test ( "provideDocumentRangeFormattingEdits() the result of the prettyPrint() is returned" , ( ) => {
83+ const tableText = `
84+ hello | world
85+ -|-
86+ new | line
87+ ` ;
88+ const mockTableFactory : TypeMoq . IMock < ITableFactory > = TypeMoq . Mock . ofType < ITableFactory > ( ) ;
89+ const mockLogger : TypeMoq . IMock < ILogger > = TypeMoq . Mock . ofType < ILogger > ( ) ;
90+ const mockTable : TypeMoq . IMock < ITable > = TypeMoq . Mock . ofType < ITable > ( ) ;
91+ const trp = new TableRangePrettyfier ( mockTableFactory . object , mockLogger . object ) ;
92+
93+ const textDoc = new mockVsCode . MockMarkdownTextDocument ( tableText ) ;
94+ const range = textDoc . getRangeForLines ( 1 , 4 ) ;
95+
96+ mockTable
97+ . setup ( t => t . prettyPrint ( ) )
98+ . returns ( ( ) => "foo bar" ) ;
99+ mockTableFactory
100+ . setup ( t => t . create ( textDoc . getText ( range ) ) )
101+ . returns ( ( ) => mockTable . object )
102+ mockLogger . setup ( t => t . logInfo ( It . isAnyString ( ) ) ) ;
103+
104+ const textEdits = trp . provideDocumentRangeFormattingEdits ( textDoc , range , null , null ) ;
105+
106+ assert . equal ( textEdits . length , 1 ) ;
107+ assert . equal ( textEdits [ 0 ] . newText , "foo bar" ) ;
108+ } ) ;
109+
39110} ) ;
0 commit comments