summaryrefslogtreecommitdiff
path: root/test/json-schema.test.js
diff options
context:
space:
mode:
authorJames Maa <jmaa@berkeley.edu>2024-05-31 08:06:52 -0700
committerGitHub <noreply@github.com>2024-05-31 15:06:52 +0000
commit76ca08bd59f0e8bfa1bb20ac813f48e7ab241265 (patch)
treebdba43d9ba704885383c7f308c6fe3f574c647c5 /test/json-schema.test.js
parentb3f54747eb2694bdc90bce72e5532e99d374ef08 (diff)
Allow trailing commas in ESLint (#1013)
* Update comma-dangle rule * Fix dangling commas
Diffstat (limited to 'test/json-schema.test.js')
-rw-r--r--test/json-schema.test.js466
1 files changed, 233 insertions, 233 deletions
diff --git a/test/json-schema.test.js b/test/json-schema.test.js
index dba14c54..0b17e7ce 100644
--- a/test/json-schema.test.js
+++ b/test/json-schema.test.js
@@ -53,28 +53,28 @@ describe('JsonSchema', () => {
const schema = {
allOf: [
{
- type: 'number'
+ type: 'number',
},
{
anyOf: [
{minimum: 10, maximum: 100},
- {minimum: -100, maximum: -10}
- ]
+ {minimum: -100, maximum: -10},
+ ],
},
{
oneOf: [
{multipleOf: 3},
- {multipleOf: 5}
- ]
+ {multipleOf: 5},
+ ],
},
{
not: {
anyOf: [
- {multipleOf: 20}
- ]
- }
- }
- ]
+ {multipleOf: 20},
+ ],
+ },
+ },
+ ],
};
/**
@@ -115,7 +115,7 @@ describe('JsonSchema', () => {
// String tests
{
schema: {
- type: 'string'
+ type: 'string',
},
inputs: [
{expected: false, value: null},
@@ -123,97 +123,97 @@ describe('JsonSchema', () => {
{expected: false, value: 0},
{expected: false, value: {}},
{expected: false, value: []},
- {expected: true, value: ''}
- ]
+ {expected: true, value: ''},
+ ],
},
{
schema: {
type: 'string',
- minLength: 2
+ minLength: 2,
},
inputs: [
{expected: false, value: ''},
{expected: false, value: '1'},
{expected: true, value: '12'},
- {expected: true, value: '123'}
- ]
+ {expected: true, value: '123'},
+ ],
},
{
schema: {
type: 'string',
- maxLength: 2
+ maxLength: 2,
},
inputs: [
{expected: true, value: ''},
{expected: true, value: '1'},
{expected: true, value: '12'},
- {expected: false, value: '123'}
- ]
+ {expected: false, value: '123'},
+ ],
},
{
schema: {
type: 'string',
- pattern: 'test'
+ pattern: 'test',
},
inputs: [
{expected: false, value: ''},
{expected: true, value: 'test'},
{expected: false, value: 'TEST'},
{expected: true, value: 'ABCtestDEF'},
- {expected: false, value: 'ABCTESTDEF'}
- ]
+ {expected: false, value: 'ABCTESTDEF'},
+ ],
},
{
schema: {
type: 'string',
- pattern: '^test$'
+ pattern: '^test$',
},
inputs: [
{expected: false, value: ''},
{expected: true, value: 'test'},
{expected: false, value: 'TEST'},
{expected: false, value: 'ABCtestDEF'},
- {expected: false, value: 'ABCTESTDEF'}
- ]
+ {expected: false, value: 'ABCTESTDEF'},
+ ],
},
{
schema: {
type: 'string',
pattern: '^test$',
- patternFlags: 'i'
+ patternFlags: 'i',
},
inputs: [
{expected: false, value: ''},
{expected: true, value: 'test'},
{expected: true, value: 'TEST'},
{expected: false, value: 'ABCtestDEF'},
- {expected: false, value: 'ABCTESTDEF'}
- ]
+ {expected: false, value: 'ABCTESTDEF'},
+ ],
},
{
schema: {
type: 'string',
- pattern: '*'
+ pattern: '*',
},
inputs: [
- {expected: false, value: ''}
- ]
+ {expected: false, value: ''},
+ ],
},
{
schema: {
type: 'string',
pattern: '.',
- patternFlags: '?'
+ patternFlags: '?',
},
inputs: [
- {expected: false, value: ''}
- ]
+ {expected: false, value: ''},
+ ],
},
// Const tests
{
schema: {
- const: 32
+ const: 32,
},
inputs: [
{expected: true, value: 32},
@@ -221,12 +221,12 @@ describe('JsonSchema', () => {
{expected: false, value: '32'},
{expected: false, value: null},
{expected: false, value: {a: 'b'}},
- {expected: false, value: [1, 2, 3]}
- ]
+ {expected: false, value: [1, 2, 3]},
+ ],
},
{
schema: {
- const: '32'
+ const: '32',
},
inputs: [
{expected: false, value: 32},
@@ -234,12 +234,12 @@ describe('JsonSchema', () => {
{expected: true, value: '32'},
{expected: false, value: null},
{expected: false, value: {a: 'b'}},
- {expected: false, value: [1, 2, 3]}
- ]
+ {expected: false, value: [1, 2, 3]},
+ ],
},
{
schema: {
- const: null
+ const: null,
},
inputs: [
{expected: false, value: 32},
@@ -247,12 +247,12 @@ describe('JsonSchema', () => {
{expected: false, value: '32'},
{expected: true, value: null},
{expected: false, value: {a: 'b'}},
- {expected: false, value: [1, 2, 3]}
- ]
+ {expected: false, value: [1, 2, 3]},
+ ],
},
{
schema: {
- const: {a: 'b'}
+ const: {a: 'b'},
},
inputs: [
{expected: false, value: 32},
@@ -260,12 +260,12 @@ describe('JsonSchema', () => {
{expected: false, value: '32'},
{expected: false, value: null},
{expected: false, value: {a: 'b'}},
- {expected: false, value: [1, 2, 3]}
- ]
+ {expected: false, value: [1, 2, 3]},
+ ],
},
{
schema: {
- const: [1, 2, 3]
+ const: [1, 2, 3],
},
inputs: [
{expected: false, value: 32},
@@ -273,15 +273,15 @@ describe('JsonSchema', () => {
{expected: false, value: '32'},
{expected: false, value: null},
{expected: false, value: {a: 'b'}},
- {expected: false, value: [1, 2, 3]}
- ]
+ {expected: false, value: [1, 2, 3]},
+ ],
},
// Array contains tests
{
schema: {
type: 'array',
- contains: {const: 32}
+ contains: {const: 32},
},
inputs: [
{expected: false, value: []},
@@ -290,119 +290,119 @@ describe('JsonSchema', () => {
{expected: true, value: [1, 32, 1]},
{expected: false, value: [33]},
{expected: false, value: [1, 33]},
- {expected: false, value: [1, 33, 1]}
- ]
+ {expected: false, value: [1, 33, 1]},
+ ],
},
// Number limits tests
{
schema: {
type: 'number',
- minimum: 0
+ minimum: 0,
},
inputs: [
{expected: false, value: -1},
{expected: true, value: 0},
- {expected: true, value: 1}
- ]
+ {expected: true, value: 1},
+ ],
},
{
schema: {
type: 'number',
- exclusiveMinimum: 0
+ exclusiveMinimum: 0,
},
inputs: [
{expected: false, value: -1},
{expected: false, value: 0},
- {expected: true, value: 1}
- ]
+ {expected: true, value: 1},
+ ],
},
{
schema: {
type: 'number',
- maximum: 0
+ maximum: 0,
},
inputs: [
{expected: true, value: -1},
{expected: true, value: 0},
- {expected: false, value: 1}
- ]
+ {expected: false, value: 1},
+ ],
},
{
schema: {
type: 'number',
- exclusiveMaximum: 0
+ exclusiveMaximum: 0,
},
inputs: [
{expected: true, value: -1},
{expected: false, value: 0},
- {expected: false, value: 1}
- ]
+ {expected: false, value: 1},
+ ],
},
// Integer limits tests
{
schema: {
type: 'integer',
- minimum: 0
+ minimum: 0,
},
inputs: [
{expected: false, value: -1},
{expected: true, value: 0},
- {expected: true, value: 1}
- ]
+ {expected: true, value: 1},
+ ],
},
{
schema: {
type: 'integer',
- exclusiveMinimum: 0
+ exclusiveMinimum: 0,
},
inputs: [
{expected: false, value: -1},
{expected: false, value: 0},
- {expected: true, value: 1}
- ]
+ {expected: true, value: 1},
+ ],
},
{
schema: {
type: 'integer',
- maximum: 0
+ maximum: 0,
},
inputs: [
{expected: true, value: -1},
{expected: true, value: 0},
- {expected: false, value: 1}
- ]
+ {expected: false, value: 1},
+ ],
},
{
schema: {
type: 'integer',
- exclusiveMaximum: 0
+ exclusiveMaximum: 0,
},
inputs: [
{expected: true, value: -1},
{expected: false, value: 0},
- {expected: false, value: 1}
- ]
+ {expected: false, value: 1},
+ ],
},
{
schema: {
type: 'integer',
- multipleOf: 2
+ multipleOf: 2,
},
inputs: [
{expected: true, value: -2},
{expected: false, value: -1},
{expected: true, value: 0},
{expected: false, value: 1},
- {expected: true, value: 2}
- ]
+ {expected: true, value: 2},
+ ],
},
// Numeric type tests
{
schema: {
- type: 'number'
+ type: 'number',
},
inputs: [
{expected: true, value: 0},
@@ -411,12 +411,12 @@ describe('JsonSchema', () => {
{expected: false, value: '0'},
{expected: false, value: null},
{expected: false, value: []},
- {expected: false, value: {}}
- ]
+ {expected: false, value: {}},
+ ],
},
{
schema: {
- type: 'integer'
+ type: 'integer',
},
inputs: [
{expected: true, value: 0},
@@ -425,8 +425,8 @@ describe('JsonSchema', () => {
{expected: false, value: '0'},
{expected: false, value: null},
{expected: false, value: []},
- {expected: false, value: {}}
- ]
+ {expected: false, value: {}},
+ ],
},
// Reference tests
@@ -434,10 +434,10 @@ describe('JsonSchema', () => {
schema: {
definitions: {
example: {
- type: 'number'
- }
+ type: 'number',
+ },
},
- $ref: '#/definitions/example'
+ $ref: '#/definitions/example',
},
inputs: [
{expected: true, value: 0},
@@ -446,17 +446,17 @@ describe('JsonSchema', () => {
{expected: false, value: '0'},
{expected: false, value: null},
{expected: false, value: []},
- {expected: false, value: {}}
- ]
+ {expected: false, value: {}},
+ ],
},
{
schema: {
definitions: {
example: {
- type: 'integer'
- }
+ type: 'integer',
+ },
},
- $ref: '#/definitions/example'
+ $ref: '#/definitions/example',
},
inputs: [
{expected: true, value: 0},
@@ -465,8 +465,8 @@ describe('JsonSchema', () => {
{expected: false, value: '0'},
{expected: false, value: null},
{expected: false, value: []},
- {expected: false, value: {}}
- ]
+ {expected: false, value: {}},
+ ],
},
{
schema: {
@@ -476,12 +476,12 @@ describe('JsonSchema', () => {
additionalProperties: false,
properties: {
test: {
- $ref: '#/definitions/example'
- }
- }
- }
+ $ref: '#/definitions/example',
+ },
+ },
+ },
},
- $ref: '#/definitions/example'
+ $ref: '#/definitions/example',
},
inputs: [
{expected: false, value: 0},
@@ -499,9 +499,9 @@ describe('JsonSchema', () => {
{expected: false, value: {test: []}},
{expected: true, value: {test: {}}},
{expected: true, value: {test: {test: {}}}},
- {expected: true, value: {test: {test: {test: {}}}}}
- ]
- }
+ {expected: true, value: {test: {test: {test: {}}}}},
+ ],
+ },
];
/* eslint-enable @stylistic/no-multi-spaces */
@@ -524,49 +524,49 @@ describe('JsonSchema', () => {
properties: {
test: {
type: 'string',
- default: 'default'
- }
+ default: 'default',
+ },
},
- additionalProperties: false
+ additionalProperties: false,
},
inputs: [
[
void 0,
- {test: 'default'}
+ {test: 'default'},
],
[
null,
- {test: 'default'}
+ {test: 'default'},
],
[
0,
- {test: 'default'}
+ {test: 'default'},
],
[
'',
- {test: 'default'}
+ {test: 'default'},
],
[
[],
- {test: 'default'}
+ {test: 'default'},
],
[
{},
- {test: 'default'}
+ {test: 'default'},
],
[
{test: 'value'},
- {test: 'value'}
+ {test: 'value'},
],
[
{test2: 'value2'},
- {test: 'default'}
+ {test: 'default'},
],
[
{test: 'value', test2: 'value2'},
- {test: 'value'}
- ]
- ]
+ {test: 'value'},
+ ],
+ ],
},
// Test value defaulting on objects with additionalProperties=true
@@ -577,29 +577,29 @@ describe('JsonSchema', () => {
properties: {
test: {
type: 'string',
- default: 'default'
- }
+ default: 'default',
+ },
},
- additionalProperties: true
+ additionalProperties: true,
},
inputs: [
[
{},
- {test: 'default'}
+ {test: 'default'},
],
[
{test: 'value'},
- {test: 'value'}
+ {test: 'value'},
],
[
{test2: 'value2'},
- {test: 'default', test2: 'value2'}
+ {test: 'default', test2: 'value2'},
],
[
{test: 'value', test2: 'value2'},
- {test: 'value', test2: 'value2'}
- ]
- ]
+ {test: 'value', test2: 'value2'},
+ ],
+ ],
},
// Test value defaulting on objects with additionalProperties={schema}
@@ -610,48 +610,48 @@ describe('JsonSchema', () => {
properties: {
test: {
type: 'string',
- default: 'default'
- }
+ default: 'default',
+ },
},
additionalProperties: {
type: 'number',
- default: 10
- }
+ default: 10,
+ },
},
inputs: [
[
{},
- {test: 'default'}
+ {test: 'default'},
],
[
{test: 'value'},
- {test: 'value'}
+ {test: 'value'},
],
[
{test2: 'value2'},
- {test: 'default', test2: 10}
+ {test: 'default', test2: 10},
],
[
{test: 'value', test2: 'value2'},
- {test: 'value', test2: 10}
+ {test: 'value', test2: 10},
],
[
{test2: 2},
- {test: 'default', test2: 2}
+ {test: 'default', test2: 2},
],
[
{test: 'value', test2: 2},
- {test: 'value', test2: 2}
+ {test: 'value', test2: 2},
],
[
{test: 'value', test2: 2, test3: null},
- {test: 'value', test2: 2, test3: 10}
+ {test: 'value', test2: 2, test3: 10},
],
[
{test: 'value', test2: 2, test3: void 0},
- {test: 'value', test2: 2, test3: 10}
- ]
- ]
+ {test: 'value', test2: 2, test3: 10},
+ ],
+ ],
},
// Test value defaulting where hasOwnProperty is false
@@ -662,24 +662,24 @@ describe('JsonSchema', () => {
properties: {
test: {
type: 'string',
- default: 'default'
- }
- }
+ default: 'default',
+ },
+ },
},
inputs: [
[
{},
- {test: 'default'}
+ {test: 'default'},
],
[
{test: 'value'},
- {test: 'value'}
+ {test: 'value'},
],
[
Object.create({test: 'value'}),
- {test: 'default'}
- ]
- ]
+ {test: 'default'},
+ ],
+ ],
},
{
schema: {
@@ -688,24 +688,24 @@ describe('JsonSchema', () => {
properties: {
toString: /** @type {import('ext/json-schema').SchemaObject} */ ({
type: 'string',
- default: 'default'
- })
- }
+ default: 'default',
+ }),
+ },
},
inputs: [
[
{},
- {toString: 'default'}
+ {toString: 'default'},
],
[
{toString: 'value'},
- {toString: 'value'}
+ {toString: 'value'},
],
[
Object.create({toString: 'value'}),
- {toString: 'default'}
- ]
- ]
+ {toString: 'default'},
+ ],
+ ],
},
// Test enum
@@ -717,28 +717,28 @@ describe('JsonSchema', () => {
test: {
type: 'string',
default: 'value1',
- enum: ['value1', 'value2', 'value3']
- }
- }
+ enum: ['value1', 'value2', 'value3'],
+ },
+ },
},
inputs: [
[
{test: 'value1'},
- {test: 'value1'}
+ {test: 'value1'},
],
[
{test: 'value2'},
- {test: 'value2'}
+ {test: 'value2'},
],
[
{test: 'value3'},
- {test: 'value3'}
+ {test: 'value3'},
],
[
{test: 'value4'},
- {test: 'value1'}
- ]
- ]
+ {test: 'value1'},
+ ],
+ ],
},
// Test valid vs invalid default
@@ -750,16 +750,16 @@ describe('JsonSchema', () => {
test: {
type: 'integer',
default: 2,
- minimum: 1
- }
- }
+ minimum: 1,
+ },
+ },
},
inputs: [
[
{test: -1},
- {test: 2}
- ]
- ]
+ {test: 2},
+ ],
+ ],
},
{
schema: {
@@ -769,16 +769,16 @@ describe('JsonSchema', () => {
test: {
type: 'integer',
default: 1,
- minimum: 2
- }
- }
+ minimum: 2,
+ },
+ },
},
inputs: [
[
{test: -1},
- {test: -1}
- ]
- ]
+ {test: -1},
+ ],
+ ],
},
// Test references
@@ -787,29 +787,29 @@ describe('JsonSchema', () => {
definitions: {
example: {
type: 'number',
- default: 0
- }
+ default: 0,
+ },
},
- $ref: '#/definitions/example'
+ $ref: '#/definitions/example',
},
inputs: [
[
1,
- 1
+ 1,
],
[
null,
- 0
+ 0,
],
[
'test',
- 0
+ 0,
],
[
{test: 'value'},
- 0
- ]
- ]
+ 0,
+ ],
+ ],
},
{
schema: {
@@ -819,44 +819,44 @@ describe('JsonSchema', () => {
additionalProperties: false,
properties: {
test: {
- $ref: '#/definitions/example'
- }
- }
- }
+ $ref: '#/definitions/example',
+ },
+ },
+ },
},
- $ref: '#/definitions/example'
+ $ref: '#/definitions/example',
},
inputs: [
[
1,
- {}
+ {},
],
[
null,
- {}
+ {},
],
[
'test',
- {}
+ {},
],
[
{},
- {}
+ {},
],
[
{test: {}},
- {test: {}}
+ {test: {}},
],
[
{test: 'value'},
- {test: {}}
+ {test: {}},
],
[
{test: {test: {}}},
- {test: {test: {}}}
- ]
- ]
- }
+ {test: {test: {}}},
+ ],
+ ],
+ },
];
describe.each(data)('Schema %#', ({schema, inputs}) => {
@@ -880,17 +880,17 @@ describe('JsonSchema', () => {
properties: {
test: {
type: 'string',
- default: 'default'
- }
- }
+ default: 'default',
+ },
+ },
},
tests: [
{error: false, value: {test: 'default'}, action: (value) => { value.test = 'string'; }},
{error: true, value: {test: 'default'}, action: (value) => { value.test = null; }},
{error: true, value: {test: 'default'}, action: (value) => { delete value.test; }},
{error: true, value: {test: 'default'}, action: (value) => { value.test2 = 'string'; }},
- {error: false, value: {test: 'default'}, action: (value) => { delete value.test2; }}
- ]
+ {error: false, value: {test: 'default'}, action: (value) => { delete value.test2; }},
+ ],
},
{
schema: {
@@ -900,17 +900,17 @@ describe('JsonSchema', () => {
properties: {
test: {
type: 'string',
- default: 'default'
- }
- }
+ default: 'default',
+ },
+ },
},
tests: [
{error: false, value: {test: 'default'}, action: (value) => { value.test = 'string'; }},
{error: true, value: {test: 'default'}, action: (value) => { value.test = null; }},
{error: true, value: {test: 'default'}, action: (value) => { delete value.test; }},
{error: false, value: {test: 'default'}, action: (value) => { value.test2 = 'string'; }},
- {error: false, value: {test: 'default'}, action: (value) => { delete value.test2; }}
- ]
+ {error: false, value: {test: 'default'}, action: (value) => { delete value.test2; }},
+ ],
},
{
schema: {
@@ -930,13 +930,13 @@ describe('JsonSchema', () => {
properties: {
test3: {
type: 'string',
- default: 'default'
- }
- }
- }
- }
- }
- }
+ default: 'default',
+ },
+ },
+ },
+ },
+ },
+ },
},
tests: [
{error: false, action: (value) => { value.test1.test2.test3 = 'string'; }},
@@ -945,8 +945,8 @@ describe('JsonSchema', () => {
{error: true, action: (value) => { value.test1.test2 = null; }},
{error: true, action: (value) => { value.test1 = null; }},
{error: true, action: (value) => { value.test4 = 'string'; }},
- {error: false, action: (value) => { delete value.test4; }}
- ]
+ {error: false, action: (value) => { delete value.test4; }},
+ ],
},
// Array tests
@@ -955,8 +955,8 @@ describe('JsonSchema', () => {
type: 'array',
items: {
type: 'string',
- default: 'default'
- }
+ default: 'default',
+ },
},
tests: [
{error: false, value: ['default'], action: (value) => { value[0] = 'string'; }},
@@ -970,9 +970,9 @@ describe('JsonSchema', () => {
value[1] = 'string';
if (value.length !== 2) { throw new Error(`Invalid length; expected=2; actual=${value.length}`); }
if (typeof value.push !== 'function') { throw new Error(`Invalid push; expected=function; actual=${typeof value.push}`); }
- }
- }
- ]
+ },
+ },
+ ],
},
// Reference tests
@@ -984,12 +984,12 @@ describe('JsonSchema', () => {
additionalProperties: false,
properties: {
test: {
- $ref: '#/definitions/example'
- }
- }
- }
+ $ref: '#/definitions/example',
+ },
+ },
+ },
},
- $ref: '#/definitions/example'
+ $ref: '#/definitions/example',
},
tests: [
{error: false, value: {}, action: (value) => { value.test = {}; }},
@@ -998,9 +998,9 @@ describe('JsonSchema', () => {
{error: true, value: {}, action: (value) => { value.test = null; }},
{error: true, value: {}, action: (value) => { value.test = 'string'; }},
{error: true, value: {}, action: (value) => { value.test = {}; value.test.test = 'string'; }},
- {error: true, value: {}, action: (value) => { value.test = {test: 'string'}; }}
- ]
- }
+ {error: true, value: {}, action: (value) => { value.test = {test: 'string'}; }},
+ ],
+ },
];
/* eslint-enable @stylistic/no-multi-spaces */