@@ -24,11 +24,6 @@ describe('Expression', function () {
24
24
expect ( await toPromise ( create ( '"foo"' ) . evaluate ( ctx , false ) ) ) . toBe ( 'foo' )
25
25
expect ( await toPromise ( create ( 'false' ) . evaluate ( ctx , false ) ) ) . toBe ( false )
26
26
} )
27
- it ( 'should eval range expression' , async function ( ) {
28
- const ctx = new Context ( { two : 2 } )
29
- expect ( await toPromise ( create ( '(2..4)' ) . evaluate ( ctx , false ) ) ) . toEqual ( [ 2 , 3 , 4 ] )
30
- expect ( await toPromise ( create ( '(two..4)' ) . evaluate ( ctx , false ) ) ) . toEqual ( [ 2 , 3 , 4 ] )
31
- } )
32
27
it ( 'should eval literal' , async function ( ) {
33
28
expect ( await toPromise ( create ( '2.4' ) . evaluate ( ctx , false ) ) ) . toBe ( 2.4 )
34
29
expect ( await toPromise ( create ( '"foo"' ) . evaluate ( ctx , false ) ) ) . toBe ( 'foo' )
@@ -221,6 +216,30 @@ describe('Expression', function () {
221
216
} )
222
217
} )
223
218
219
+ describe ( 'range' , function ( ) {
220
+ const ctx = new Context ( { two : 2 , num : { one : 1 , two : 2 } } )
221
+ it ( 'should eval range expression' , async function ( ) {
222
+ expect ( await toPromise ( create ( '(2..4)' ) . evaluate ( ctx , false ) ) ) . toEqual ( [ 2 , 3 , 4 ] )
223
+ expect ( await toPromise ( create ( '(two..4)' ) . evaluate ( ctx , false ) ) ) . toEqual ( [ 2 , 3 , 4 ] )
224
+ } )
225
+ it ( 'should allow property access expression as variables' , async function ( ) {
226
+ expect ( await toPromise ( create ( '(num.one..num.two)' ) . evaluate ( ctx ) ) ) . toEqual ( [ 1 , 2 ] )
227
+ expect ( await toPromise ( create ( '(num.one .. two)' ) . evaluate ( ctx ) ) ) . toEqual ( [ 1 , 2 ] )
228
+ } )
229
+ it ( 'should allow blanks in range' , async function ( ) {
230
+ expect ( await toPromise ( create ( '(3 ..5)' ) . evaluate ( ctx ) ) ) . toEqual ( [ 3 , 4 , 5 ] )
231
+ expect ( await toPromise ( create ( '(3 .. 5)' ) . evaluate ( ctx ) ) ) . toEqual ( [ 3 , 4 , 5 ] )
232
+ expect ( await toPromise ( create ( '( 3 .. 5 )' ) . evaluate ( ctx ) ) ) . toEqual ( [ 3 , 4 , 5 ] )
233
+ } )
234
+ it ( 'should throw if .. not matched' , async function ( ) {
235
+ expect ( ( ) => create ( '(3.5' ) ) . toThrow ( 'invalid range syntax' )
236
+ expect ( ( ) => create ( '(3 5' ) ) . toThrow ( 'invalid range syntax' )
237
+ } )
238
+ it ( 'should throw if ( not patched' , async function ( ) {
239
+ expect ( ( ) => create ( '(3..5' ) ) . toThrow ( 'invalid range syntax' )
240
+ } )
241
+ } )
242
+
224
243
describe ( 'sync' , function ( ) {
225
244
it ( 'should eval literal' , function ( ) {
226
245
expect ( toValueSync ( create ( '2.4' ) . evaluate ( ctx , false ) ) ) . toBe ( 2.4 )
0 commit comments