1
1
var parser = require ( "../src/index" ) ;
2
2
3
3
describe ( "Test strings" , function ( ) {
4
+ it ( "fix #101" , function ( ) {
5
+ let ast = parser . parseEval ( '"encapsed {$var}";' ) ;
6
+ ast . children [ 0 ] . value [ 1 ] . kind . should . be . exactly ( "variable" ) ;
7
+ ast . children [ 0 ] . value [ 1 ] . curly . should . be . true ( ) ;
8
+ ast = parser . parseEval ( '"encapsed {$arr[0]}";' ) ;
9
+ ast . children [ 0 ] . value [ 1 ] . kind . should . be . exactly ( "offsetlookup" ) ;
10
+ ast = parser . parseEval ( '"encapsed ${var}";' ) ;
11
+ ast . children [ 0 ] . value [ 1 ] . name . kind . should . be . exactly ( "constref" ) ;
12
+ } ) ;
4
13
it ( "fix #124" , function ( ) {
5
- const ast = parser . parseEval ( "$string = \"He drank some $juices[koolaid1] juice.\";" ) ;
14
+ const ast = parser . parseEval (
15
+ '$string = "He drank some $juices[koolaid1] juice.";'
16
+ ) ;
6
17
const text = ast . children [ 0 ] . right ;
7
- text . kind . should . be . exactly ( ' encapsed' ) ;
18
+ text . kind . should . be . exactly ( " encapsed" ) ;
8
19
text . value . length . should . be . exactly ( 3 ) ;
9
20
const offset = text . value [ 1 ] ;
10
- offset . kind . should . be . exactly ( ' offsetlookup' ) ;
11
- offset . what . name . should . be . exactly ( ' juices' ) ;
12
- offset . offset . kind . should . be . exactly ( ' constref' ) ;
13
- offset . offset . name . should . be . exactly ( ' koolaid1' ) ;
21
+ offset . kind . should . be . exactly ( " offsetlookup" ) ;
22
+ offset . what . name . should . be . exactly ( " juices" ) ;
23
+ offset . offset . kind . should . be . exactly ( " constref" ) ;
24
+ offset . offset . name . should . be . exactly ( " koolaid1" ) ;
14
25
} ) ;
15
- it ( ' fix #123' , function ( ) {
26
+ it ( " fix #123" , function ( ) {
16
27
const ast = parser . parseEval (
17
- "$string = \ 'Avoid converting \n chars, but \\' or \\\\ is ok.\ ';"
28
+ "$string = 'Avoid converting \n chars, but \\' or \\\\ is ok.';"
18
29
) ;
19
30
const text = ast . children [ 0 ] . right ;
20
- text . value . should . be . exactly ( 'Avoid converting \n chars, but \' or \\ is ok.' ) ;
31
+ text . value . should . be . exactly (
32
+ "Avoid converting \n chars, but ' or \\ is ok."
33
+ ) ;
21
34
} ) ;
22
- it ( ' implement #116' , function ( ) {
23
- const ast = parser . parseEval ( " $a = \ "foo\\nbar\";" ) ;
35
+ it ( " implement #116" , function ( ) {
36
+ const ast = parser . parseEval ( ' $a = "foo\\nbar";' ) ;
24
37
const text = ast . children [ 0 ] . right ;
25
- text . raw . should . be . exactly ( "\" foo\\nbar\"" ) ;
38
+ text . raw . should . be . exactly ( '" foo\\nbar"' ) ;
26
39
} ) ;
27
40
it ( "..." , function ( ) {
28
41
var ast = parser . parseEval ( "$a = b'\\t\\ra';" ) ;
@@ -36,70 +49,71 @@ describe("Test strings", function() {
36
49
it ( "check infinite on $" , function ( ) {
37
50
var ast = parser . parseEval ( 'echo "$' , {
38
51
parser : { suppressErrors : true , debug : false } ,
39
- lexer : { debug : false } ,
52
+ lexer : { debug : false }
40
53
} ) ;
41
- ast . children [ 0 ] . arguments [ 0 ] . value [ 0 ] . kind . should . be . exactly ( ' string' ) ;
42
- ast . children [ 0 ] . arguments [ 0 ] . value [ 0 ] . value . should . be . exactly ( '$' ) ;
54
+ ast . children [ 0 ] . arguments [ 0 ] . value [ 0 ] . kind . should . be . exactly ( " string" ) ;
55
+ ast . children [ 0 ] . arguments [ 0 ] . value [ 0 ] . value . should . be . exactly ( "$" ) ;
43
56
44
57
// @todo ...
45
- ast = parser . parseEval ( ' echo `$' , {
58
+ ast = parser . parseEval ( " echo `$" , {
46
59
parser : { suppressErrors : true , debug : false } ,
47
- lexer : { debug : false } ,
60
+ lexer : { debug : false }
48
61
} ) ;
49
- ast = parser . parseEval ( ' echo ` -> $' , {
62
+ ast = parser . parseEval ( " echo ` -> $" , {
50
63
parser : { suppressErrors : true , debug : false } ,
51
- lexer : { debug : false } ,
64
+ lexer : { debug : false }
52
65
} ) ;
53
-
54
66
} ) ;
55
67
it ( "check infinite on {" , function ( ) {
56
68
var ast = parser . parseEval ( 'echo "{' , {
57
69
parser : { suppressErrors : true , debug : false } ,
58
- lexer : { debug : false } ,
70
+ lexer : { debug : false }
59
71
} ) ;
60
- ast . children [ 0 ] . arguments [ 0 ] . value [ 0 ] . kind . should . be . exactly ( ' string' ) ;
61
- ast . children [ 0 ] . arguments [ 0 ] . value [ 0 ] . value . should . be . exactly ( '{' ) ;
62
- ast = parser . parseEval ( ' echo `{' , {
72
+ ast . children [ 0 ] . arguments [ 0 ] . value [ 0 ] . kind . should . be . exactly ( " string" ) ;
73
+ ast . children [ 0 ] . arguments [ 0 ] . value [ 0 ] . value . should . be . exactly ( "{" ) ;
74
+ ast = parser . parseEval ( " echo `{" , {
63
75
parser : { suppressErrors : true , debug : false } ,
64
- lexer : { debug : false } ,
76
+ lexer : { debug : false }
65
77
} ) ;
66
- ast = parser . parseEval ( ' echo ` -> {' , {
78
+ ast = parser . parseEval ( " echo ` -> {" , {
67
79
parser : { suppressErrors : true , debug : false } ,
68
- lexer : { debug : false } ,
80
+ lexer : { debug : false }
69
81
} ) ;
70
82
} ) ;
71
83
it ( "check infinite on ${" , function ( ) {
72
84
var ast = parser . parseEval ( 'echo "${' , {
73
85
parser : { suppressErrors : true , debug : false } ,
74
- lexer : { debug : false } ,
86
+ lexer : { debug : false }
75
87
} ) ;
76
- ast . children [ 0 ] . arguments [ 0 ] . value [ 0 ] . kind . should . be . exactly ( ' variable' ) ;
77
- ast = parser . parseEval ( ' echo `${' , {
88
+ ast . children [ 0 ] . arguments [ 0 ] . value [ 0 ] . kind . should . be . exactly ( " variable" ) ;
89
+ ast = parser . parseEval ( " echo `${" , {
78
90
parser : { suppressErrors : true , debug : false } ,
79
- lexer : { debug : false } ,
91
+ lexer : { debug : false }
80
92
} ) ;
81
- ast = parser . parseEval ( ' echo ` -> ${' , {
93
+ ast = parser . parseEval ( " echo ` -> ${" , {
82
94
parser : { suppressErrors : true , debug : false } ,
83
- lexer : { debug : false } ,
95
+ lexer : { debug : false }
84
96
} ) ;
85
97
} ) ;
86
98
it ( "check infinite on {$" , function ( ) {
87
99
var ast = parser . parseEval ( 'echo "{$' , {
88
100
parser : { suppressErrors : true , debug : false } ,
89
- lexer : { debug : false } ,
101
+ lexer : { debug : false }
90
102
} ) ;
91
- ast . children [ 0 ] . arguments [ 0 ] . value [ 0 ] . kind . should . be . exactly ( ' variable' ) ;
92
- ast = parser . parseEval ( ' echo `{$' , {
103
+ ast . children [ 0 ] . arguments [ 0 ] . value [ 0 ] . kind . should . be . exactly ( " variable" ) ;
104
+ ast = parser . parseEval ( " echo `{$" , {
93
105
parser : { suppressErrors : true , debug : false } ,
94
- lexer : { debug : false } ,
106
+ lexer : { debug : false }
95
107
} ) ;
96
- ast = parser . parseEval ( ' echo ` -> {$' , {
108
+ ast = parser . parseEval ( " echo ` -> {$" , {
97
109
parser : { suppressErrors : true , debug : false } ,
98
- lexer : { debug : false } ,
110
+ lexer : { debug : false }
99
111
} ) ;
100
112
} ) ;
101
113
it ( "binary cast" , function ( ) {
102
- var ast = parser . parseEval ( 'echo (binary)"\\colors[1] contains >$colors[1]<\\n";' ) ;
114
+ var ast = parser . parseEval (
115
+ 'echo (binary)"\\colors[1] contains >$colors[1]<\\n";'
116
+ ) ;
103
117
// @todo console.log(ast.children[0].arguments[0]);
104
118
} ) ;
105
119
it ( "..." , function ( ) {
@@ -150,7 +164,7 @@ describe("Test strings", function() {
150
164
arg1 . value [ 2 ] . value . should . be . exactly ( "->name !" ) ;
151
165
// test the varname
152
166
arg1 . value [ 1 ] . kind . should . be . exactly ( "variable" ) ;
153
- arg1 . value [ 1 ] . name . should . be . exactly ( "obj" ) ;
167
+ arg1 . value [ 1 ] . name . name . should . be . exactly ( "obj" ) ;
154
168
arg1 . value [ 1 ] . curly . should . be . exactly ( true ) ;
155
169
} ) ;
156
170
it ( "Encapsed variable / curly constant" , function ( ) {
0 commit comments