-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
491 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const {test} = require("uvu"); | ||
const assert = require("uvu/assert"); | ||
|
||
const output = require("../src/output"); | ||
|
||
const schema = {}; | ||
const userConfig = {}; | ||
|
||
test("passes with \"asd\"", () => { | ||
const errors = output("\"asd\"", schema, userConfig); | ||
|
||
assert.equal(errors, []); | ||
}); | ||
|
||
test("passes with null", () => { | ||
const errors = output("null", schema, userConfig); | ||
|
||
assert.equal(errors, []); | ||
}); | ||
|
||
test("passes with 0", () => { | ||
const errors = output("0", schema, userConfig); | ||
|
||
assert.equal(errors, []); | ||
}); | ||
|
||
test("passes with 123", () => { | ||
const errors = output("123", schema, userConfig); | ||
|
||
assert.equal(errors, []); | ||
}); | ||
|
||
test("passes with false", () => { | ||
const errors = output("false", schema, userConfig); | ||
|
||
assert.equal(errors, []); | ||
}); | ||
|
||
test("passes with true", () => { | ||
const errors = output("true", schema, userConfig); | ||
|
||
assert.equal(errors, []); | ||
}); | ||
|
||
test("passes with []", () => { | ||
const errors = output("[]", schema, userConfig); | ||
|
||
assert.equal(errors, []); | ||
}); | ||
|
||
test("passes with {}", () => { | ||
const errors = output("{}", schema, userConfig); | ||
|
||
assert.equal(errors, []); | ||
}); | ||
|
||
test("passes with larger object", () => { | ||
const input = { "an": ["arbitrarily", "nested"], "data": "structure" }; | ||
|
||
const errors = output(JSON.stringify(input), schema, userConfig); | ||
|
||
assert.equal(errors, []); | ||
}); | ||
|
||
test.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const {test} = require("uvu"); | ||
const assert = require("uvu/assert"); | ||
|
||
const output = require("../src/output"); | ||
|
||
const schema = false; | ||
const userConfig = {}; | ||
|
||
test("throws error with \"asd\"", () => { | ||
const errors = output("\"asd\"", schema, userConfig); | ||
|
||
assert.equal(errors, [ | ||
new Error('Invalid schema') | ||
]); | ||
}); | ||
|
||
test("throws error with null", () => { | ||
const errors = output("null", schema, userConfig); | ||
|
||
assert.equal(errors, [ | ||
new Error('Invalid schema') | ||
]); | ||
}); | ||
|
||
test("throws error with 0", () => { | ||
const errors = output("0", schema, userConfig); | ||
|
||
assert.equal(errors, [ | ||
new Error('Invalid schema') | ||
]); | ||
}); | ||
|
||
test("throws error with 123", () => { | ||
const errors = output("123", schema, userConfig); | ||
|
||
assert.equal(errors, [ | ||
new Error('Invalid schema') | ||
]); | ||
}); | ||
|
||
test("throws error with false", () => { | ||
const errors = output("false", schema, userConfig); | ||
|
||
assert.equal(errors, [ | ||
new Error('Invalid schema') | ||
]); | ||
}); | ||
|
||
test("throws error with true", () => { | ||
const errors = output("true", schema, userConfig); | ||
|
||
assert.equal(errors, [ | ||
new Error('Invalid schema') | ||
]); | ||
}); | ||
|
||
test("throws error with []", () => { | ||
const errors = output("[]", schema, userConfig); | ||
|
||
assert.equal(errors, [ | ||
new Error('Invalid schema') | ||
]); | ||
}); | ||
|
||
test("throws error with {}", () => { | ||
const errors = output("{}", schema, userConfig); | ||
|
||
assert.equal(errors, [ | ||
new Error('Invalid schema') | ||
]); | ||
}); | ||
|
||
test("throws error with larger object", () => { | ||
const input = { "an": ["arbitrarily", "nested"], "data": "structure" }; | ||
|
||
const errors = output(JSON.stringify(input), schema, userConfig); | ||
|
||
assert.equal(errors, [ | ||
new Error('Invalid schema') | ||
]); | ||
}); | ||
|
||
test.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const {test} = require("uvu"); | ||
const assert = require("uvu/assert"); | ||
|
||
const ValidationError = require("../src/diagnostics/error"); | ||
const output = require("../src/output"); | ||
|
||
const schema = {type: ["number", "string"]}; | ||
const userConfig = {}; | ||
|
||
test("passes with 0", () => { | ||
const errors = output("0", schema, userConfig); | ||
const expectation = []; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("passes with \"asd\"", () => { | ||
const errors = output("\"asd\"", schema, userConfig); | ||
const expectation = []; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("throws error with null", () => { | ||
const errors = output("null", schema, userConfig); | ||
const expectation = [ | ||
new ValidationError('"null" should be number or string', "type") | ||
]; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("throws error with false", () => { | ||
const errors = output("false", schema, userConfig); | ||
const expectation = [ | ||
new ValidationError('"false" should be number or string', "type") | ||
]; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("throws error with true", () => { | ||
const errors = output("true", schema, userConfig); | ||
const expectation = [ | ||
new ValidationError('"true" should be number or string', "type") | ||
]; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("throws error with []", () => { | ||
const errors = output("[]", schema, userConfig); | ||
const expectation = [ | ||
new ValidationError('"" should be number or string', "type") | ||
]; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("throws error with {}", () => { | ||
const errors = output("{}", schema, userConfig); | ||
const expectation = [ | ||
new ValidationError('"[object Object]" should be number or string', "type") | ||
]; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const {test} = require("uvu"); | ||
const assert = require("uvu/assert"); | ||
|
||
const ValidationError = require("../src/diagnostics/error"); | ||
const output = require("../src/output"); | ||
|
||
const schema = {type: "null"}; | ||
const userConfig = {}; | ||
|
||
test("passes with null", () => { | ||
const errors = output("null", schema, userConfig); | ||
const expectation = []; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("throws error with 0", () => { | ||
const errors = output("0", schema, userConfig); | ||
const expectation = [ | ||
new ValidationError('"0" should be null', "type") | ||
]; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("throws error with 123", () => { | ||
const errors = output("123", schema, userConfig); | ||
const expectation = [ | ||
new ValidationError('"123" should be null', "type") | ||
]; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("throws error with \"asd\"", () => { | ||
const errors = output("\"asd\"", schema, userConfig); | ||
const expectation = [ | ||
new ValidationError('"asd" should be null', "type") | ||
]; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("throws error with false", () => { | ||
const errors = output("false", schema, userConfig); | ||
const expectation = [ | ||
new ValidationError('"false" should be null', "type") | ||
]; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("throws error with true", () => { | ||
const errors = output("true", schema, userConfig); | ||
const expectation = [ | ||
new ValidationError('"true" should be null', "type") | ||
]; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("throws error with []", () => { | ||
const errors = output("[]", schema, userConfig); | ||
const expectation = [ | ||
new ValidationError('"" should be null', "type") | ||
]; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test("throws error with {}", () => { | ||
const errors = output("{}", schema, userConfig); | ||
const expectation = [ | ||
new ValidationError('"[object Object]" should be null', "type") | ||
]; | ||
|
||
assert.equal(errors, expectation); | ||
}); | ||
|
||
test.run(); |
Oops, something went wrong.