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

Commit

Permalink
sem: tests + fixtures for other escapes
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Bezzubov <[email protected]>
  • Loading branch information
bzz committed Mar 29, 2019
1 parent 65c306a commit 758380a
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 13 deletions.
18 changes: 15 additions & 3 deletions driver/normalizer/strconv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,22 @@ var testCasesUnquoteSingle = []struct {
{`'\0\0'`, "\u0000\u0000", "'\\x00\\x00'"},
}

var testCasesUnquoteDouble = []struct {
quoted string
unquoted string
}{
// {`"\0\0\0"`, "\x00\x00\x00"},
{`"\.\."`, "\\.\\."},
}

func TestUnquoteDouble(t *testing.T) {
s, err := unquoteDouble(`"\0\0\0\0\0\0\0\0"`)
require.NoError(t, err)
require.Equal(t, "\x00\x00\x00\x00\x00\x00\x00\x00", s)
for _, test := range testCasesUnquoteDouble {
t.Run("", func(t *testing.T) {
s, err := unquoteDouble(test.quoted)
require.NoError(t, err)
require.Equal(t, test.unquoted, s)
})
}
}

func TestUnquoteSingle(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions fixtures/string-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ var escComma = '\0COMMA'+Math.random()+'\0';
var escPeriod = '\0PERIOD'+Math.random()+'\0';

d = "\0\0\0\0\0\0\0\0"

c = "\.\1 or really \anthining"
78 changes: 73 additions & 5 deletions fixtures/string-literal.js.native
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
comments: [],
end: 279,
end: 312,
loc: {
end: {
column: 0,
line: 12,
line: 14,
},
start: {
column: 0,
Expand Down Expand Up @@ -1225,20 +1225,88 @@
start: 256,
type: "ExpressionStatement",
},
{
end: 311,
expression: {
end: 311,
left: {
end: 281,
loc: {
end: {
column: 1,
line: 13,
},
identifierName: "c",
start: {
column: 0,
line: 13,
},
},
name: "c",
start: 280,
type: "Identifier",
},
loc: {
end: {
column: 31,
line: 13,
},
start: {
column: 0,
line: 13,
},
},
operator: "=",
right: {
end: 311,
extra: {
raw: "\"\\.\\1 or really \\anthining\"",
rawValue: ".\x01 or really anthining",
},
loc: {
end: {
column: 31,
line: 13,
},
start: {
column: 4,
line: 13,
},
},
start: 284,
type: "StringLiteral",
value: ".\x01 or really anthining",
},
start: 280,
type: "AssignmentExpression",
},
loc: {
end: {
column: 31,
line: 13,
},
start: {
column: 0,
line: 13,
},
},
start: 280,
type: "ExpressionStatement",
},
],
directives: [],
end: 279,
end: 312,
loc: {
end: {
column: 0,
line: 12,
line: 14,
},
start: {
column: 0,
line: 1,
},
},
sourceType: "module",
sourceType: "script",
start: 0,
type: "Program",
},
Expand Down
76 changes: 71 additions & 5 deletions fixtures/string-literal.js.uast
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
col: 1,
},
end: { '@type': "uast:Position",
offset: 280,
line: 12,
offset: 313,
line: 14,
col: 1,
},
},
Expand All @@ -22,8 +22,8 @@
col: 1,
},
end: { '@type': "uast:Position",
offset: 280,
line: 12,
offset: 313,
line: 14,
col: 1,
},
},
Expand Down Expand Up @@ -1207,8 +1207,74 @@
},
},
},
{ '@type': "ExpressionStatement",
'@role': [Statement],
'@pos': { '@type': "uast:Positions",
start: { '@type': "uast:Position",
offset: 281,
line: 13,
col: 1,
},
end: { '@type': "uast:Position",
offset: 312,
line: 13,
col: 32,
},
},
expression: { '@type': "AssignmentExpression",
'@role': [Assignment, Binary, Expression, Operator],
'@pos': { '@type': "uast:Positions",
start: { '@type': "uast:Position",
offset: 281,
line: 13,
col: 1,
},
end: { '@type': "uast:Position",
offset: 312,
line: 13,
col: 32,
},
},
left: { '@type': "Identifier",
'@token': "c",
'@role': [Assignment, Binary, Expression, Identifier, Left],
'@pos': { '@type': "uast:Positions",
start: { '@type': "uast:Position",
offset: 281,
line: 13,
col: 1,
},
end: { '@type': "uast:Position",
offset: 282,
line: 13,
col: 2,
},
},
},
operator: { '@type': "uast:Operator",
'@token': "=",
'@role': [Assignment, Binary, Expression, Operator],
},
right: { '@type': "StringLiteral",
'@token': "\"\\.\\1 or really \\anthining\"",
'@role': [Assignment, Binary, Expression, Literal, Right, String],
'@pos': { '@type': "uast:Positions",
start: { '@type': "uast:Position",
offset: 285,
line: 13,
col: 5,
},
end: { '@type': "uast:Position",
offset: 312,
line: 13,
col: 32,
},
},
},
},
},
],
directives: [],
sourceType: "module",
sourceType: "script",
},
}

0 comments on commit 758380a

Please sign in to comment.