@@ -5,66 +5,44 @@ describe("extractLinesWithByteLimit", () => {
55 const simpleContent = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5" ;
66
77 it ( "should extract all lines when under byte limit" , ( ) => {
8- const result = extractLinesWithByteLimit ( simpleContent , 0 , 5 , 1000 ) ;
8+ const result = extractLinesWithByteLimit ( simpleContent , 1000 ) ;
99
1010 expect ( result . content ) . toBe ( simpleContent ) ;
11- expect ( result . actualEndLine ) . toBe ( 4 ) ;
1211 expect ( result . wasLimited ) . toBe ( false ) ;
1312 expect ( result . linesRead ) . toBe ( 5 ) ;
1413 } ) ;
1514
16- it ( "should extract partial lines with offset" , ( ) => {
17- const result = extractLinesWithByteLimit ( simpleContent , 2 , 2 , 1000 ) ;
18-
19- expect ( result . content ) . toBe ( "Line 3\nLine 4" ) ;
20- expect ( result . actualEndLine ) . toBe ( 3 ) ;
21- expect ( result . wasLimited ) . toBe ( false ) ;
22- expect ( result . linesRead ) . toBe ( 2 ) ;
23- } ) ;
24-
2515 it ( "should limit output when exceeding byte limit" , ( ) => {
2616 // Create content that will exceed byte limit
2717 const longLine = "x" . repeat ( 100 ) ;
2818 const manyLines = Array ( 10 ) . fill ( longLine ) . join ( "\n" ) ;
2919
30- const result = extractLinesWithByteLimit ( manyLines , 0 , 10 , 250 ) ;
20+ const result = extractLinesWithByteLimit ( manyLines , 250 ) ;
3121
3222 expect ( result . wasLimited ) . toBe ( true ) ;
33- expect ( result . actualEndLine ) . toBe ( 1 ) ; // Should only get 2 lines
3423 expect ( result . linesRead ) . toBe ( 2 ) ;
3524 } ) ;
3625
37- it ( "should handle offset beyond file length" , ( ) => {
38- const result = extractLinesWithByteLimit ( simpleContent , 10 , 5 , 1000 ) ;
39-
40- expect ( result . content ) . toBe ( "" ) ;
41- expect ( result . actualEndLine ) . toBe ( 10 ) ;
42- expect ( result . wasLimited ) . toBe ( false ) ;
43- expect ( result . linesRead ) . toBe ( 0 ) ;
44- } ) ;
45-
4626 it ( "should handle empty content" , ( ) => {
47- const result = extractLinesWithByteLimit ( "" , 0 , 10 , 1000 ) ;
27+ const result = extractLinesWithByteLimit ( "" , 1000 ) ;
4828
4929 expect ( result . content ) . toBe ( "" ) ;
50- expect ( result . actualEndLine ) . toBe ( 0 ) ; // Empty string splits to [""] and we process that one empty line
5130 expect ( result . wasLimited ) . toBe ( false ) ;
5231 expect ( result . linesRead ) . toBe ( 1 ) ; // We read the one empty line
5332 } ) ;
5433
5534 it ( "should handle single line file" , ( ) => {
5635 const singleLine = "This is a single line without newline" ;
57- const result = extractLinesWithByteLimit ( singleLine , 0 , 10 , 1000 ) ;
36+ const result = extractLinesWithByteLimit ( singleLine , 1000 ) ;
5837
5938 expect ( result . content ) . toBe ( singleLine ) ;
60- expect ( result . actualEndLine ) . toBe ( 0 ) ;
6139 expect ( result . wasLimited ) . toBe ( false ) ;
6240 expect ( result . linesRead ) . toBe ( 1 ) ;
6341 } ) ;
6442
6543 it ( "should correctly count bytes with multi-byte characters" , ( ) => {
6644 const unicodeContent = "Hello 世界\n你好 World\nEmoji: 🌍\nNormal line" ;
67- const result = extractLinesWithByteLimit ( unicodeContent , 0 , 10 , 1000 ) ;
45+ const result = extractLinesWithByteLimit ( unicodeContent , 1000 ) ;
6846
6947 expect ( result . content ) . toBe ( unicodeContent ) ;
7048 expect ( result . linesRead ) . toBe ( 4 ) ;
@@ -77,63 +55,25 @@ describe("extractLinesWithByteLimit", () => {
7755 const line3 = "c" . repeat ( 40 ) ;
7856 const content = `${ line1 } \n${ line2 } \n${ line3 } ` ;
7957
80- const result = extractLinesWithByteLimit ( content , 0 , 3 , 85 ) ;
58+ const result = extractLinesWithByteLimit ( content , 85 ) ;
8159
82- expect ( result . content ) . toBe ( `${ line1 } \n${ line2 } ` ) ;
83- expect ( result . actualEndLine ) . toBe ( 1 ) ;
60+ expect ( result . content ) . toBe ( `${ line1 } \n${ line2 } \n` ) ;
8461 expect ( result . wasLimited ) . toBe ( true ) ;
8562 expect ( result . linesRead ) . toBe ( 2 ) ;
8663 } ) ;
8764
8865 it ( "should read exactly to limit when possible" , ( ) => {
8966 const exactContent = "12345\n67890\n12345" ; // 17 bytes total
90- const result = extractLinesWithByteLimit ( exactContent , 0 , 3 , 17 ) ;
67+ const result = extractLinesWithByteLimit ( exactContent , 17 ) ;
9168
9269 expect ( result . content ) . toBe ( exactContent ) ;
93- expect ( result . actualEndLine ) . toBe ( 2 ) ;
9470 expect ( result . wasLimited ) . toBe ( false ) ;
9571 expect ( result . linesRead ) . toBe ( 3 ) ;
9672 } ) ;
9773
98- it ( "should handle reading from middle to end" , ( ) => {
99- const result = extractLinesWithByteLimit ( simpleContent , 3 , 100 , 1000 ) ;
100-
101- expect ( result . content ) . toBe ( "Line 4\nLine 5" ) ;
102- expect ( result . actualEndLine ) . toBe ( 4 ) ;
103- expect ( result . wasLimited ) . toBe ( false ) ;
104- expect ( result . linesRead ) . toBe ( 2 ) ;
105- } ) ;
106-
107- it ( "should handle large content with typical parameters" , ( ) => {
108- const longContent = Array ( 2000 ) . fill ( "Line content here" ) . join ( "\n" ) ;
109- const result = extractLinesWithByteLimit ( longContent , 0 , 1000 , 50000 ) ;
110-
111- expect ( result . actualEndLine ) . toBeLessThanOrEqual ( 1000 ) ; // Should be limited by line count
112- } ) ;
113-
114- it ( "should provide correct data for partial read at start" , ( ) => {
115- const result = extractLinesWithByteLimit ( simpleContent , 0 , 2 , 1000 ) ;
116-
117- expect ( result . actualEndLine ) . toBe ( 1 ) ;
118- expect ( result . linesRead ) . toBe ( 2 ) ;
119- } ) ;
120-
121- it ( "should provide correct data for partial read with offset" , ( ) => {
122- const result = extractLinesWithByteLimit ( simpleContent , 1 , 2 , 1000 ) ;
123-
124- expect ( result . actualEndLine ) . toBe ( 2 ) ;
125- expect ( result . linesRead ) . toBe ( 2 ) ;
126- } ) ;
127-
128- it ( "should not add newline after last line" , ( ) => {
129- const result = extractLinesWithByteLimit ( "Line 1\nLine 2\nLine 3" , 2 , 1 , 1000 ) ;
130-
131- expect ( result . content ) . toBe ( "Line 3" ) ; // No trailing newline
132- } ) ;
133-
13474 it ( "should handle Windows-style line endings" , ( ) => {
13575 const windowsContent = "Line 1\r\nLine 2\r\nLine 3" ;
136- const result = extractLinesWithByteLimit ( windowsContent , 0 , 3 , 1000 ) ;
76+ const result = extractLinesWithByteLimit ( windowsContent , 1000 ) ;
13777
13878 // Note: split("\n") will keep the \r characters
13979 expect ( result . content ) . toBe ( "Line 1\r\nLine 2\r\nLine 3" ) ;
@@ -145,29 +85,18 @@ describe("extractLinesWithByteLimit", () => {
14585 const largeLine = "x" . repeat ( 1000 ) ;
14686 const largeContent = Array ( 110 ) . fill ( largeLine ) . join ( "\n" ) ;
14787
148- const result = extractLinesWithByteLimit ( largeContent , 0 , 200 , 50000 ) ;
88+ const result = extractLinesWithByteLimit ( largeContent , 50000 ) ;
14989
15090 expect ( result . wasLimited ) . toBe ( true ) ;
151- expect ( result . actualEndLine ) . toBeLessThan ( 50 ) ; // Should stop well before 200 lines
152- } ) ;
153-
154- it ( "should handle line limit of 0" , ( ) => {
155- const result = extractLinesWithByteLimit ( simpleContent , 0 , 0 , 1000 ) ;
156-
157- expect ( result . content ) . toBe ( "" ) ;
158- expect ( result . actualEndLine ) . toBe ( 0 ) ;
159- expect ( result . linesRead ) . toBe ( 0 ) ;
160- expect ( result . wasLimited ) . toBe ( false ) ;
16191 } ) ;
16292
16393 it ( "should allow at least one line even if it exceeds byte limit" , ( ) => {
16494 const veryLongLine = "x" . repeat ( 100000 ) ; // 100KB line
165- const result = extractLinesWithByteLimit ( veryLongLine , 0 , 1 , 50000 ) ;
95+ const result = extractLinesWithByteLimit ( veryLongLine , 50000 ) ;
16696
16797 // Should return the line even though it exceeds the byte limit
16898 // because we always allow at least one line if no lines have been added yet
16999 expect ( result . content ) . toBe ( veryLongLine ) ;
170- expect ( result . actualEndLine ) . toBe ( 0 ) ;
171100 expect ( result . linesRead ) . toBe ( 1 ) ;
172101 expect ( result . wasLimited ) . toBe ( false ) ;
173102 } ) ;
0 commit comments