@@ -17,8 +17,6 @@ const noPoints = {type: 'c', position: {}}
1717
1818const noPosition = { type : 'd' }
1919
20- const generated = { line : null , column : null , offset : null }
21-
2220test ( 'core' , ( ) => {
2321 assert . deepEqual (
2422 Object . keys ( mod ) . sort ( ) ,
@@ -34,28 +32,52 @@ test('position', () => {
3432 'should get the whole position'
3533 )
3634
35+ assert . deepEqual (
36+ position ( {
37+ type : 'x' ,
38+ position : {
39+ start : { line : 0 , column : 0 , offset : - 1 } ,
40+ end : { line : 0 , column : 0 , offset : - 1 }
41+ }
42+ } ) ,
43+ undefined ,
44+ 'should not get too low values'
45+ )
46+
47+ assert . deepEqual (
48+ position ( {
49+ type : 'x' ,
50+ position : { start : { line : 1 , column : 1 } , end : { line : 1 , column : 2 } }
51+ } ) ,
52+ {
53+ start : { line : 1 , column : 1 , offset : undefined } ,
54+ end : { line : 1 , column : 2 , offset : undefined }
55+ } ,
56+ 'should support points w/o `offset`'
57+ )
58+
3759 assert . deepEqual (
3860 position ( noFields ) ,
39- { start : generated , end : generated } ,
40- 'should return an empty position without fields'
61+ undefined ,
62+ 'should return nothing when without fields'
4163 )
4264
4365 assert . deepEqual (
4466 position ( noPoints ) ,
45- { start : generated , end : generated } ,
46- 'should return an empty position without points'
67+ undefined ,
68+ 'should return nothing when without points'
4769 )
4870
4971 assert . deepEqual (
5072 position ( noPosition ) ,
51- { start : generated , end : generated } ,
52- 'should return an empty position without position'
73+ undefined ,
74+ 'should return nothing when without position'
5375 )
5476
5577 assert . deepEqual (
5678 position ( ) ,
57- { start : generated , end : generated } ,
58- 'should return an empty position without node'
79+ undefined ,
80+ 'should return nothing when without node'
5981 )
6082} )
6183
@@ -66,28 +88,49 @@ test('pointStart', () => {
6688 'should get a side'
6789 )
6890
91+ assert . deepEqual (
92+ pointStart ( {
93+ type : 'x' ,
94+ position : {
95+ start : { line : 0 , column : 0 , offset : - 1 } ,
96+ end : { line : 0 , column : 0 , offset : - 1 }
97+ }
98+ } ) ,
99+ undefined ,
100+ 'should not get too low values'
101+ )
102+
103+ assert . deepEqual (
104+ pointStart ( {
105+ type : 'x' ,
106+ position : { start : { line : 1 , column : 1 } , end : { line : 1 , column : 2 } }
107+ } ) ,
108+ { line : 1 , column : 1 , offset : undefined } ,
109+ 'should support points w/o `offset`'
110+ )
111+
69112 assert . deepEqual (
70113 pointStart ( noFields ) ,
71- generated ,
72- 'should return an empty point without fields'
114+ undefined ,
115+ 'should return nothing when without fields'
73116 )
74117
75118 assert . deepEqual (
76119 pointStart ( noPoints ) ,
77- generated ,
78- 'should return an empty point without points'
120+ undefined ,
121+ 'should return nothing when without points'
79122 )
80123
81124 assert . deepEqual (
82125 pointStart ( noPosition ) ,
83- generated ,
84- 'should return an empty point without position'
126+ undefined ,
127+ 'should return nothing when without position'
85128 )
86129
87130 assert . deepEqual (
88131 pointStart ( ) ,
89- generated ,
90- 'should return an empty point without node'
132+ undefined ,
133+ 'should return nothing when without node'
91134 )
92135} )
93136
@@ -98,27 +141,48 @@ test('pointEnd', () => {
98141 'should get a side'
99142 )
100143
144+ assert . deepEqual (
145+ pointEnd ( {
146+ type : 'x' ,
147+ position : {
148+ start : { line : 0 , column : 0 , offset : - 1 } ,
149+ end : { line : 0 , column : 0 , offset : - 1 }
150+ }
151+ } ) ,
152+ undefined ,
153+ 'should not get too low values'
154+ )
155+
156+ assert . deepEqual (
157+ pointEnd ( {
158+ type : 'x' ,
159+ position : { start : { line : 1 , column : 1 } , end : { line : 1 , column : 2 } }
160+ } ) ,
161+ { line : 1 , column : 2 , offset : undefined } ,
162+ 'should support points w/o `offset`'
163+ )
164+
101165 assert . deepEqual (
102166 pointEnd ( noFields ) ,
103- generated ,
104- 'should return an empty point without fields'
167+ undefined ,
168+ 'should return nothing when without fields'
105169 )
106170
107171 assert . deepEqual (
108172 pointEnd ( noPoints ) ,
109- generated ,
110- 'should return an empty point without points'
173+ undefined ,
174+ 'should return nothing when without points'
111175 )
112176
113177 assert . deepEqual (
114178 pointEnd ( noPosition ) ,
115- generated ,
116- 'should return an empty point without position'
179+ undefined ,
180+ 'should return nothing when without position'
117181 )
118182
119183 assert . deepEqual (
120184 pointEnd ( ) ,
121- generated ,
122- 'should return an empty point without node'
185+ undefined ,
186+ 'should return nothing when without node'
123187 )
124188} )
0 commit comments