Skip to content

Commit

Permalink
improved tests to handle newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Pike committed Apr 26, 2018
1 parent 9aebcad commit 21448e0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
21 changes: 17 additions & 4 deletions tests/basic-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var assert = require('assert'),
colors = require('../lib/index');
colors = require('../lib/index');

var s = 'string';

Expand Down Expand Up @@ -43,8 +43,21 @@ aE(s, 'yellow', 33);

assert.equal(s, 'string');

colors.setTheme({error:'red'});
var testStringWithNewLines = s + `
` + s;

assert.equal(typeof("astring".red),'string');
assert.equal(typeof("astring".error),'string');
// single style
assert.equal(testStringWithNewLines.red, '\x1b[31m' + s + '\n' + s + '\x1b[39m');

var testStringWithNewLinesStyled = s.underline + `
` + s.bold;

// nested styles
assert.equal(testStringWithNewLinesStyled.red, '\x1b[31m' + '\x1b[4m' + s + '\x1b[24m' + '\n' + '\x1b[1m' + s + '\x1b[22m' + '\x1b[39m');

colors.setTheme({ error: 'red' });

assert.equal(typeof ("astring".red), 'string');
assert.equal(typeof ("astring".error), 'string');

assert.equal(s, 'string');
21 changes: 17 additions & 4 deletions tests/safe-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var assert = require('assert'),
colors = require('../safe');
colors = require('../safe');

var s = 'string';

Expand Down Expand Up @@ -39,7 +39,20 @@ aE(s, 'red', 31);
aE(s, 'yellow', 33);

assert.equal(s, 'string');
colors.setTheme({error:'red'});

assert.equal(typeof(colors.red("astring")), 'string');
assert.equal(typeof(colors.error("astring")), 'string');
var testStringWithNewLines = s + `
` + s;

// single style
assert.equal(colors.red(testStringWithNewLines), '\x1b[31m' + s + '\x1b[39m' + '\n' + '\x1b[31m' + s + '\x1b[39m');

var testStringWithNewLinesStyled = colors.underline(s) + `
` + colors.bold(s);

// nested styles
assert.equal(colors.red(testStringWithNewLinesStyled), '\x1b[31m' + '\x1b[4m' + s + '\x1b[24m' + '\x1b[39m' + '\n' + '\x1b[31m' + '\x1b[1m' + s + '\x1b[22m' + '\x1b[39m');

colors.setTheme({ error: 'red' });

assert.equal(typeof (colors.red("astring")), 'string');
assert.equal(typeof (colors.error("astring")), 'string');

0 comments on commit 21448e0

Please sign in to comment.