@@ -11,122 +11,88 @@ import {computeStartOfLinePositions} from '../../src/sourcemaps/source_file';
11
11
describe ( 'SegmentMarker utils' , ( ) => {
12
12
describe ( 'compareSegments()' , ( ) => {
13
13
it ( 'should return 0 if the segments are the same' , ( ) => {
14
- expect ( compareSegments ( { line : 0 , column : 0 } , { line : 0 , column : 0 } ) ) . toEqual ( 0 ) ;
15
- expect ( compareSegments ( { line : 123 , column : 0 } , { line : 123 , column : 0 } ) ) . toEqual ( 0 ) ;
16
- expect ( compareSegments ( { line : 0 , column : 45 } , { line : 0 , column : 45 } ) ) . toEqual ( 0 ) ;
17
- expect ( compareSegments ( { line : 123 , column : 45 } , { line : 123 , column : 45 } ) ) . toEqual ( 0 ) ;
18
- } ) ;
19
-
20
- it ( 'should return a negative number if the first segment is before the second segment' , ( ) => {
21
- expect ( compareSegments ( { line : 0 , column : 0 } , { line : 0 , column : 45 } ) ) . toBeLessThan ( 0 ) ;
22
- expect ( compareSegments ( { line : 123 , column : 0 } , { line : 123 , column : 45 } ) ) . toBeLessThan ( 0 ) ;
23
- expect ( compareSegments ( { line : 13 , column : 45 } , { line : 123 , column : 45 } ) ) . toBeLessThan ( 0 ) ;
24
- expect ( compareSegments ( { line : 13 , column : 45 } , { line : 123 , column : 9 } ) ) . toBeLessThan ( 0 ) ;
25
- } ) ;
26
-
27
- it ( 'should return a positive number if the first segment is after the second segment' , ( ) => {
28
- expect ( compareSegments ( { line : 0 , column : 45 } , { line : 0 , column : 0 } ) ) . toBeGreaterThan ( 0 ) ;
29
- expect ( compareSegments ( { line : 123 , column : 45 } , { line : 123 , column : 0 } ) ) . toBeGreaterThan ( 0 ) ;
30
- expect ( compareSegments ( { line : 123 , column : 45 } , { line : 13 , column : 45 } ) ) . toBeGreaterThan ( 0 ) ;
31
- expect ( compareSegments ( { line : 123 , column : 9 } , { line : 13 , column : 45 } ) ) . toBeGreaterThan ( 0 ) ;
32
- } ) ;
33
- } ) ;
34
-
35
- describe ( 'segmentDiff()' , ( ) => {
36
- it ( 'should return 0 if the segments are the same' , ( ) => {
37
- const startOfLinePositions =
38
- computeStartOfLinePositions ( 'abcdef\nabcdefghj\nabcdefghijklm\nabcdef' ) ;
39
- expect ( segmentDiff ( startOfLinePositions , { line : 0 , column : 0 } , { line : 0 , column : 0 } ) )
14
+ expect ( compareSegments (
15
+ { line : 0 , column : 0 , next : undefined } , { line : 0 , column : 0 , next : undefined } ) )
40
16
. toEqual ( 0 ) ;
41
- expect ( segmentDiff ( startOfLinePositions , { line : 3 , column : 0 } , { line : 3 , column : 0 } ) )
17
+ expect ( compareSegments (
18
+ { line : 123 , column : 0 , next : undefined } , { line : 123 , column : 0 , next : undefined } ) )
42
19
. toEqual ( 0 ) ;
43
- expect ( segmentDiff ( startOfLinePositions , { line : 0 , column : 5 } , { line : 0 , column : 5 } ) )
20
+ expect ( compareSegments (
21
+ { line : 0 , column : 45 , next : undefined } , { line : 0 , column : 45 , next : undefined } ) )
44
22
. toEqual ( 0 ) ;
45
- expect ( segmentDiff ( startOfLinePositions , { line : 3 , column : 5 } , { line : 3 , column : 5 } ) )
23
+ expect (
24
+ compareSegments (
25
+ { line : 123 , column : 45 , next : undefined } , { line : 123 , column : 45 , next : undefined } ) )
46
26
. toEqual ( 0 ) ;
47
27
} ) ;
48
28
49
- it ( 'should return the column difference if the markers are on the same line' , ( ) => {
50
- const startOfLinePositions =
51
- computeStartOfLinePositions ( 'abcdef\nabcdefghj\nabcdefghijklm\nabcdef' ) ;
52
- expect ( segmentDiff ( startOfLinePositions , { line : 0 , column : 0 } , { line : 0 , column : 3 } ) )
53
- . toEqual ( 3 ) ;
54
- expect ( segmentDiff ( startOfLinePositions , { line : 1 , column : 1 } , { line : 1 , column : 5 } ) )
55
- . toEqual ( 4 ) ;
56
- expect ( segmentDiff ( startOfLinePositions , { line : 2 , column : 5 } , { line : 2 , column : 1 } ) )
57
- . toEqual ( - 4 ) ;
58
- expect ( segmentDiff ( startOfLinePositions , { line : 3 , column : 3 } , { line : 3 , column : 0 } ) )
59
- . toEqual ( - 3 ) ;
29
+ it ( 'should return a negative number if the first segment is before the second segment' , ( ) => {
30
+ expect ( compareSegments (
31
+ { line : 0 , column : 0 , next : undefined } , { line : 0 , column : 45 , next : undefined } ) )
32
+ . toBeLessThan ( 0 ) ;
33
+ expect ( compareSegments (
34
+ { line : 123 , column : 0 , next : undefined } , { line : 123 , column : 45 , next : undefined } ) )
35
+ . toBeLessThan ( 0 ) ;
36
+ expect ( compareSegments (
37
+ { line : 13 , column : 45 , next : undefined } , { line : 123 , column : 45 , next : undefined } ) )
38
+ . toBeLessThan ( 0 ) ;
39
+ expect ( compareSegments (
40
+ { line : 13 , column : 45 , next : undefined } , { line : 123 , column : 9 , next : undefined } ) )
41
+ . toBeLessThan ( 0 ) ;
60
42
} ) ;
61
43
62
- it ( 'should return the number of actual characters difference (including newline markers) if not on the same line' ,
63
- ( ) => {
64
- let startOfLinePositions : number [ ] ;
65
-
66
- startOfLinePositions = computeStartOfLinePositions ( 'A12345\nB123456789' ) ;
67
- expect ( segmentDiff ( startOfLinePositions , { line : 0 , column : 0 } , { line : 1 , column : 0 } ) )
68
- . toEqual ( 6 + 1 ) ;
69
-
70
- startOfLinePositions = computeStartOfLinePositions ( '012A45\n01234B6789' ) ;
71
- expect ( segmentDiff ( startOfLinePositions , { line : 0 , column : 3 } , { line : 1 , column : 5 } ) )
72
- . toEqual ( 3 + 1 + 5 ) ;
73
-
74
- startOfLinePositions =
75
- computeStartOfLinePositions ( '012345\n012345A789\n01234567\nB123456' ) ;
76
- expect ( segmentDiff ( startOfLinePositions , { line : 1 , column : 6 } , { line : 3 , column : 0 } ) )
77
- . toEqual ( 4 + 1 + 8 + 1 + 0 ) ;
78
-
79
- startOfLinePositions =
80
- computeStartOfLinePositions ( '012345\nA123456789\n01234567\n012B456' ) ;
81
- expect ( segmentDiff ( startOfLinePositions , { line : 1 , column : 0 } , { line : 3 , column : 3 } ) )
82
- . toEqual ( 10 + 1 + 8 + 1 + 3 ) ;
83
-
84
- startOfLinePositions =
85
- computeStartOfLinePositions ( '012345\nB123456789\nA1234567\n0123456' ) ;
86
- expect ( segmentDiff ( startOfLinePositions , { line : 2 , column : 0 } , { line : 1 , column : 0 } ) )
87
- . toEqual ( 0 - 1 - 10 + 0 ) ;
88
-
89
- startOfLinePositions =
90
- computeStartOfLinePositions ( '012345\n0123B56789\n01234567\n012A456' ) ;
91
- expect ( segmentDiff ( startOfLinePositions , { line : 3 , column : 3 } , { line : 1 , column : 4 } ) )
92
- . toEqual ( - 3 - 1 - 8 - 1 - 10 + 4 ) ;
93
-
94
- startOfLinePositions =
95
- computeStartOfLinePositions ( 'B12345\n0123456789\n0123A567\n0123456' ) ;
96
- expect ( segmentDiff ( startOfLinePositions , { line : 2 , column : 4 } , { line : 0 , column : 0 } ) )
97
- . toEqual ( - 4 - 1 - 10 - 1 - 6 + 0 ) ;
98
-
99
- startOfLinePositions =
100
- computeStartOfLinePositions ( '0123B5\n0123456789\nA1234567\n0123456' ) ;
101
- expect ( segmentDiff ( startOfLinePositions , { line : 2 , column : 0 } , { line : 0 , column : 4 } ) )
102
- . toEqual ( 0 - 1 - 10 - 1 - 6 + 4 ) ;
103
- } ) ;
44
+ it ( 'should return a positive number if the first segment is after the second segment' , ( ) => {
45
+ expect ( compareSegments (
46
+ { line : 0 , column : 45 , next : undefined } , { line : 0 , column : 0 , next : undefined } ) )
47
+ . toBeGreaterThan ( 0 ) ;
48
+ expect ( compareSegments (
49
+ { line : 123 , column : 45 , next : undefined } , { line : 123 , column : 0 , next : undefined } ) )
50
+ . toBeGreaterThan ( 0 ) ;
51
+ expect ( compareSegments (
52
+ { line : 123 , column : 45 , next : undefined } , { line : 13 , column : 45 , next : undefined } ) )
53
+ . toBeGreaterThan ( 0 ) ;
54
+ expect ( compareSegments (
55
+ { line : 123 , column : 9 , next : undefined } , { line : 13 , column : 45 , next : undefined } ) )
56
+ . toBeGreaterThan ( 0 ) ;
57
+ } ) ;
104
58
} ) ;
105
59
106
60
describe ( 'offsetSegment()' , ( ) => {
107
61
it ( 'should return an identical marker if offset is 0' , ( ) => {
108
62
const startOfLinePositions =
109
- computeStartOfLinePositions ( '012345\n0123456789\r\n01234567 \n0123456' ) ;
110
- const marker = { line : 2 , column : 3 } ;
63
+ computeStartOfLinePositions ( '012345\n0123456789\r\n012*4567 \n0123456' ) ;
64
+ const marker = { line : 2 , column : 3 , next : undefined } ;
111
65
expect ( offsetSegment ( startOfLinePositions , marker , 0 ) ) . toBe ( marker ) ;
112
66
} ) ;
113
67
114
68
it ( 'should return a new marker offset by the given chars' , ( ) => {
115
69
const startOfLinePositions =
116
70
computeStartOfLinePositions ( '012345\n0123456789\r\n012*4567\n0123456' ) ;
117
- const marker = { line : 2 , column : 3 } ;
118
- expect ( offsetSegment ( startOfLinePositions , marker , 1 ) ) . toEqual ( { line : 2 , column : 4 } ) ;
119
- expect ( offsetSegment ( startOfLinePositions , marker , 2 ) ) . toEqual ( { line : 2 , column : 5 } ) ;
120
- expect ( offsetSegment ( startOfLinePositions , marker , 4 ) ) . toEqual ( { line : 2 , column : 7 } ) ;
121
- expect ( offsetSegment ( startOfLinePositions , marker , 6 ) ) . toEqual ( { line : 3 , column : 0 } ) ;
122
- expect ( offsetSegment ( startOfLinePositions , marker , 8 ) ) . toEqual ( { line : 3 , column : 2 } ) ;
123
- expect ( offsetSegment ( startOfLinePositions , marker , 20 ) ) . toEqual ( { line : 3 , column : 14 } ) ;
124
- expect ( offsetSegment ( startOfLinePositions , marker , - 1 ) ) . toEqual ( { line : 2 , column : 2 } ) ;
125
- expect ( offsetSegment ( startOfLinePositions , marker , - 2 ) ) . toEqual ( { line : 2 , column : 1 } ) ;
126
- expect ( offsetSegment ( startOfLinePositions , marker , - 3 ) ) . toEqual ( { line : 2 , column : 0 } ) ;
127
- expect ( offsetSegment ( startOfLinePositions , marker , - 4 ) ) . toEqual ( { line : 1 , column : 10 } ) ;
128
- expect ( offsetSegment ( startOfLinePositions , marker , - 6 ) ) . toEqual ( { line : 1 , column : 8 } ) ;
129
- expect ( offsetSegment ( startOfLinePositions , marker , - 16 ) ) . toEqual ( { line : 0 , column : 5 } ) ;
71
+ const marker = { line : 2 , column : 3 , next : undefined } ;
72
+ expect ( offsetSegment ( startOfLinePositions , marker , 1 ) )
73
+ . toEqual ( { line : 2 , column : 4 , next : undefined } ) ;
74
+ expect ( offsetSegment ( startOfLinePositions , marker , 2 ) )
75
+ . toEqual ( { line : 2 , column : 5 , next : undefined } ) ;
76
+ expect ( offsetSegment ( startOfLinePositions , marker , 4 ) )
77
+ . toEqual ( { line : 2 , column : 7 , next : undefined } ) ;
78
+ expect ( offsetSegment ( startOfLinePositions , marker , 6 ) )
79
+ . toEqual ( { line : 3 , column : 0 , next : undefined } ) ;
80
+ expect ( offsetSegment ( startOfLinePositions , marker , 8 ) )
81
+ . toEqual ( { line : 3 , column : 2 , next : undefined } ) ;
82
+ expect ( offsetSegment ( startOfLinePositions , marker , 20 ) )
83
+ . toEqual ( { line : 3 , column : 14 , next : undefined } ) ;
84
+ expect ( offsetSegment ( startOfLinePositions , marker , - 1 ) )
85
+ . toEqual ( { line : 2 , column : 2 , next : undefined } ) ;
86
+ expect ( offsetSegment ( startOfLinePositions , marker , - 2 ) )
87
+ . toEqual ( { line : 2 , column : 1 , next : undefined } ) ;
88
+ expect ( offsetSegment ( startOfLinePositions , marker , - 3 ) )
89
+ . toEqual ( { line : 2 , column : 0 , next : undefined } ) ;
90
+ expect ( offsetSegment ( startOfLinePositions , marker , - 4 ) )
91
+ . toEqual ( { line : 1 , column : 10 , next : undefined } ) ;
92
+ expect ( offsetSegment ( startOfLinePositions , marker , - 6 ) )
93
+ . toEqual ( { line : 1 , column : 8 , next : undefined } ) ;
94
+ expect ( offsetSegment ( startOfLinePositions , marker , - 16 ) )
95
+ . toEqual ( { line : 0 , column : 5 , next : undefined } ) ;
130
96
} ) ;
131
97
} ) ;
132
98
} ) ;
0 commit comments