-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from fink-lang/fixes
fix(literals): fix escape handling in strings and add regex tests
- Loading branch information
Showing
9 changed files
with
518 additions
and
504 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
import {fink2js} from '../../testing'; | ||
|
||
|
||
test('compiles regex', ()=> { | ||
expect( | ||
fink2js(` | ||
regex1 = rx/ | ||
(?<year>\\d{4})- # year part of a date | ||
(?<month>\\d{2})- # month part of a date | ||
(?<day>\\d{2}) # day part of a date | ||
/gm | ||
describe('regex', ()=> { | ||
it('compiles single line', ()=> { | ||
expect( | ||
fink2js(` | ||
regex = rx/(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})/ | ||
`) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
regex2 = rx/(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})/ | ||
|
||
regex3 = rx/.+\\/.+/ | ||
`) | ||
).toMatchSnapshot(); | ||
it('compiles multiline', ()=> { | ||
expect( | ||
fink2js(` | ||
regex = rx/ | ||
(?<year>\\d{4})- # year part of a date | ||
(?<month>\\d{2})- # month part of a date | ||
(?<day>\\d{2}) # day part of a date | ||
/gm | ||
`) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
|
||
it('compiles escape char', ()=> { | ||
expect( | ||
fink2js(` | ||
regex = rx/.+\\/.+\\\\/ | ||
`) | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`compiles regex 1`] = ` | ||
"const regex1 = /(?<year>\\\\d{4})-(?<month>\\\\d{2})-(?<day>\\\\d{2})/gm; | ||
const regex2 = /(?<year>\\\\d{4})-(?<month>\\\\d{2})-(?<day>\\\\d{2})/; | ||
const regex3 = /.+\\\\/.+/; | ||
exports[`regex compiles escape char 1`] = ` | ||
"const regex = /.+\\\\/.+\\\\\\\\/; | ||
Object.assign(module.exports, { | ||
regex1, | ||
regex2, | ||
regex3 | ||
regex | ||
});" | ||
`; | ||
|
||
exports[`regex compiles multiline 1`] = ` | ||
"const regex = /(?<year>\\\\d{4})-(?<month>\\\\d{2})-(?<day>\\\\d{2})/gm; | ||
Object.assign(module.exports, { | ||
regex | ||
});" | ||
`; | ||
exports[`regex compiles single line 1`] = ` | ||
"const regex = /(?<year>\\\\d{4})-(?<month>\\\\d{2})-(?<day>\\\\d{2})/; | ||
Object.assign(module.exports, { | ||
regex | ||
});" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,58 @@ | ||
import {fink2js} from '../../testing'; | ||
|
||
|
||
test('compiles regex', ()=> { | ||
expect( | ||
fink2js(` | ||
str1 = \` | ||
line 1 | ||
line 2 with leading space | ||
line 3\` | ||
str2 = \`ab\` | ||
str3 = foo\`bar spam \${shrub + ni} na\` | ||
str4 = \` | ||
bar | ||
spam \${shrub + ni}\${foo} | ||
ni | ||
\` | ||
`) | ||
).toMatchSnapshot(); | ||
describe('string', ()=> { | ||
|
||
it('compiles simple', ()=> { | ||
expect( | ||
fink2js(` | ||
str = 'ab' | ||
`) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
|
||
it('compiles multiline', ()=> { | ||
expect( | ||
fink2js(` | ||
str = ' | ||
line 1 | ||
line 2 with leading space | ||
line 3' | ||
`) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
|
||
it('compiles escape chars', ()=> { | ||
expect( | ||
fink2js(` | ||
${"str1 = 'foo`bar\\nspam`ni'"} | ||
${'str2 = `foo\\`bar`'} | ||
${'str3 = "foo\\\\"'} | ||
`) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
|
||
it('compiles tagged template string', ()=> { | ||
expect( | ||
fink2js(` | ||
str = foo'bar \${spam ni shrub} na' | ||
`) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
|
||
it('compiles multiline with expressions', ()=> { | ||
expect( | ||
fink2js(` | ||
str = ' | ||
bar | ||
spam \${shrub + ni}\${foo} | ||
ni | ||
' | ||
`) | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,45 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`compiles regex 1`] = ` | ||
"const str1 = \`line 1 | ||
exports[`string compiles escape chars 1`] = ` | ||
"const str1 = \`foo\\\\\`bar\\\\nspam\\\\\`ni\`; | ||
const str2 = \`foo\\\\\`bar\`; | ||
const str3 = \`foo\\\\\\\\\`; | ||
Object.assign(module.exports, { | ||
str1, | ||
str2, | ||
str3 | ||
});" | ||
`; | ||
|
||
exports[`string compiles multiline 1`] = ` | ||
"const str = \`line 1 | ||
line 2 with leading space | ||
line 3\`; | ||
const str2 = \`ab\`; | ||
const str3 = foo\`bar spam \${shrub + ni} na\`; | ||
const str4 = \`bar | ||
spam \${shrub + ni}\${foo} | ||
Object.assign(module.exports, { | ||
str | ||
});" | ||
`; | ||
|
||
exports[`string compiles multiline with expressions 1`] = ` | ||
"const str = \`bar | ||
spam \${shrub + ni}\${foo} | ||
ni | ||
\`; | ||
Object.assign(module.exports, { | ||
str1, | ||
str2, | ||
str3, | ||
str4 | ||
str | ||
});" | ||
`; | ||
|
||
exports[`string compiles simple 1`] = ` | ||
"const str = \`ab\`; | ||
Object.assign(module.exports, { | ||
str | ||
});" | ||
`; | ||
|
||
exports[`string compiles tagged template string 1`] = ` | ||
"const str = foo\`bar \${ni(spam, shrub)} na\`; | ||
Object.assign(module.exports, { | ||
str | ||
});" | ||
`; |