@@ -4,128 +4,9 @@ const expect = chai.expect
4
4
const lexical = require ( 'src/parser/lexical' )
5
5
6
6
describe ( 'lexical' , function ( ) {
7
- it ( 'should test filter syntax' , function ( ) {
8
- expect ( lexical . filterLine . test ( 'abs' ) ) . to . equal ( true )
9
- expect ( lexical . filterLine . test ( 'plus:1' ) ) . to . equal ( true )
10
- expect ( lexical . filterLine . test ( 'replace: "a", b' ) ) . to . equal ( true )
11
- expect ( lexical . filterLine . test ( 'foo: a, "b"' ) ) . to . equal ( true )
12
- expect ( lexical . filterLine . test ( 'abs | another' ) ) . to . equal ( false )
13
- expect ( lexical . filterLine . test ( 'join: "," | another' ) ) . to . equal ( false )
14
- expect ( lexical . filterLine . test ( 'obj_test: k1: "v1", k2: "v2"' ) ) . to . equal ( true )
15
- } )
16
-
17
- it ( 'should test boolean literal' , function ( ) {
18
- expect ( lexical . isLiteral ( 'true' ) ) . to . equal ( true )
19
- expect ( lexical . isLiteral ( 'TrUE' ) ) . to . equal ( true )
20
- expect ( lexical . isLiteral ( 'false' ) ) . to . equal ( true )
21
- } )
22
-
23
- it ( 'should test number literal' , function ( ) {
24
- expect ( lexical . isLiteral ( '2.3' ) ) . to . equal ( true )
25
- expect ( lexical . isLiteral ( '.3' ) ) . to . equal ( true )
26
- expect ( lexical . isLiteral ( '-3.' ) ) . to . equal ( true )
27
- expect ( lexical . isLiteral ( '23' ) ) . to . equal ( true )
28
- } )
29
-
30
7
it ( 'should test range literal' , function ( ) {
31
8
expect ( lexical . isRange ( '(12..32)' ) ) . to . equal ( true )
32
9
expect ( lexical . isRange ( '(12..foo)' ) ) . to . equal ( true )
33
10
expect ( lexical . isRange ( '(foo.bar..foo)' ) ) . to . equal ( true )
34
11
} )
35
-
36
- it ( 'should test string literal' , function ( ) {
37
- expect ( lexical . isLiteral ( '""' ) ) . to . equal ( true )
38
- expect ( lexical . isLiteral ( '"a\'b"' ) ) . to . equal ( true )
39
- expect ( lexical . isLiteral ( "''" ) ) . to . equal ( true )
40
- expect ( lexical . isLiteral ( "'a bcd'" ) ) . to . equal ( true )
41
- } )
42
-
43
- describe ( '.isVariable()' , function ( ) {
44
- it ( 'should return true for foo' , function ( ) {
45
- expect ( lexical . isVariable ( 'foo' ) ) . to . equal ( true )
46
- } )
47
- it ( 'should return true for.bar.foo' , function ( ) {
48
- expect ( lexical . isVariable ( 'foo.bar.foo' ) ) . to . equal ( true )
49
- } )
50
- it ( 'should return true for foo[0].b' , function ( ) {
51
- expect ( lexical . isVariable ( 'foo[0].b' ) ) . to . equal ( true )
52
- } )
53
- it ( 'should return true for 0a' , function ( ) {
54
- expect ( lexical . isVariable ( '0a' ) ) . to . equal ( true )
55
- } )
56
- it ( 'should return true for foo[a.b]' , function ( ) {
57
- expect ( lexical . isVariable ( 'foo[a.b]' ) ) . to . equal ( true )
58
- } )
59
- it ( 'should return true for foo[a.b]' , function ( ) {
60
- expect ( lexical . isVariable ( "foo['a[0]']" ) ) . to . equal ( true )
61
- } )
62
- it ( 'should return true for "var-1"' , function ( ) {
63
- expect ( lexical . isVariable ( 'var-1' ) ) . to . equal ( true )
64
- } )
65
- it ( 'should return true for "-var"' , function ( ) {
66
- expect ( lexical . isVariable ( '-var' ) ) . to . equal ( true )
67
- } )
68
- it ( 'should return true for "var-"' , function ( ) {
69
- expect ( lexical . isVariable ( 'var-' ) ) . to . equal ( true )
70
- } )
71
- it ( 'should return true for "3-4"' , function ( ) {
72
- expect ( lexical . isVariable ( '3-4' ) ) . to . equal ( true )
73
- } )
74
- } )
75
-
76
- it ( 'should test none literal' , function ( ) {
77
- expect ( lexical . isLiteral ( '2a' ) ) . to . equal ( false )
78
- expect ( lexical . isLiteral ( '"x' ) ) . to . equal ( false )
79
- expect ( lexical . isLiteral ( 'a2' ) ) . to . equal ( false )
80
- } )
81
-
82
- it ( 'should test none variable' , function ( ) {
83
- expect ( lexical . isVariable ( 'a.' ) ) . to . equal ( false )
84
- expect ( lexical . isVariable ( '.b' ) ) . to . equal ( false )
85
- expect ( lexical . isVariable ( '.' ) ) . to . equal ( false )
86
- expect ( lexical . isVariable ( '[0][12].bar[0]' ) ) . to . equal ( false )
87
- } )
88
-
89
- describe ( '.parseLiteral()' , function ( ) {
90
- it ( 'should parse boolean literal' , function ( ) {
91
- expect ( lexical . parseLiteral ( 'true' ) ) . to . equal ( true )
92
- expect ( lexical . parseLiteral ( 'TrUE' ) ) . to . equal ( true )
93
- expect ( lexical . parseLiteral ( 'false' ) ) . to . equal ( false )
94
- } )
95
-
96
- it ( 'should parse number literal' , function ( ) {
97
- expect ( lexical . parseLiteral ( '2.3' ) ) . to . equal ( 2.3 )
98
- expect ( lexical . parseLiteral ( '.32' ) ) . to . equal ( 0.32 )
99
- expect ( lexical . parseLiteral ( '-23.' ) ) . to . equal ( - 23 )
100
- expect ( lexical . parseLiteral ( '23' ) ) . to . equal ( 23 )
101
- } )
102
-
103
- it ( 'should parse string literal' , function ( ) {
104
- expect ( lexical . parseLiteral ( '"ab\'c"' ) ) . to . equal ( "ab'c" )
105
- } )
106
-
107
- it ( 'should throw if non-literal' , function ( ) {
108
- const fn = ( ) => lexical . parseLiteral ( 'a' )
109
- expect ( fn ) . to . throw ( "cannot parse 'a' as literal" )
110
- } )
111
- } )
112
-
113
- describe ( '.matchValue()' , function ( ) {
114
- it ( 'should match -5-5' , function ( ) {
115
- const match = lexical . matchValue ( '-5-5' )
116
- expect ( match && match [ 0 ] ) . to . equal ( '-5-5' )
117
- } )
118
- it ( 'should match 4-3' , function ( ) {
119
- const match = lexical . matchValue ( '4-3' )
120
- expect ( match && match [ 0 ] ) . to . equal ( '4-3' )
121
- } )
122
- it ( 'should match 4-3' , function ( ) {
123
- const match = lexical . matchValue ( '4-3' )
124
- expect ( match && match [ 0 ] ) . to . equal ( '4-3' )
125
- } )
126
- it ( 'should match var-1' , function ( ) {
127
- const match = lexical . matchValue ( 'var-1' )
128
- expect ( match && match [ 0 ] ) . to . equal ( 'var-1' )
129
- } )
130
- } )
131
12
} )
0 commit comments