|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const test = require('tap').test |
| 4 | +const validator = require('is-my-json-valid') |
| 5 | +const build = require('..') |
| 6 | + |
| 7 | +test(`render a string with surrogate pairs as JSON:test 1`, (t) => { |
| 8 | + t.plan(2) |
| 9 | + |
| 10 | + const schema = { |
| 11 | + title: 'surrogate', |
| 12 | + type: 'string' |
| 13 | + } |
| 14 | + |
| 15 | + const validate = validator(schema) |
| 16 | + const stringify = build(schema) |
| 17 | + const output = stringify('𝌆') |
| 18 | + |
| 19 | + t.equal(output, '"𝌆"') |
| 20 | + t.ok(validate(JSON.parse(output)), 'valid schema') |
| 21 | +}) |
| 22 | + |
| 23 | +test(`render a string with surrogate pairs as JSON: test 2`, (t) => { |
| 24 | + t.plan(2) |
| 25 | + |
| 26 | + const schema = { |
| 27 | + title: 'long', |
| 28 | + type: 'string' |
| 29 | + } |
| 30 | + |
| 31 | + const validate = validator(schema) |
| 32 | + const stringify = build(schema) |
| 33 | + const output = stringify('\uD834\uDF06') |
| 34 | + |
| 35 | + t.equal(output, '"𝌆"') |
| 36 | + t.ok(validate(JSON.parse(output)), 'valid schema') |
| 37 | +}) |
| 38 | + |
| 39 | +test(`render a string with Unpaired surrogate code as JSON`, (t) => { |
| 40 | + t.plan(2) |
| 41 | + |
| 42 | + const schema = { |
| 43 | + title: 'surrogate', |
| 44 | + type: 'string' |
| 45 | + } |
| 46 | + |
| 47 | + const validate = validator(schema) |
| 48 | + const stringify = build(schema) |
| 49 | + const output = stringify('\uDF06\uD834') |
| 50 | + t.equal(output, JSON.stringify('\uDF06\uD834')) |
| 51 | + t.ok(validate(JSON.parse(output)), 'valid schema') |
| 52 | +}) |
| 53 | + |
| 54 | +test(`render a string with lone surrogate code as JSON`, (t) => { |
| 55 | + t.plan(2) |
| 56 | + |
| 57 | + const schema = { |
| 58 | + title: 'surrogate', |
| 59 | + type: 'string' |
| 60 | + } |
| 61 | + |
| 62 | + const validate = validator(schema) |
| 63 | + const stringify = build(schema) |
| 64 | + const output = stringify('\uDEAD') |
| 65 | + t.equal(output, JSON.stringify('\uDEAD')) |
| 66 | + t.ok(validate(JSON.parse(output)), 'valid schema') |
| 67 | +}) |
0 commit comments