Run lebab on test folder: convert let/const and arrow functions
This commit is contained in:
parent
531ddc5c74
commit
e67fa19375
|
@ -1,13 +1,13 @@
|
||||||
var assert = require('assert')
|
const assert = require('assert')
|
||||||
var setUpTestEnvironment = require('./setup')
|
const setUpTestEnvironment = require('./setup')
|
||||||
setUpTestEnvironment()
|
setUpTestEnvironment()
|
||||||
|
|
||||||
var Node = require('../src/js/Node')
|
const Node = require('../src/js/Node')
|
||||||
|
|
||||||
describe('Node', function () {
|
describe('Node', () => {
|
||||||
describe('_findSchema', function () {
|
describe('_findSchema', () => {
|
||||||
it('should find schema', function () {
|
it('should find schema', () => {
|
||||||
var schema = {
|
const schema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
child: {
|
child: {
|
||||||
|
@ -15,12 +15,12 @@ describe('Node', function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var path = ['child']
|
const path = ['child']
|
||||||
assert.strictEqual(Node._findSchema(schema, {}, path), schema.properties.child)
|
assert.strictEqual(Node._findSchema(schema, {}, path), schema.properties.child)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should find schema inside an array item', function () {
|
it('should find schema inside an array item', () => {
|
||||||
var schema = {
|
const schema = {
|
||||||
properties: {
|
properties: {
|
||||||
job: {
|
job: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
|
@ -47,8 +47,8 @@ describe('Node', function () {
|
||||||
schema.properties.job.items.properties.company)
|
schema.properties.job.items.properties.company)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should find schema within multi-level object properties', function () {
|
it('should find schema within multi-level object properties', () => {
|
||||||
var schema = {
|
const schema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
levelTwo: {
|
levelTwo: {
|
||||||
|
@ -66,7 +66,7 @@ describe('Node', function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var path = []
|
let path = []
|
||||||
assert.strictEqual(Node._findSchema(schema, {}, path), schema)
|
assert.strictEqual(Node._findSchema(schema, {}, path), schema)
|
||||||
path = ['levelTwo']
|
path = ['levelTwo']
|
||||||
assert.strictEqual(Node._findSchema(schema, {}, path), schema.properties.levelTwo)
|
assert.strictEqual(Node._findSchema(schema, {}, path), schema.properties.levelTwo)
|
||||||
|
@ -79,8 +79,8 @@ describe('Node', function () {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return null for path that has no schema', function () {
|
it('should return null for path that has no schema', () => {
|
||||||
var schema = {
|
const schema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
foo: {
|
foo: {
|
||||||
|
@ -93,15 +93,15 @@ describe('Node', function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var path = ['bar']
|
let path = ['bar']
|
||||||
assert.strictEqual(Node._findSchema(schema, {}, path), null)
|
assert.strictEqual(Node._findSchema(schema, {}, path), null)
|
||||||
path = ['foo', 'bar']
|
path = ['foo', 'bar']
|
||||||
assert.strictEqual(Node._findSchema(schema, {}, path), null)
|
assert.strictEqual(Node._findSchema(schema, {}, path), null)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with $ref', function () {
|
describe('with $ref', () => {
|
||||||
it('should find a referenced schema', function () {
|
it('should find a referenced schema', () => {
|
||||||
var schema = {
|
const schema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
foo: {
|
foo: {
|
||||||
|
@ -109,18 +109,18 @@ describe('Node', function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var fooSchema = {
|
const fooSchema = {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
title: 'Foo'
|
title: 'Foo'
|
||||||
}
|
}
|
||||||
var path = ['foo']
|
const path = ['foo']
|
||||||
assert.strictEqual(Node._findSchema(schema, { foo: fooSchema }, path), fooSchema)
|
assert.strictEqual(Node._findSchema(schema, { foo: fooSchema }, path), fooSchema)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('with pattern properties', function () {
|
describe('with pattern properties', () => {
|
||||||
it('should find schema', function () {
|
it('should find schema', () => {
|
||||||
var schema = {
|
const schema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
str: {
|
str: {
|
||||||
|
@ -135,14 +135,14 @@ describe('Node', function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var path = []
|
let path = []
|
||||||
assert.strictEqual(Node._findSchema(schema, {}, path), schema, 'top level')
|
assert.strictEqual(Node._findSchema(schema, {}, path), schema, 'top level')
|
||||||
path = ['str']
|
path = ['str']
|
||||||
assert.strictEqual(Node._findSchema(schema, {}, path), schema.properties.str, 'normal property')
|
assert.strictEqual(Node._findSchema(schema, {}, path), schema.properties.str, 'normal property')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should find schema within multi-level object properties', function () {
|
it('should find schema within multi-level object properties', () => {
|
||||||
var schema = {
|
const schema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
levelTwo: {
|
levelTwo: {
|
||||||
|
@ -167,7 +167,7 @@ describe('Node', function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var path = []
|
let path = []
|
||||||
assert.strictEqual(Node._findSchema(schema, {}, path), schema, 'top level')
|
assert.strictEqual(Node._findSchema(schema, {}, path), schema, 'top level')
|
||||||
path = ['levelTwo']
|
path = ['levelTwo']
|
||||||
assert.strictEqual(Node._findSchema(schema, {}, path), schema.properties.levelTwo, 'level two')
|
assert.strictEqual(Node._findSchema(schema, {}, path), schema.properties.levelTwo, 'level two')
|
||||||
|
@ -181,8 +181,8 @@ describe('Node', function () {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should find schema for pattern properties', function () {
|
it('should find schema for pattern properties', () => {
|
||||||
var schema = {
|
const schema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
patternProperties: {
|
patternProperties: {
|
||||||
'^foo[0-9]': {
|
'^foo[0-9]': {
|
||||||
|
@ -195,7 +195,7 @@ describe('Node', function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var path = ['foo1']
|
let path = ['foo1']
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
Node._findSchema(schema, {}, path),
|
Node._findSchema(schema, {}, path),
|
||||||
schema.patternProperties['^foo[0-9]'],
|
schema.patternProperties['^foo[0-9]'],
|
||||||
|
@ -209,8 +209,8 @@ describe('Node', function () {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should find schema for multi-level pattern properties', function () {
|
it('should find schema for multi-level pattern properties', () => {
|
||||||
var schema = {
|
const schema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
patternProperties: {
|
patternProperties: {
|
||||||
'^foo[0-9]': {
|
'^foo[0-9]': {
|
||||||
|
@ -239,7 +239,7 @@ describe('Node', function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var path = ['foo1', 'fooChild', 'fooChild2']
|
let path = ['foo1', 'fooChild', 'fooChild2']
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
Node._findSchema(schema, {}, path),
|
Node._findSchema(schema, {}, path),
|
||||||
schema.patternProperties['^foo[0-9]'].properties.fooChild.properties.fooChild2,
|
schema.patternProperties['^foo[0-9]'].properties.fooChild.properties.fooChild2,
|
||||||
|
@ -253,8 +253,8 @@ describe('Node', function () {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return null for path that has no schema', function () {
|
it('should return null for path that has no schema', () => {
|
||||||
var schema = {
|
const schema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
levelTwo: {
|
levelTwo: {
|
||||||
|
@ -277,7 +277,7 @@ describe('Node', function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var path = ['not-in-schema']
|
let path = ['not-in-schema']
|
||||||
assert.strictEqual(Node._findSchema(schema, {}, path), null)
|
assert.strictEqual(Node._findSchema(schema, {}, path), null)
|
||||||
path = ['levelOne', 'not-in-schema']
|
path = ['levelOne', 'not-in-schema']
|
||||||
assert.strictEqual(Node._findSchema(schema, {}, path), null)
|
assert.strictEqual(Node._findSchema(schema, {}, path), null)
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
var assert = require('assert')
|
const assert = require('assert')
|
||||||
var stringifyPartial = require('../src/js/jsonUtils').stringifyPartial
|
const stringifyPartial = require('../src/js/jsonUtils').stringifyPartial
|
||||||
var containsArray = require('../src/js/jsonUtils').containsArray
|
const containsArray = require('../src/js/jsonUtils').containsArray
|
||||||
|
|
||||||
describe('jsonUtils', function () {
|
describe('jsonUtils', () => {
|
||||||
it('should stringify a small object', function () {
|
it('should stringify a small object', () => {
|
||||||
var json = {
|
const json = {
|
||||||
a: 2,
|
a: 2,
|
||||||
b: 'foo',
|
b: 'foo',
|
||||||
c: null,
|
c: null,
|
||||||
|
@ -16,8 +16,8 @@ describe('jsonUtils', function () {
|
||||||
assert.strictEqual(stringifyPartial(json), '{"a":2,"b":"foo","c":null,"d":false,"e":[1,2,3],"f":{"g":"h"}}')
|
assert.strictEqual(stringifyPartial(json), '{"a":2,"b":"foo","c":null,"d":false,"e":[1,2,3],"f":{"g":"h"}}')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should stringify a small object with formatting', function () {
|
it('should stringify a small object with formatting', () => {
|
||||||
var json = {
|
const json = {
|
||||||
a: 2,
|
a: 2,
|
||||||
b: 'foo',
|
b: 'foo',
|
||||||
c: null,
|
c: null,
|
||||||
|
@ -58,8 +58,8 @@ describe('jsonUtils', function () {
|
||||||
'}')
|
'}')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should limit stringified output', function () {
|
it('should limit stringified output', () => {
|
||||||
var json = {
|
const json = {
|
||||||
a: 2,
|
a: 2,
|
||||||
b: 'foo',
|
b: 'foo',
|
||||||
c: null,
|
c: null,
|
||||||
|
@ -68,8 +68,8 @@ describe('jsonUtils', function () {
|
||||||
f: { g: 'h' }
|
f: { g: 'h' }
|
||||||
}
|
}
|
||||||
|
|
||||||
var all = '{"a":2,"b":"foo","c":null,"d":false,"e":[1,2,3],"f":{"g":"h"}}'
|
const all = '{"a":2,"b":"foo","c":null,"d":false,"e":[1,2,3],"f":{"g":"h"}}'
|
||||||
var limit = 20
|
const limit = 20
|
||||||
|
|
||||||
assert.strictEqual(stringifyPartial(json, undefined, limit),
|
assert.strictEqual(stringifyPartial(json, undefined, limit),
|
||||||
all.slice(0, limit) + '...')
|
all.slice(0, limit) + '...')
|
||||||
|
@ -82,7 +82,7 @@ describe('jsonUtils', function () {
|
||||||
assert.strictEqual(stringifyPartial(12345678, undefined, 4), '1234...')
|
assert.strictEqual(stringifyPartial(12345678, undefined, 4), '1234...')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should count array items', function () {
|
it('should count array items', () => {
|
||||||
// assert.strictEqual(countArrayItems('[1,2,3]'), 3)
|
// assert.strictEqual(countArrayItems('[1,2,3]'), 3)
|
||||||
assert.strictEqual(containsArray('[]'), true)
|
assert.strictEqual(containsArray('[]'), true)
|
||||||
assert.strictEqual(containsArray(' []'), true)
|
assert.strictEqual(containsArray(' []'), true)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var JSDOM = require('jsdom').JSDOM
|
const JSDOM = require('jsdom').JSDOM
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the test environment by simulating browser globals.
|
* Set up the test environment by simulating browser globals.
|
||||||
|
@ -10,7 +10,7 @@ module.exports = function setUpTestEnvironment (locale) {
|
||||||
locale = 'en'
|
locale = 'en'
|
||||||
}
|
}
|
||||||
|
|
||||||
var dom = new JSDOM('...')
|
const dom = new JSDOM('...')
|
||||||
global.window = dom.window
|
global.window = dom.window
|
||||||
global.document = dom.window.document
|
global.document = dom.window.document
|
||||||
global.navigator = dom.window.navigator
|
global.navigator = dom.window.navigator
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
var assert = require('assert')
|
const assert = require('assert')
|
||||||
var util = require('../src/js/util')
|
const util = require('../src/js/util')
|
||||||
|
|
||||||
describe('util', function () {
|
describe('util', () => {
|
||||||
describe('repair', function () {
|
describe('repair', () => {
|
||||||
it('should leave valid JSON as is', function () {
|
it('should leave valid JSON as is', () => {
|
||||||
assert.strictEqual(util.repair('{"a":2}'), '{"a":2}')
|
assert.strictEqual(util.repair('{"a":2}'), '{"a":2}')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should replace JavaScript with JSON', function () {
|
it('should replace JavaScript with JSON', () => {
|
||||||
assert.strictEqual(util.repair('{a:2}'), '{"a":2}')
|
assert.strictEqual(util.repair('{a:2}'), '{"a":2}')
|
||||||
assert.strictEqual(util.repair('{a: 2}'), '{"a": 2}')
|
assert.strictEqual(util.repair('{a: 2}'), '{"a": 2}')
|
||||||
assert.strictEqual(util.repair('{\n a: 2\n}'), '{\n "a": 2\n}')
|
assert.strictEqual(util.repair('{\n a: 2\n}'), '{\n "a": 2\n}')
|
||||||
|
@ -19,7 +19,7 @@ describe('util', function () {
|
||||||
assert.strictEqual(util.repair('"{a:b}"'), '"{a:b}"')
|
assert.strictEqual(util.repair('"{a:b}"'), '"{a:b}"')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should add/remove escape characters', function () {
|
it('should add/remove escape characters', () => {
|
||||||
assert.strictEqual(util.repair('"foo\'bar"'), '"foo\'bar"')
|
assert.strictEqual(util.repair('"foo\'bar"'), '"foo\'bar"')
|
||||||
assert.strictEqual(util.repair('"foo\\"bar"'), '"foo\\"bar"')
|
assert.strictEqual(util.repair('"foo\\"bar"'), '"foo\\"bar"')
|
||||||
assert.strictEqual(util.repair('\'foo"bar\''), '"foo\\"bar"')
|
assert.strictEqual(util.repair('\'foo"bar\''), '"foo\\"bar"')
|
||||||
|
@ -27,12 +27,12 @@ describe('util', function () {
|
||||||
assert.strictEqual(util.repair('"foo\\\'bar"'), '"foo\'bar"')
|
assert.strictEqual(util.repair('"foo\\\'bar"'), '"foo\'bar"')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should replace special white characters', function () {
|
it('should replace special white characters', () => {
|
||||||
assert.strictEqual(util.repair('{"a":\u00a0"foo\u00a0bar"}'), '{"a": "foo\u00a0bar"}')
|
assert.strictEqual(util.repair('{"a":\u00a0"foo\u00a0bar"}'), '{"a": "foo\u00a0bar"}')
|
||||||
assert.strictEqual(util.repair('{"a":\u2009"foo"}'), '{"a": "foo"}')
|
assert.strictEqual(util.repair('{"a":\u2009"foo"}'), '{"a": "foo"}')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should escape unescaped control characters', function () {
|
it('should escape unescaped control characters', () => {
|
||||||
assert.strictEqual(util.repair('"hello\bworld"'), '"hello\\bworld"')
|
assert.strictEqual(util.repair('"hello\bworld"'), '"hello\\bworld"')
|
||||||
assert.strictEqual(util.repair('"hello\fworld"'), '"hello\\fworld"')
|
assert.strictEqual(util.repair('"hello\fworld"'), '"hello\\fworld"')
|
||||||
assert.strictEqual(util.repair('"hello\nworld"'), '"hello\\nworld"')
|
assert.strictEqual(util.repair('"hello\nworld"'), '"hello\\nworld"')
|
||||||
|
@ -41,13 +41,13 @@ describe('util', function () {
|
||||||
assert.strictEqual(util.repair('{"value\n": "dc=hcm,dc=com"}'), '{"value\\n": "dc=hcm,dc=com"}')
|
assert.strictEqual(util.repair('{"value\n": "dc=hcm,dc=com"}'), '{"value\\n": "dc=hcm,dc=com"}')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should replace left/right quotes', function () {
|
it('should replace left/right quotes', () => {
|
||||||
assert.strictEqual(util.repair('\u2018foo\u2019'), '"foo"')
|
assert.strictEqual(util.repair('\u2018foo\u2019'), '"foo"')
|
||||||
assert.strictEqual(util.repair('\u201Cfoo\u201D'), '"foo"')
|
assert.strictEqual(util.repair('\u201Cfoo\u201D'), '"foo"')
|
||||||
assert.strictEqual(util.repair('\u0060foo\u00B4'), '"foo"')
|
assert.strictEqual(util.repair('\u0060foo\u00B4'), '"foo"')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('remove comments', function () {
|
it('remove comments', () => {
|
||||||
assert.strictEqual(util.repair('/* foo */ {}'), ' {}')
|
assert.strictEqual(util.repair('/* foo */ {}'), ' {}')
|
||||||
assert.strictEqual(util.repair('/* foo */ {}'), ' {}')
|
assert.strictEqual(util.repair('/* foo */ {}'), ' {}')
|
||||||
assert.strictEqual(util.repair('{a:\'foo\',/*hello*/b:\'bar\'}'), '{"a":"foo","b":"bar"}')
|
assert.strictEqual(util.repair('{a:\'foo\',/*hello*/b:\'bar\'}'), '{"a":"foo","b":"bar"}')
|
||||||
|
@ -57,7 +57,7 @@ describe('util', function () {
|
||||||
assert.strictEqual(util.repair('{"str":"/* foo */"}'), '{"str":"/* foo */"}')
|
assert.strictEqual(util.repair('{"str":"/* foo */"}'), '{"str":"/* foo */"}')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should strip JSONP notation', function () {
|
it('should strip JSONP notation', () => {
|
||||||
// matching
|
// matching
|
||||||
assert.strictEqual(util.repair('callback_123({});'), '{}')
|
assert.strictEqual(util.repair('callback_123({});'), '{}')
|
||||||
assert.strictEqual(util.repair('callback_123([]);'), '[]')
|
assert.strictEqual(util.repair('callback_123([]);'), '[]')
|
||||||
|
@ -78,7 +78,7 @@ describe('util', function () {
|
||||||
assert.strictEqual(util.repair('callback({}'), 'callback({}')
|
assert.strictEqual(util.repair('callback({}'), 'callback({}')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should strip trailing zeros', function () {
|
it('should strip trailing zeros', () => {
|
||||||
// matching
|
// matching
|
||||||
assert.strictEqual(util.repair('[1,2,3,]'), '[1,2,3]')
|
assert.strictEqual(util.repair('[1,2,3,]'), '[1,2,3]')
|
||||||
assert.strictEqual(util.repair('[1,2,3,\n]'), '[1,2,3\n]')
|
assert.strictEqual(util.repair('[1,2,3,\n]'), '[1,2,3\n]')
|
||||||
|
@ -90,8 +90,8 @@ describe('util', function () {
|
||||||
assert.strictEqual(util.repair('"{a:2,}"'), '"{a:2,}"')
|
assert.strictEqual(util.repair('"{a:2,}"'), '"{a:2,}"')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should strip MongoDB data types', function () {
|
it('should strip MongoDB data types', () => {
|
||||||
var mongoDocument = '{\n' +
|
const mongoDocument = '{\n' +
|
||||||
' "_id" : ObjectId("123"),\n' +
|
' "_id" : ObjectId("123"),\n' +
|
||||||
' "isoDate" : ISODate("2012-12-19T06:01:17.171Z"),\n' +
|
' "isoDate" : ISODate("2012-12-19T06:01:17.171Z"),\n' +
|
||||||
' "regularNumber" : 67,\n' +
|
' "regularNumber" : 67,\n' +
|
||||||
|
@ -103,7 +103,7 @@ describe('util', function () {
|
||||||
' "decimal2" : NumberDecimal(4)\n' +
|
' "decimal2" : NumberDecimal(4)\n' +
|
||||||
'}'
|
'}'
|
||||||
|
|
||||||
var expectedJson = '{\n' +
|
const expectedJson = '{\n' +
|
||||||
' "_id" : "123",\n' +
|
' "_id" : "123",\n' +
|
||||||
' "isoDate" : "2012-12-19T06:01:17.171Z",\n' +
|
' "isoDate" : "2012-12-19T06:01:17.171Z",\n' +
|
||||||
' "regularNumber" : 67,\n' +
|
' "regularNumber" : 67,\n' +
|
||||||
|
@ -119,8 +119,8 @@ describe('util', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('jsonPath', function () {
|
describe('jsonPath', () => {
|
||||||
it('should stringify an array of paths', function () {
|
it('should stringify an array of paths', () => {
|
||||||
assert.deepStrictEqual(util.stringifyPath([]), '')
|
assert.deepStrictEqual(util.stringifyPath([]), '')
|
||||||
assert.deepStrictEqual(util.stringifyPath(['foo']), '.foo')
|
assert.deepStrictEqual(util.stringifyPath(['foo']), '.foo')
|
||||||
assert.deepStrictEqual(util.stringifyPath(['foo', 'bar']), '.foo.bar')
|
assert.deepStrictEqual(util.stringifyPath(['foo', 'bar']), '.foo.bar')
|
||||||
|
@ -132,7 +132,7 @@ describe('util', function () {
|
||||||
assert.deepStrictEqual(util.stringifyPath(['foo', 'prop with spaces']), '.foo["prop with spaces"]')
|
assert.deepStrictEqual(util.stringifyPath(['foo', 'prop with spaces']), '.foo["prop with spaces"]')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should parse a json path', function () {
|
it('should parse a json path', () => {
|
||||||
assert.deepStrictEqual(util.parsePath(''), [])
|
assert.deepStrictEqual(util.parsePath(''), [])
|
||||||
assert.deepStrictEqual(util.parsePath('.foo'), ['foo'])
|
assert.deepStrictEqual(util.parsePath('.foo'), ['foo'])
|
||||||
assert.deepStrictEqual(util.parsePath('.foo.bar'), ['foo', 'bar'])
|
assert.deepStrictEqual(util.parsePath('.foo.bar'), ['foo', 'bar'])
|
||||||
|
@ -146,36 +146,36 @@ describe('util', function () {
|
||||||
assert.deepStrictEqual(util.parsePath('[2]'), [2])
|
assert.deepStrictEqual(util.parsePath('[2]'), [2])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should throw an exception in case of an invalid path', function () {
|
it('should throw an exception in case of an invalid path', () => {
|
||||||
assert.throws(function () { util.parsePath('.') }, /Invalid JSON path: property name expected at index 1/)
|
assert.throws(() => { util.parsePath('.') }, /Invalid JSON path: property name expected at index 1/)
|
||||||
assert.throws(function () { util.parsePath('[') }, /Invalid JSON path: unexpected end, character ] expected/)
|
assert.throws(() => { util.parsePath('[') }, /Invalid JSON path: unexpected end, character ] expected/)
|
||||||
assert.throws(function () { util.parsePath('[]') }, /Invalid JSON path: array value expected at index 1/)
|
assert.throws(() => { util.parsePath('[]') }, /Invalid JSON path: array value expected at index 1/)
|
||||||
assert.throws(function () { util.parsePath('.foo[ ]') }, /Invalid JSON path: array value expected at index 7/)
|
assert.throws(() => { util.parsePath('.foo[ ]') }, /Invalid JSON path: array value expected at index 7/)
|
||||||
assert.throws(function () { util.parsePath('.[]') }, /Invalid JSON path: property name expected at index 1/)
|
assert.throws(() => { util.parsePath('.[]') }, /Invalid JSON path: property name expected at index 1/)
|
||||||
assert.throws(function () { util.parsePath('["23]') }, /Invalid JSON path: unexpected end, character " expected/)
|
assert.throws(() => { util.parsePath('["23]') }, /Invalid JSON path: unexpected end, character " expected/)
|
||||||
assert.throws(function () { util.parsePath('.foo bar') }, /Invalid JSON path: unexpected character " " at index 4/)
|
assert.throws(() => { util.parsePath('.foo bar') }, /Invalid JSON path: unexpected character " " at index 4/)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getIndexForPosition', function () {
|
describe('getIndexForPosition', () => {
|
||||||
var el = {
|
const el = {
|
||||||
value: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\nUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\nExcepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
|
value: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\nUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\nExcepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
|
||||||
}
|
}
|
||||||
|
|
||||||
it('happy flows - row and column in range', function () {
|
it('happy flows - row and column in range', () => {
|
||||||
assert.strictEqual(util.getIndexForPosition(el, 1, 1), 0)
|
assert.strictEqual(util.getIndexForPosition(el, 1, 1), 0)
|
||||||
assert.strictEqual(util.getIndexForPosition(el, 2, 1), 124)
|
assert.strictEqual(util.getIndexForPosition(el, 2, 1), 124)
|
||||||
assert.strictEqual(util.getIndexForPosition(el, 3, 8), 239)
|
assert.strictEqual(util.getIndexForPosition(el, 3, 8), 239)
|
||||||
assert.strictEqual(util.getIndexForPosition(el, 4, 22), 356)
|
assert.strictEqual(util.getIndexForPosition(el, 4, 22), 356)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('if range exceeds it should be considered as if it is last row or column length', function () {
|
it('if range exceeds it should be considered as if it is last row or column length', () => {
|
||||||
assert.strictEqual(util.getIndexForPosition(el, 1, 100000), 123)
|
assert.strictEqual(util.getIndexForPosition(el, 1, 100000), 123)
|
||||||
assert.strictEqual(util.getIndexForPosition(el, 100000, 1), 335)
|
assert.strictEqual(util.getIndexForPosition(el, 100000, 1), 335)
|
||||||
assert.strictEqual(util.getIndexForPosition(el, 100000, 100000), 445)
|
assert.strictEqual(util.getIndexForPosition(el, 100000, 100000), 445)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('missing or wrong input sould return -1', function () {
|
it('missing or wrong input sould return -1', () => {
|
||||||
assert.strictEqual(util.getIndexForPosition(el), -1)
|
assert.strictEqual(util.getIndexForPosition(el), -1)
|
||||||
assert.strictEqual(util.getIndexForPosition(el, undefined, 1), -1)
|
assert.strictEqual(util.getIndexForPosition(el, undefined, 1), -1)
|
||||||
assert.strictEqual(util.getIndexForPosition(el, 1, undefined), -1)
|
assert.strictEqual(util.getIndexForPosition(el, 1, undefined), -1)
|
||||||
|
@ -183,9 +183,9 @@ describe('util', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('get', function () {
|
describe('get', () => {
|
||||||
it('should get a nested property from an object', function () {
|
it('should get a nested property from an object', () => {
|
||||||
var obj = {
|
const obj = {
|
||||||
a: {
|
a: {
|
||||||
b: 2
|
b: 2
|
||||||
},
|
},
|
||||||
|
@ -205,34 +205,34 @@ describe('util', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('makeFieldTooltip', function () {
|
describe('makeFieldTooltip', () => {
|
||||||
it('should return empty string when the schema is missing all relevant fields', function () {
|
it('should return empty string when the schema is missing all relevant fields', () => {
|
||||||
assert.strictEqual(util.makeFieldTooltip({}), '')
|
assert.strictEqual(util.makeFieldTooltip({}), '')
|
||||||
assert.strictEqual(util.makeFieldTooltip({ additionalProperties: false }), '')
|
assert.strictEqual(util.makeFieldTooltip({ additionalProperties: false }), '')
|
||||||
assert.strictEqual(util.makeFieldTooltip(), '')
|
assert.strictEqual(util.makeFieldTooltip(), '')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should make tooltips with only title', function () {
|
it('should make tooltips with only title', () => {
|
||||||
assert.strictEqual(util.makeFieldTooltip({ title: 'foo' }), 'foo')
|
assert.strictEqual(util.makeFieldTooltip({ title: 'foo' }), 'foo')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should make tooltips with only description', function () {
|
it('should make tooltips with only description', () => {
|
||||||
assert.strictEqual(util.makeFieldTooltip({ description: 'foo' }), 'foo')
|
assert.strictEqual(util.makeFieldTooltip({ description: 'foo' }), 'foo')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should make tooltips with only default', function () {
|
it('should make tooltips with only default', () => {
|
||||||
assert.strictEqual(util.makeFieldTooltip({ default: 'foo' }), 'Default\n"foo"')
|
assert.strictEqual(util.makeFieldTooltip({ default: 'foo' }), 'Default\n"foo"')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should make tooltips with only examples', function () {
|
it('should make tooltips with only examples', () => {
|
||||||
assert.strictEqual(util.makeFieldTooltip({ examples: ['foo', 'bar'] }), 'Examples\n"foo"\n"bar"')
|
assert.strictEqual(util.makeFieldTooltip({ examples: ['foo', 'bar'] }), 'Examples\n"foo"\n"bar"')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should make tooltips with title and description', function () {
|
it('should make tooltips with title and description', () => {
|
||||||
assert.strictEqual(util.makeFieldTooltip({ title: 'foo', description: 'bar' }), 'foo\nbar')
|
assert.strictEqual(util.makeFieldTooltip({ title: 'foo', description: 'bar' }), 'foo\nbar')
|
||||||
|
|
||||||
var longTitle = 'Lorem Ipsum Dolor'
|
const longTitle = 'Lorem Ipsum Dolor'
|
||||||
var longDescription = 'Duis id elit non ante gravida vestibulum non nec est. ' +
|
const longDescription = 'Duis id elit non ante gravida vestibulum non nec est. ' +
|
||||||
'Proin vitae ligula at elit dapibus tempor. ' +
|
'Proin vitae ligula at elit dapibus tempor. ' +
|
||||||
'Etiam lacinia augue vel condimentum interdum. '
|
'Etiam lacinia augue vel condimentum interdum. '
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
|
@ -241,39 +241,39 @@ describe('util', function () {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should make tooltips with title, description, and examples', function () {
|
it('should make tooltips with title, description, and examples', () => {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
util.makeFieldTooltip({ title: 'foo', description: 'bar', examples: ['baz'] }),
|
util.makeFieldTooltip({ title: 'foo', description: 'bar', examples: ['baz'] }),
|
||||||
'foo\nbar\n\nExamples\n"baz"'
|
'foo\nbar\n\nExamples\n"baz"'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should make tooltips with title, description, default, and examples', function () {
|
it('should make tooltips with title, description, default, and examples', () => {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
util.makeFieldTooltip({ title: 'foo', description: 'bar', default: 'bat', examples: ['baz'] }),
|
util.makeFieldTooltip({ title: 'foo', description: 'bar', default: 'bat', examples: ['baz'] }),
|
||||||
'foo\nbar\n\nDefault\n"bat"\n\nExamples\n"baz"'
|
'foo\nbar\n\nDefault\n"bat"\n\nExamples\n"baz"'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle empty fields', function () {
|
it('should handle empty fields', () => {
|
||||||
assert.strictEqual(util.makeFieldTooltip({ title: '', description: 'bar' }), 'bar')
|
assert.strictEqual(util.makeFieldTooltip({ title: '', description: 'bar' }), 'bar')
|
||||||
assert.strictEqual(util.makeFieldTooltip({ title: 'foo', description: '' }), 'foo')
|
assert.strictEqual(util.makeFieldTooltip({ title: 'foo', description: '' }), 'foo')
|
||||||
assert.strictEqual(util.makeFieldTooltip({ description: 'bar', examples: [] }), 'bar')
|
assert.strictEqual(util.makeFieldTooltip({ description: 'bar', examples: [] }), 'bar')
|
||||||
assert.strictEqual(util.makeFieldTooltip({ description: 'bar', examples: [''] }), 'bar\n\nExamples\n""')
|
assert.strictEqual(util.makeFieldTooltip({ description: 'bar', examples: [''] }), 'bar\n\nExamples\n""')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should internationalize "Defaults" correctly', function () {
|
it('should internationalize "Defaults" correctly', () => {
|
||||||
assert.strictEqual(util.makeFieldTooltip({ default: 'foo' }, 'pt-BR'), 'Revelia\n"foo"')
|
assert.strictEqual(util.makeFieldTooltip({ default: 'foo' }, 'pt-BR'), 'Revelia\n"foo"')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should internationalize "Examples" correctly', function () {
|
it('should internationalize "Examples" correctly', () => {
|
||||||
assert.strictEqual(util.makeFieldTooltip({ examples: ['foo'] }, 'pt-BR'), 'Exemplos\n"foo"')
|
assert.strictEqual(util.makeFieldTooltip({ examples: ['foo'] }, 'pt-BR'), 'Exemplos\n"foo"')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getChildPaths', function () {
|
describe('getChildPaths', () => {
|
||||||
it('should extract all child paths of an array containing objects', function () {
|
it('should extract all child paths of an array containing objects', () => {
|
||||||
var json = [
|
const json = [
|
||||||
{ name: 'A', location: { latitude: 1, longitude: 2 } },
|
{ name: 'A', location: { latitude: 1, longitude: 2 } },
|
||||||
{ name: 'B', location: { latitude: 1, longitude: 2 } },
|
{ name: 'B', location: { latitude: 1, longitude: 2 } },
|
||||||
{ name: 'C', timestamp: 0 }
|
{ name: 'C', timestamp: 0 }
|
||||||
|
@ -287,8 +287,8 @@ describe('util', function () {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should extract all child paths of an array containing objects, including objects', function () {
|
it('should extract all child paths of an array containing objects, including objects', () => {
|
||||||
var json = [
|
const json = [
|
||||||
{ name: 'A', location: { latitude: 1, longitude: 2 } },
|
{ name: 'A', location: { latitude: 1, longitude: 2 } },
|
||||||
{ name: 'B', location: { latitude: 1, longitude: 2 } },
|
{ name: 'B', location: { latitude: 1, longitude: 2 } },
|
||||||
{ name: 'C', timestamp: 0 }
|
{ name: 'C', timestamp: 0 }
|
||||||
|
@ -304,22 +304,22 @@ describe('util', function () {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should extract all child paths of an array containing values', function () {
|
it('should extract all child paths of an array containing values', () => {
|
||||||
var json = [1, 2, 3]
|
const json = [1, 2, 3]
|
||||||
|
|
||||||
assert.deepStrictEqual(util.getChildPaths(json), [
|
assert.deepStrictEqual(util.getChildPaths(json), [
|
||||||
''
|
''
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should extract all child paths of a non-array', function () {
|
it('should extract all child paths of a non-array', () => {
|
||||||
assert.deepStrictEqual(util.getChildPaths({ a: 2, b: { c: 3 } }), [''])
|
assert.deepStrictEqual(util.getChildPaths({ a: 2, b: { c: 3 } }), [''])
|
||||||
assert.deepStrictEqual(util.getChildPaths('foo'), [''])
|
assert.deepStrictEqual(util.getChildPaths('foo'), [''])
|
||||||
assert.deepStrictEqual(util.getChildPaths(123), [''])
|
assert.deepStrictEqual(util.getChildPaths(123), [''])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should test whether something is an object', function () {
|
it('should test whether something is an object', () => {
|
||||||
assert.strictEqual(util.isObject({}), true)
|
assert.strictEqual(util.isObject({}), true)
|
||||||
assert.strictEqual(util.isObject(new Date()), true)
|
assert.strictEqual(util.isObject(new Date()), true)
|
||||||
assert.strictEqual(util.isObject([]), false)
|
assert.strictEqual(util.isObject([]), false)
|
||||||
|
@ -329,15 +329,15 @@ describe('util', function () {
|
||||||
assert.strictEqual(util.isObject(), false)
|
assert.strictEqual(util.isObject(), false)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('sort', function () {
|
describe('sort', () => {
|
||||||
it('should sort an array', function () {
|
it('should sort an array', () => {
|
||||||
var array = [4, 1, 10, 2]
|
const array = [4, 1, 10, 2]
|
||||||
assert.deepStrictEqual(util.sort(array), [1, 2, 4, 10])
|
assert.deepStrictEqual(util.sort(array), [1, 2, 4, 10])
|
||||||
assert.deepStrictEqual(util.sort(array, '.', 'desc'), [10, 4, 2, 1])
|
assert.deepStrictEqual(util.sort(array, '.', 'desc'), [10, 4, 2, 1])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should sort an array containing objects', function () {
|
it('should sort an array containing objects', () => {
|
||||||
var array = [
|
const array = [
|
||||||
{ value: 4 },
|
{ value: 4 },
|
||||||
{ value: 1 },
|
{ value: 1 },
|
||||||
{ value: 10 },
|
{ value: 10 },
|
||||||
|
@ -360,9 +360,9 @@ describe('util', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('sortObjectKeys', function () {
|
describe('sortObjectKeys', () => {
|
||||||
it('should sort the keys of an object', function () {
|
it('should sort the keys of an object', () => {
|
||||||
var object = {
|
const object = {
|
||||||
c: 'c',
|
c: 'c',
|
||||||
a: 'a',
|
a: 'a',
|
||||||
b: 'b'
|
b: 'b'
|
||||||
|
@ -374,7 +374,7 @@ describe('util', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should parse a string', function () {
|
it('should parse a string', () => {
|
||||||
assert.strictEqual(util.parseString('foo'), 'foo')
|
assert.strictEqual(util.parseString('foo'), 'foo')
|
||||||
assert.strictEqual(util.parseString('234foo'), '234foo')
|
assert.strictEqual(util.parseString('234foo'), '234foo')
|
||||||
assert.strictEqual(util.parseString('2.3'), 2.3)
|
assert.strictEqual(util.parseString('2.3'), 2.3)
|
||||||
|
@ -383,7 +383,7 @@ describe('util', function () {
|
||||||
assert.strictEqual(util.parseString('false'), false)
|
assert.strictEqual(util.parseString('false'), false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should find a unique name', function () {
|
it('should find a unique name', () => {
|
||||||
assert.strictEqual(util.findUniqueName('other', [
|
assert.strictEqual(util.findUniqueName('other', [
|
||||||
'a',
|
'a',
|
||||||
'b',
|
'b',
|
||||||
|
@ -428,7 +428,7 @@ describe('util', function () {
|
||||||
]), 'b (copy 3)')
|
]), 'b (copy 3)')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should format a document size in a human readable way', function () {
|
it('should format a document size in a human readable way', () => {
|
||||||
assert.strictEqual(util.formatSize(500), '500 B')
|
assert.strictEqual(util.formatSize(500), '500 B')
|
||||||
assert.strictEqual(util.formatSize(900), '0.9 KiB')
|
assert.strictEqual(util.formatSize(900), '0.9 KiB')
|
||||||
assert.strictEqual(util.formatSize(77.89 * 1024), '77.9 KiB')
|
assert.strictEqual(util.formatSize(77.89 * 1024), '77.9 KiB')
|
||||||
|
@ -439,13 +439,13 @@ describe('util', function () {
|
||||||
assert.strictEqual(util.formatSize(1024 * 1024 * 1024 * 1024), '1.0 TiB')
|
assert.strictEqual(util.formatSize(1024 * 1024 * 1024 * 1024), '1.0 TiB')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should limit characters', function () {
|
it('should limit characters', () => {
|
||||||
assert.strictEqual(util.limitCharacters('hello world', 11), 'hello world')
|
assert.strictEqual(util.limitCharacters('hello world', 11), 'hello world')
|
||||||
assert.strictEqual(util.limitCharacters('hello world', 5), 'hello...')
|
assert.strictEqual(util.limitCharacters('hello world', 5), 'hello...')
|
||||||
assert.strictEqual(util.limitCharacters('hello world', 100), 'hello world')
|
assert.strictEqual(util.limitCharacters('hello world', 100), 'hello world')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should compile a JSON pointer', function () {
|
it('should compile a JSON pointer', () => {
|
||||||
assert.strictEqual(util.compileJSONPointer(['foo', 'bar']), '/foo/bar')
|
assert.strictEqual(util.compileJSONPointer(['foo', 'bar']), '/foo/bar')
|
||||||
assert.strictEqual(util.compileJSONPointer(['foo', '/~ ~/']), '/foo/~1~0 ~0~1')
|
assert.strictEqual(util.compileJSONPointer(['foo', '/~ ~/']), '/foo/~1~0 ~0~1')
|
||||||
assert.strictEqual(util.compileJSONPointer(['']), '/')
|
assert.strictEqual(util.compileJSONPointer(['']), '/')
|
||||||
|
|
Loading…
Reference in New Issue