Skip to content

Commit

Permalink
Cleanup tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjmnt4n committed Jan 17, 2018
1 parent 246e923 commit 79ea403
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ node_js:
- "0.10"
- "0.12"
- "4"
- "5"
- "6"
- "8"
git:
depth: 10
before_install:
Expand Down
6 changes: 6 additions & 0 deletions tests/test-data-unicode.json
Original file line number Diff line number Diff line change
Expand Up @@ -892,5 +892,11 @@
16
],
"raw": "(?:\\uD83D\\uDCA9)"
},
"\\u{110000}": {
"type": "error",
"name": "SyntaxError",
"message":"Invalid escape sequence at position 1\n \\u{110000}\n ^",
"input":"\\u{110000}"
}
}
21 changes: 11 additions & 10 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ var parse = require('regjsparser').parse;

function runTests(data, excused, flags, features) {
excused || (excused = []);
flags || (flags = '');
var keys = Object.keys(data).filter(function(name) {
return data[name].type != 'error' && excused.indexOf(name) == -1;
});

keys.forEach(function(regex) {
var node = data[regex],
expected = JSON.stringify(regex),
generated;

try {
generated = JSON.stringify(generate(node));
} catch (error) {
var isError = true,
stack = error.stack;
generated = JSON.stringify({
name: error.name,
message: error.message,
input: regex
'name': error.name,
'message': error.message,
'input': regex
});
}

Expand All @@ -30,9 +31,9 @@ function runTests(data, excused, flags, features) {
} catch (error) {
var stack = error.stack;
generated = JSON.stringify({
name: error.name,
message: error.message,
input: regex
'name': error.name,
'message': error.message,
'input': regex
});
}
}
Expand Down Expand Up @@ -63,6 +64,6 @@ runTests(require('./test-data.json'));
runTests(require('./test-data-nonstandard.json'));
runTests(require('./test-data-unicode.json'), null, 'u');
runTests(require('./test-data-unicode-properties.json'), null, 'u', { 'unicodePropertyEscape': true });
runTests(require('./test-data-named-groups.json'), null, '', { namedGroups: true });
runTests(require('./test-data-named-groups-unicode.json'), null, 'u', { namedGroups: true });
runTests(require('./test-data-named-groups-unicode-properties.json'), null, 'u', { namedGroups: true, unicodePropertyEscape: true });
runTests(require('./test-data-named-groups.json'), null, '', { 'namedGroups': true });
runTests(require('./test-data-named-groups-unicode.json'), null, 'u', { 'namedGroups': true });
runTests(require('./test-data-named-groups-unicode-properties.json'), null, 'u', { 'namedGroups': true, 'unicodePropertyEscape': true });
21 changes: 9 additions & 12 deletions tests/update-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ var fs = require('fs'),
function saveFile(url, name) {
name || (name = url.slice(url.lastIndexOf('/') + 1));

request.get(url, function(err, response, body) {
if (err) {
request.get(url)
.on('error', function(err) {
console.log(err);
} else {
fs.writeFile(path.join(__dirname, name), body, function() {
if (err) {
console.log(err);
} else {
console.log('`%s` updated successfully.', name);
}
});
}
});
})
.pipe(
fs.createWriteStream(path.join(__dirname, name))
)
.on('finish', function() {
console.log('`%s` updated successfully.', name);
});
}

saveFile('https://raw.githubusercontent.com/jviereck/regjsparser/gh-pages/test/test-data.json');
Expand Down

0 comments on commit 79ea403

Please sign in to comment.