Sha256: c03df9d6428d694b3402eb093c743a320243e61256f0edca4d9242b7f5ed1918

Contents?: true

Size: 1.41 KB

Versions: 11

Compression:

Stored size: 1.41 KB

Contents

var test = require('tap').test
var jsStringEscape = require('../')

// Require the local copy of Punycode.js, as we don't want to use the outdated
// version that shipped with Node v0.8:
var punycode = require('./../node_modules/punycode/punycode.js')

test('basic use', function (t) {
  t.equal(jsStringEscape('"Hello World!"'), '\\"Hello World!\\"')
  t.end()
})

test('invariants', function (t) {
  var allCharacters = ''
  var i
  // The Punycode.js version that ships with Node v0.8 won't create unmatched
  // surrogate halves, so let's use `String.fromCharCode` for BMP code points.
  for (i = 0; i <= 0x00FFFF; i++) {
    allCharacters += String.fromCharCode(i)
  }
  // Generate strings based on astral code points. Trickier than it seems:
  // http://mathiasbynens.be/notes/javascript-encoding
  for (i = 0x010000; i <= 0x10FFFF; i++) {
    allCharacters += punycode.ucs2.encode([ i ])
  }

  var escaped = jsStringEscape(allCharacters);

  // Do not use .equal; mega-diffs in the output are not helpful.
  t.ok(eval("'" + escaped + "'") === allCharacters)
  t.ok(eval('"' + escaped + '"') === allCharacters)
  t.end()
})

test('supports arbitrary objects', function (t) {
  t.equal(jsStringEscape(null), 'null')
  t.equal(jsStringEscape(undefined), 'undefined')
  t.equal(jsStringEscape(false), 'false')
  t.equal(jsStringEscape(0.0), '0')
  t.equal(jsStringEscape({}), '[object Object]')
  t.equal(jsStringEscape(''), '')
  t.end()
})

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
webpack_rails-2.0.1 lib/webpack_rails/node_modules/js-string-escape/test/test.js
webpack_rails-2.0.0 lib/webpack_rails/node_modules/js-string-escape/test/test.js
webpack_rails-1.3.1 lib/webpack_rails/node_modules/js-string-escape/test/test.js
webpack_rails-1.3.0 lib/webpack_rails/node_modules/js-string-escape/test/test.js
webpack_rails-1.2.2 lib/webpack_rails/node_modules/js-string-escape/test/test.js
webpack_rails-1.2.1 lib/webpack_rails/node_modules/js-string-escape/test/test.js
webpack_rails-1.2.0 lib/webpack_rails/node_modules/js-string-escape/test/test.js
webpack_rails-1.1.1 lib/webpack_rails/node_modules/js-string-escape/test/test.js
webpack_rails-1.1.0 lib/webpack_rails/node_modules/js-string-escape/test/test.js
webpack_rails-1.0.1 lib/webpack_rails/node_modules/js-string-escape/test/test.js
webpack_rails-1.0.0 lib/webpack_rails/node_modules/js-string-escape/test/test.js