-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
81 lines (67 loc) · 2.74 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*eslint quotes: [0]*/
'use strict';
require('mocha');
var assert = require('assert');
var regex = require('./');
describe('regex', function() {
describe('single quotes', function() {
it('should match single-quoted strings', function() {
var match = `var foo = 'bar';`.match(regex());
assert.equal(match[0], `'bar'`);
});
it('should match empty single-quoted strings', function() {
var match = `var foo = '';`.match(regex());
assert.equal(match[0], `''`);
});
});
describe('double quotes', function() {
it('should match double-quoted strings', function() {
var match = 'var foo = "bar";'.match(regex());
assert.equal(match[0], '"bar"');
});
it('should match empty double-quoted strings', function() {
assert.equal('var foo = "";'.match(regex())[0], '""');
assert.equal('var foo = "\'\'";'.match(regex())[0], '"\'\'"');
assert.equal(regex().exec('var foo = "\'\'";')[2], '\'\'');
});
});
describe('backticks', function() {
it('should match strings in backticks', function() {
var match = 'var foo = `${bar}`;'.match(regex());
assert.equal(match[0], '`${bar}`');
});
it('should match empty strings in backticks', function() {
assert.equal('var foo = ``;'.match(regex())[0], '``');
assert.equal('var foo = `""`;'.match(regex())[0], '`""`');
assert.equal(regex().exec('var foo = `\'\'`;')[2], '\'\'');
});
});
describe('multiple', function() {
it('should match multiple quoted strings', function() {
var match = `var foo = "one";\nvar bar = 'two'\nvar baz = \`three\``.match(regex());
assert.equal(match[0], '"one"');
assert.equal(match[1], `'two'`);
assert.equal(match[2], `\`three\``);
});
});
describe('escaping', function() {
it('should work with escaped quotes', function() {
var double = `var foo = "bar\\"baz";`.match(regex());
assert.equal(double[0], '"bar\\"baz"');
var single = `var foo = 'bar\\'baz';`.match(regex());
assert.equal(single[0], `'bar\\'baz'`);
var both = `var foo = '"bar\\'\\"\\'baz"';`.match(regex());
assert.equal(both[0], `'"bar\\'\\"\\'baz"'`);
});
it('should match complex nested quotes', function() {
var double = `foo bar ". // ' \\" \\ . // ' \\ ." baz`.match(regex());
assert.equal(double[0], `". // ' \\" \\ . // ' \\ ."`);
var single = `foo bar '. // \\' \\" \\ . // \\' \\ .' baz`.match(regex());
assert.equal(single[0], `'. // \\' \\" \\ . // \\' \\ .'`);
});
it('should create a match for the inner string', function() {
var inner = regex().exec(`foo bar \\" \\' '. // \\' \\" \\ . // \\' \\ .' \\'\\' baz`);
assert.equal(inner[2], '. // \\\' \\" \\ . // \\\' \\ .');
});
});
});