Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit db1786f

Browse files
committed
sem: tests + fixtures for other escapes
Signed-off-by: Alexander Bezzubov <[email protected]>
1 parent e696d7e commit db1786f

File tree

4 files changed

+161
-13
lines changed

4 files changed

+161
-13
lines changed

driver/normalizer/strconv_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,22 @@ var testCasesUnquoteSingle = []struct {
2626
{`'\0\0'`, "\u0000\u0000", "'\\x00\\x00'"},
2727
}
2828

29+
var testCasesUnquoteDouble = []struct {
30+
quoted string
31+
unquoted string
32+
}{
33+
{`"\0\0\0"`, "\x00\x00\x00"},
34+
{`"\.\."`, "\\.\\."},
35+
}
36+
2937
func TestUnquoteDouble(t *testing.T) {
30-
s, err := unquoteDouble(`"\0\0\0\0\0\0\0\0"`)
31-
require.NoError(t, err)
32-
require.Equal(t, "\x00\x00\x00\x00\x00\x00\x00\x00", s)
38+
for _, test := range testCasesUnquoteDouble {
39+
t.Run("", func(t *testing.T) {
40+
s, err := unquoteDouble(test.quoted)
41+
require.NoError(t, err)
42+
require.Equal(t, test.unquoted, s)
43+
})
44+
}
3345
}
3446

3547
func TestUnquoteSingle(t *testing.T) {

fixtures/string-literal.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ var escComma = '\0COMMA'+Math.random()+'\0';
99
var escPeriod = '\0PERIOD'+Math.random()+'\0';
1010

1111
d = "\0\0\0\0\0\0\0\0"
12+
13+
c = "\.\1 or really \anything"

fixtures/string-literal.js.native

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
comments: [],
3-
end: 279,
3+
end: 311,
44
loc: {
55
end: {
66
column: 0,
7-
line: 12,
7+
line: 14,
88
},
99
start: {
1010
column: 0,
@@ -1225,20 +1225,88 @@
12251225
start: 256,
12261226
type: "ExpressionStatement",
12271227
},
1228+
{
1229+
end: 310,
1230+
expression: {
1231+
end: 310,
1232+
left: {
1233+
end: 281,
1234+
loc: {
1235+
end: {
1236+
column: 1,
1237+
line: 13,
1238+
},
1239+
identifierName: "c",
1240+
start: {
1241+
column: 0,
1242+
line: 13,
1243+
},
1244+
},
1245+
name: "c",
1246+
start: 280,
1247+
type: "Identifier",
1248+
},
1249+
loc: {
1250+
end: {
1251+
column: 30,
1252+
line: 13,
1253+
},
1254+
start: {
1255+
column: 0,
1256+
line: 13,
1257+
},
1258+
},
1259+
operator: "=",
1260+
right: {
1261+
end: 310,
1262+
extra: {
1263+
raw: "\"\\.\\1 or really \\anything\"",
1264+
rawValue: ".\x01 or really anything",
1265+
},
1266+
loc: {
1267+
end: {
1268+
column: 30,
1269+
line: 13,
1270+
},
1271+
start: {
1272+
column: 4,
1273+
line: 13,
1274+
},
1275+
},
1276+
start: 284,
1277+
type: "StringLiteral",
1278+
value: ".\x01 or really anything",
1279+
},
1280+
start: 280,
1281+
type: "AssignmentExpression",
1282+
},
1283+
loc: {
1284+
end: {
1285+
column: 30,
1286+
line: 13,
1287+
},
1288+
start: {
1289+
column: 0,
1290+
line: 13,
1291+
},
1292+
},
1293+
start: 280,
1294+
type: "ExpressionStatement",
1295+
},
12281296
],
12291297
directives: [],
1230-
end: 279,
1298+
end: 311,
12311299
loc: {
12321300
end: {
12331301
column: 0,
1234-
line: 12,
1302+
line: 14,
12351303
},
12361304
start: {
12371305
column: 0,
12381306
line: 1,
12391307
},
12401308
},
1241-
sourceType: "module",
1309+
sourceType: "script",
12421310
start: 0,
12431311
type: "Program",
12441312
},

fixtures/string-literal.js.uast

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
col: 1,
88
},
99
end: { '@type': "uast:Position",
10-
offset: 280,
11-
line: 12,
10+
offset: 312,
11+
line: 14,
1212
col: 1,
1313
},
1414
},
@@ -22,8 +22,8 @@
2222
col: 1,
2323
},
2424
end: { '@type': "uast:Position",
25-
offset: 280,
26-
line: 12,
25+
offset: 312,
26+
line: 14,
2727
col: 1,
2828
},
2929
},
@@ -1207,8 +1207,74 @@
12071207
},
12081208
},
12091209
},
1210+
{ '@type': "ExpressionStatement",
1211+
'@role': [Statement],
1212+
'@pos': { '@type': "uast:Positions",
1213+
start: { '@type': "uast:Position",
1214+
offset: 281,
1215+
line: 13,
1216+
col: 1,
1217+
},
1218+
end: { '@type': "uast:Position",
1219+
offset: 311,
1220+
line: 13,
1221+
col: 31,
1222+
},
1223+
},
1224+
expression: { '@type': "AssignmentExpression",
1225+
'@role': [Assignment, Binary, Expression, Operator],
1226+
'@pos': { '@type': "uast:Positions",
1227+
start: { '@type': "uast:Position",
1228+
offset: 281,
1229+
line: 13,
1230+
col: 1,
1231+
},
1232+
end: { '@type': "uast:Position",
1233+
offset: 311,
1234+
line: 13,
1235+
col: 31,
1236+
},
1237+
},
1238+
left: { '@type': "Identifier",
1239+
'@token': "c",
1240+
'@role': [Assignment, Binary, Expression, Identifier, Left],
1241+
'@pos': { '@type': "uast:Positions",
1242+
start: { '@type': "uast:Position",
1243+
offset: 281,
1244+
line: 13,
1245+
col: 1,
1246+
},
1247+
end: { '@type': "uast:Position",
1248+
offset: 282,
1249+
line: 13,
1250+
col: 2,
1251+
},
1252+
},
1253+
},
1254+
operator: { '@type': "uast:Operator",
1255+
'@token': "=",
1256+
'@role': [Assignment, Binary, Expression, Operator],
1257+
},
1258+
right: { '@type': "StringLiteral",
1259+
'@token': "\"\\.\\1 or really \\anything\"",
1260+
'@role': [Assignment, Binary, Expression, Literal, Right, String],
1261+
'@pos': { '@type': "uast:Positions",
1262+
start: { '@type': "uast:Position",
1263+
offset: 285,
1264+
line: 13,
1265+
col: 5,
1266+
},
1267+
end: { '@type': "uast:Position",
1268+
offset: 311,
1269+
line: 13,
1270+
col: 31,
1271+
},
1272+
},
1273+
},
1274+
},
1275+
},
12101276
],
12111277
directives: [],
1212-
sourceType: "module",
1278+
sourceType: "script",
12131279
},
12141280
}

0 commit comments

Comments
 (0)