Sha256: b3b60220331256fe15ac396ebd54bda2e2e5be590bb0d39b4b36552f515f854c

Contents?: true

Size: 1.46 KB

Versions: 7

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[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('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

7 entries across 7 versions & 1 rubygems

Version Path
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
entangled-0.0.14 spec/dummy/public/node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
entangled-0.0.13 spec/dummy/public/node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
entangled-0.0.12 spec/dummy/public/node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
entangled-0.0.11 spec/dummy/public/node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js
entangled-0.0.10 spec/dummy/public/node_modules/bower/node_modules/cardinal/test/cardinal-highlight-json.js