Skip to content

Commit

Permalink
Rewrited tests
Browse files Browse the repository at this point in the history
  • Loading branch information
exdis committed Jul 25, 2019
1 parent db2db25 commit 6092205
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 292 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fs = require('fs');
const path = require('path');
const cli = require('clap');
const jora = require('jora/dist/jora');
const { colorize } = require('./utils/colorize');
const colorize = require('./utils/colorize');

function readFromStream(stream, processBuffer) {
const buffer = [];
Expand Down Expand Up @@ -91,7 +91,7 @@ function processStream(options) {
if (options.outputFile) {
fs.writeFileSync(options.outputFile, serializedResult, 'utf-8');
} else {
const result = options.noColor ? serializeResult : colorize(serializedResult);
const result = options.color ? colorize(serializedResult) : serializedResult;
console.log(result);
}
});
Expand Down
20 changes: 17 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"coveralls": "nyc report --reporter=text-lcov | coveralls"
},
"dependencies": {
"ansi-regex": "^4.1.0",
"chalk": "^2.4.2",
"clap": "^1.0.9",
"jora": "1.0.0-alpha.10"
Expand Down
15 changes: 15 additions & 0 deletions test/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"string": "st\"ri\u1234ng",
"number": 1234,
"emptyArray": [],
"emptyObject": {},
"null": null,
"false": false,
"true": true,
"complexJSON": {
"f\"oo\u01234"
:-0.1234, "bar": 0e-3,
"ba/": -0.1234e12,
"quux": 1.123
}
}
251 changes: 0 additions & 251 deletions test/fixtures.js

This file was deleted.

23 changes: 23 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const {
LEFT_BRACE,
RIGHT_BRACE,
LEFT_BRACKET,
RIGHT_BRACKET,
STRING,
NUMBER,
NULL,
FALSE,
TRUE
} = require('../utils/constants').TOKENS;
const { TOKEN_COLORS } = require('../utils/constants');
const ansiRegex = require('ansi-regex');

module.exports = {
STRING: TOKEN_COLORS[STRING](' ').match(ansiRegex()),
NUMBER: TOKEN_COLORS[NUMBER](' ').match(ansiRegex()),
EMPTY_ARRAY: [...TOKEN_COLORS[LEFT_BRACKET](' ').match(ansiRegex()), ...TOKEN_COLORS[RIGHT_BRACKET](' ').match(ansiRegex())],
EMPTY_OBJECT: [...TOKEN_COLORS[LEFT_BRACE](' ').match(ansiRegex()), ...TOKEN_COLORS[RIGHT_BRACE](' ').match(ansiRegex())],
NULL: TOKEN_COLORS[NULL](' ').match(ansiRegex()),
FALSE: TOKEN_COLORS[FALSE](' ').match(ansiRegex()),
TRUE: TOKEN_COLORS[TRUE](' ').match(ansiRegex())
};
Loading

0 comments on commit 6092205

Please sign in to comment.