Sha256: ec3d209ca68c956ed7188c41be8801f27068f53ccc2a68a10d47af803dbee3ff

Contents?: true

Size: 1.46 KB

Versions: 62

Compression:

Stored size: 1.46 KB

Contents

'use strict';
/*jshint asi: true*/

var test = require('tap').test
  , util = require('util')
  , customTheme = require('./fixtures/custom') 
  , cardinal = require('..')


function inspect (obj) {
  return console.log(util.inspect(obj, false, 5, false))
}

var json = JSON.stringify({
  foo: 'bar',
  baz: 'quux',
  bam: null
});

test('supplying custom theme', function (t) {
  var highlighted = cardinal.highlight(json, { json: true, theme: customTheme });

  t.equals(highlighted, '\u001b[33m{\u001b[39m\u001b[92m"foo"\u001b[39m\u001b[93m:\u001b[39m\u001b[92m"bar"\u001b[39m\u001b[32m,\u001b[39m\u001b[92m"baz"\u001b[39m\u001b[93m:\u001b[39m\u001b[92m"quux"\u001b[39m\u001b[32m,\u001b[39m\u001b[92m"bam"\u001b[39m\u001b[93m:\u001b[39m\u001b[90mnull\u001b[39m\u001b[33m}\u001b[39m')
  t.end();
});

test('not supplying custom theme', function (t) {
  var highlighted = cardinal.highlight(json, { json: true });

  t.equals(highlighted, '\u001b[33m{\u001b[39m\u001b[32m"foo"\u001b[39m\u001b[93m:\u001b[39m\u001b[92m"bar"\u001b[39m\u001b[32m,\u001b[39m\u001b[32m"baz"\u001b[39m\u001b[93m:\u001b[39m\u001b[92m"quux"\u001b[39m\u001b[32m,\u001b[39m\u001b[32m"bam"\u001b[39m\u001b[93m:\u001b[39m\u001b[90mnull\u001b[39m\u001b[33m}\u001b[39m')
  t.end();
});

test('without json option', function (t) {
  try {
    cardinal.highlight(json);
  } catch (e) {
    t.similar(e.message, /Unable to perform highlight. The code contained syntax errors.* Line 1: Unexpected token /)
    t.end();
  }
});

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.8 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.7 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.6 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.5 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
trusty-festivity-extension-2.5.4 node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js