1- import { addLineNumbers } from '../extract-text' ;
1+ import { addLineNumbers , everyLineHasLineNumbers , stripLineNumbers } from '../extract-text' ;
22
33describe ( 'addLineNumbers' , ( ) => {
44 it ( 'should add line numbers starting from 1 by default' , ( ) => {
@@ -29,4 +29,81 @@ describe('addLineNumbers', () => {
2929 const expected = ' 99 | line 1\n100 | line 2' ;
3030 expect ( addLineNumbers ( input , 99 ) ) . toBe ( expected ) ;
3131 } ) ;
32+ } ) ;
33+
34+ describe ( 'everyLineHasLineNumbers' , ( ) => {
35+ it ( 'should return true for content with line numbers' , ( ) => {
36+ const input = '1 | line one\n2 | line two\n3 | line three' ;
37+ expect ( everyLineHasLineNumbers ( input ) ) . toBe ( true ) ;
38+ } ) ;
39+
40+ it ( 'should return true for content with padded line numbers' , ( ) => {
41+ const input = ' 1 | line one\n 2 | line two\n 3 | line three' ;
42+ expect ( everyLineHasLineNumbers ( input ) ) . toBe ( true ) ;
43+ } ) ;
44+
45+ it ( 'should return false for content without line numbers' , ( ) => {
46+ const input = 'line one\nline two\nline three' ;
47+ expect ( everyLineHasLineNumbers ( input ) ) . toBe ( false ) ;
48+ } ) ;
49+
50+ it ( 'should return false for mixed content' , ( ) => {
51+ const input = '1 | line one\nline two\n3 | line three' ;
52+ expect ( everyLineHasLineNumbers ( input ) ) . toBe ( false ) ;
53+ } ) ;
54+
55+ it ( 'should handle empty content' , ( ) => {
56+ expect ( everyLineHasLineNumbers ( '' ) ) . toBe ( false ) ;
57+ } ) ;
58+
59+ it ( 'should return false for content with pipe but no line numbers' , ( ) => {
60+ const input = 'a | b\nc | d' ;
61+ expect ( everyLineHasLineNumbers ( input ) ) . toBe ( false ) ;
62+ } ) ;
63+ } ) ;
64+
65+ describe ( 'stripLineNumbers' , ( ) => {
66+ it ( 'should strip line numbers from content' , ( ) => {
67+ const input = '1 | line one\n2 | line two\n3 | line three' ;
68+ const expected = 'line one\nline two\nline three' ;
69+ expect ( stripLineNumbers ( input ) ) . toBe ( expected ) ;
70+ } ) ;
71+
72+ it ( 'should strip padded line numbers' , ( ) => {
73+ const input = ' 1 | line one\n 2 | line two\n 3 | line three' ;
74+ const expected = 'line one\nline two\nline three' ;
75+ expect ( stripLineNumbers ( input ) ) . toBe ( expected ) ;
76+ } ) ;
77+
78+ it ( 'should handle content without line numbers' , ( ) => {
79+ const input = 'line one\nline two\nline three' ;
80+ expect ( stripLineNumbers ( input ) ) . toBe ( input ) ;
81+ } ) ;
82+
83+ it ( 'should handle empty content' , ( ) => {
84+ expect ( stripLineNumbers ( '' ) ) . toBe ( '' ) ;
85+ } ) ;
86+
87+ it ( 'should preserve content with pipe but no line numbers' , ( ) => {
88+ const input = 'a | b\nc | d' ;
89+ expect ( stripLineNumbers ( input ) ) . toBe ( input ) ;
90+ } ) ;
91+
92+ it ( 'should handle windows-style line endings' , ( ) => {
93+ const input = '1 | line one\r\n2 | line two\r\n3 | line three' ;
94+ const expected = 'line one\r\nline two\r\nline three' ;
95+ expect ( stripLineNumbers ( input ) ) . toBe ( expected ) ;
96+ } ) ;
97+
98+ it ( 'should handle content with varying line number widths' , ( ) => {
99+ const input = ' 1 | line one\n 10 | line two\n100 | line three' ;
100+ const expected = 'line one\nline two\nline three' ;
101+ expect ( stripLineNumbers ( input ) ) . toBe ( expected ) ;
102+ } ) ;
103+
104+ it ( 'should preserve indentation after line numbers' , ( ) => {
105+ const input = '1 | indented line\n2 | another indented' ;
106+ const expected = ' indented line\n another indented' ;
107+ expect ( stripLineNumbers ( input ) ) . toBe ( expected ) ;
108+ } ) ;
32109} ) ;
0 commit comments