@@ -29,20 +29,20 @@ namespace ts.textStorage {
2929 for ( let offset = 0 ; offset < end - start ; offset ++ ) {
3030 const pos1 = ts1 . lineOffsetToPosition ( line + 1 , offset + 1 ) ;
3131 const pos2 = ts2 . lineOffsetToPosition ( line + 1 , offset + 1 ) ;
32- assert . isTrue ( pos1 === pos2 , `lineOffsetToPosition ${ line + 1 } -${ offset + 1 } : expected ${ pos1 } to equal ${ pos2 } ` ) ;
32+ assert . strictEqual ( pos1 , pos2 , `lineOffsetToPosition ${ line + 1 } -${ offset + 1 } : expected ${ pos1 } to equal ${ pos2 } ` ) ;
3333 }
3434
3535 const { start : start1 , length : length1 } = ts1 . lineToTextSpan ( line ) ;
3636 const { start : start2 , length : length2 } = ts2 . lineToTextSpan ( line ) ;
37- assert . isTrue ( start1 === start2 , `lineToTextSpan ${ line } ::start:: expected ${ start1 } to equal ${ start2 } ` ) ;
38- assert . isTrue ( length1 === length2 , `lineToTextSpan ${ line } ::length:: expected ${ length1 } to equal ${ length2 } ` ) ;
37+ assert . strictEqual ( start1 , start2 , `lineToTextSpan ${ line } ::start:: expected ${ start1 } to equal ${ start2 } ` ) ;
38+ assert . strictEqual ( length1 , length2 , `lineToTextSpan ${ line } ::length:: expected ${ length1 } to equal ${ length2 } ` ) ;
3939 }
4040
4141 for ( let pos = 0 ; pos < f . content . length ; pos ++ ) {
4242 const { line : line1 , offset : offset1 } = ts1 . positionToLineOffset ( pos ) ;
4343 const { line : line2 , offset : offset2 } = ts2 . positionToLineOffset ( pos ) ;
44- assert . isTrue ( line1 === line2 , `positionToLineOffset ${ pos } ::line:: expected ${ line1 } to equal ${ line2 } ` ) ;
45- assert . isTrue ( offset1 === offset2 , `positionToLineOffset ${ pos } ::offset:: expected ${ offset1 } to equal ${ offset2 } ` ) ;
44+ assert . strictEqual ( line1 , line2 , `positionToLineOffset ${ pos } ::line:: expected ${ line1 } to equal ${ line2 } ` ) ;
45+ assert . strictEqual ( offset1 , offset2 , `positionToLineOffset ${ pos } ::offset:: expected ${ offset1 } to equal ${ offset2 } ` ) ;
4646 }
4747 } ) ;
4848
@@ -52,16 +52,93 @@ namespace ts.textStorage {
5252 const ts1 = new server . TextStorage ( host , server . asNormalizedPath ( f . path ) , /*initialVersion*/ undefined , /*info*/ undefined ! ) ;
5353
5454 ts1 . getSnapshot ( ) ;
55- assert . isTrue ( ! ts1 . hasScriptVersionCache_TestOnly ( ) , "should not have script version cache - 1" ) ;
55+ assert . isFalse ( ts1 . hasScriptVersionCache_TestOnly ( ) , "should not have script version cache - 1" ) ;
5656
5757 ts1 . edit ( 0 , 5 , " " ) ;
5858 assert . isTrue ( ts1 . hasScriptVersionCache_TestOnly ( ) , "have script version cache - 1" ) ;
5959
6060 ts1 . useText ( ) ;
61- assert . isTrue ( ! ts1 . hasScriptVersionCache_TestOnly ( ) , "should not have script version cache - 2" ) ;
61+ assert . isFalse ( ts1 . hasScriptVersionCache_TestOnly ( ) , "should not have script version cache - 2" ) ;
6262
6363 ts1 . getLineInfo ( 0 ) ;
6464 assert . isTrue ( ts1 . hasScriptVersionCache_TestOnly ( ) , "have script version cache - 2" ) ;
6565 } ) ;
66+
67+ it ( "should be able to return the file size immediately after construction" , ( ) => {
68+ const host = projectSystem . createServerHost ( [ f ] ) ;
69+ // Since script info is not used in these tests, just cheat by passing undefined
70+ const ts1 = new server . TextStorage ( host , server . asNormalizedPath ( f . path ) , /*initialVersion*/ undefined , /*info*/ undefined ! ) ;
71+
72+ assert . strictEqual ( f . content . length , ts1 . getTelemetryFileSize ( ) ) ;
73+ } ) ;
74+
75+ it ( "should be able to return the file size when backed by text" , ( ) => {
76+ const host = projectSystem . createServerHost ( [ f ] ) ;
77+ // Since script info is not used in these tests, just cheat by passing undefined
78+ const ts1 = new server . TextStorage ( host , server . asNormalizedPath ( f . path ) , /*initialVersion*/ undefined , /*info*/ undefined ! ) ;
79+
80+ ts1 . useText ( f . content ) ;
81+ assert . isFalse ( ts1 . hasScriptVersionCache_TestOnly ( ) ) ;
82+
83+ assert . strictEqual ( f . content . length , ts1 . getTelemetryFileSize ( ) ) ;
84+ } ) ;
85+
86+ it ( "should be able to return the file size when backed by a script version cache" , ( ) => {
87+ const host = projectSystem . createServerHost ( [ f ] ) ;
88+ // Since script info is not used in these tests, just cheat by passing undefined
89+ const ts1 = new server . TextStorage ( host , server . asNormalizedPath ( f . path ) , /*initialVersion*/ undefined , /*info*/ undefined ! ) ;
90+
91+ ts1 . useScriptVersionCache_TestOnly ( ) ;
92+ assert . isTrue ( ts1 . hasScriptVersionCache_TestOnly ( ) ) ;
93+
94+ assert . strictEqual ( f . content . length , ts1 . getTelemetryFileSize ( ) ) ;
95+ } ) ;
96+
97+ it ( "should be able to return the file size when a JS file is too large to load into text" , ( ) => {
98+ const largeFile = {
99+ path : "/a/large.js" ,
100+ content : " " . repeat ( server . maxFileSize + 1 )
101+ } ;
102+
103+ const host = projectSystem . createServerHost ( [ largeFile ] ) ;
104+
105+ // The large-file handling requires a ScriptInfo with a containing project
106+ const projectService = projectSystem . createProjectService ( host ) ;
107+ projectService . openClientFile ( largeFile . path ) ;
108+ const scriptInfo = projectService . getScriptInfo ( largeFile . path ) ;
109+
110+ const ts1 = new server . TextStorage ( host , server . asNormalizedPath ( largeFile . path ) , /*initialVersion*/ undefined , scriptInfo ! ) ;
111+
112+ assert . isTrue ( ts1 . reloadFromDisk ( ) ) ;
113+ assert . isFalse ( ts1 . hasScriptVersionCache_TestOnly ( ) ) ;
114+
115+ assert . strictEqual ( largeFile . content . length , ts1 . getTelemetryFileSize ( ) ) ;
116+ } ) ;
117+
118+ it ( "should return the file size without reloading the file" , ( ) => {
119+ const oldText = "hello" ;
120+ const newText = "goodbye" ;
121+
122+ const changingFile = {
123+ path : "/a/changing.ts" ,
124+ content : oldText
125+ } ;
126+
127+ const host = projectSystem . createServerHost ( [ changingFile ] ) ;
128+ // Since script info is not used in these tests, just cheat by passing undefined
129+ const ts1 = new server . TextStorage ( host , server . asNormalizedPath ( changingFile . path ) , /*initialVersion*/ undefined , /*info*/ undefined ! ) ;
130+
131+ assert . isTrue ( ts1 . reloadFromDisk ( ) ) ;
132+
133+ // Refresh the file and notify TextStorage
134+ host . writeFile ( changingFile . path , newText ) ;
135+ ts1 . delayReloadFromFileIntoText ( ) ;
136+
137+ assert . strictEqual ( oldText . length , ts1 . getTelemetryFileSize ( ) ) ;
138+
139+ assert . isTrue ( ts1 . reloadWithFileText ( ) ) ;
140+
141+ assert . strictEqual ( newText . length , ts1 . getTelemetryFileSize ( ) ) ;
142+ } ) ;
66143 } ) ;
67144}
0 commit comments