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 more failing escape seq
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Bezzubov <[email protected]>
  • Loading branch information
bzz committed Apr 3, 2019
1 parent e5d8d05 commit 5c17858
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 11 deletions.
11 changes: 8 additions & 3 deletions driver/normalizer/strconv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@ var testCasesUnquoteSingle = []struct {
{`'\0something\0else'`, "\u0000something\u0000else", "'\\x00something\\x00else'"},
{`'\u0000123\0s'`, "\u0000123\u0000s", "'\\x00123\\x00s'"},
{`'\0\0'`, "\u0000\u0000", "'\\x00\\x00'"},
{`'\01'`, "\u0001", "'\\x01'"},
}

var testCasesUnquoteDouble = []struct {
quoted string
unquoted string
}{
{`"\0\0\0"`, "\x00\x00\x00"},
{`"\.\."`, "\\.\\."},
{`"\a"`, "a"},
{`"\.\."`, ".."},
{`"\1"`, "1"},
{`"\01"`, "1"},
{`"\u{1D306}"`, "𝌆"},
}

func TestUnquoteDouble(t *testing.T) {
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)
assertEquals(t, test.unquoted, s)
})
}
}
Expand All @@ -49,7 +54,7 @@ func TestUnquoteSingle(t *testing.T) {
t.Run("", func(t *testing.T) {
s, err := unquoteSingle(test.quoted)
require.NoError(t, err)
require.Equal(t, test.unquoted, s)
assertEquals(t, test.unquoted, s)
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions fixtures/string-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ var escPeriod = '\0PERIOD'+Math.random()+'\0';
d = "\0\0\0\0\0\0\0\0"

c = "\.\1 or really \anything"

f = "\u{1D306}"
76 changes: 72 additions & 4 deletions fixtures/string-literal.js.native
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
comments: [],
end: 311,
end: 328,
loc: {
end: {
column: 0,
line: 14,
line: 16,
},
start: {
column: 0,
Expand Down Expand Up @@ -1293,13 +1293,81 @@
start: 280,
type: "ExpressionStatement",
},
{
end: 327,
expression: {
end: 327,
left: {
end: 313,
loc: {
end: {
column: 1,
line: 15,
},
identifierName: "f",
start: {
column: 0,
line: 15,
},
},
name: "f",
start: 312,
type: "Identifier",
},
loc: {
end: {
column: 15,
line: 15,
},
start: {
column: 0,
line: 15,
},
},
operator: "=",
right: {
end: 327,
extra: {
raw: "\"\\u{1D306}\"",
rawValue: "𝌆",
},
loc: {
end: {
column: 15,
line: 15,
},
start: {
column: 4,
line: 15,
},
},
start: 316,
type: "StringLiteral",
value: "𝌆",
},
start: 312,
type: "AssignmentExpression",
},
loc: {
end: {
column: 15,
line: 15,
},
start: {
column: 0,
line: 15,
},
},
start: 312,
type: "ExpressionStatement",
},
],
directives: [],
end: 311,
end: 328,
loc: {
end: {
column: 0,
line: 14,
line: 16,
},
start: {
column: 0,
Expand Down
74 changes: 70 additions & 4 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: 312,
line: 14,
offset: 329,
line: 16,
col: 1,
},
},
Expand All @@ -22,8 +22,8 @@
col: 1,
},
end: { '@type': "uast:Position",
offset: 312,
line: 14,
offset: 329,
line: 16,
col: 1,
},
},
Expand Down Expand Up @@ -1273,6 +1273,72 @@
},
},
},
{ '@type': "ExpressionStatement",
'@role': [Statement],
'@pos': { '@type': "uast:Positions",
start: { '@type': "uast:Position",
offset: 313,
line: 15,
col: 1,
},
end: { '@type': "uast:Position",
offset: 328,
line: 15,
col: 16,
},
},
expression: { '@type': "AssignmentExpression",
'@role': [Assignment, Binary, Expression, Operator],
'@pos': { '@type': "uast:Positions",
start: { '@type': "uast:Position",
offset: 313,
line: 15,
col: 1,
},
end: { '@type': "uast:Position",
offset: 328,
line: 15,
col: 16,
},
},
left: { '@type': "Identifier",
'@token': "f",
'@role': [Assignment, Binary, Expression, Identifier, Left],
'@pos': { '@type': "uast:Positions",
start: { '@type': "uast:Position",
offset: 313,
line: 15,
col: 1,
},
end: { '@type': "uast:Position",
offset: 314,
line: 15,
col: 2,
},
},
},
operator: { '@type': "uast:Operator",
'@token': "=",
'@role': [Assignment, Binary, Expression, Operator],
},
right: { '@type': "StringLiteral",
'@token': "\"\\u{1D306}\"",
'@role': [Assignment, Binary, Expression, Literal, Right, String],
'@pos': { '@type': "uast:Positions",
start: { '@type': "uast:Position",
offset: 317,
line: 15,
col: 5,
},
end: { '@type': "uast:Position",
offset: 328,
line: 15,
col: 16,
},
},
},
},
},
],
directives: [],
sourceType: "script",
Expand Down

0 comments on commit 5c17858

Please sign in to comment.