pb-parser/test/test.js

102 lines
1.9 KiB
JavaScript
Raw Normal View History

2023-05-15 14:24:41 +00:00
import {deepStrictEqual} from "assert";
import {parse} from "../index.js";
const SIMPLE_KV_VALUES =
`text: "text"
integer: 123
float: 123.456
`
const OBJECT =
`object {
text: "text"
integer: 123
float: 123.456
}
`
const OBJECTS =
`object1 {
text: "text"
integer: 123
float: 123.456
}
object2 {
text: "text"
integer: 123
float: 123.456
}
`
const OBJECT_AND_SIMPLE_VALUES =
`text: "text"
integer: 123
float: 123.456
object1 {
text: "text"
integer: 123
float: 123.456
}
object2 {
text: "text"
integer: 123
float: 123.456
}
`
describe("#parse()", () => {
it("should parse simple KV values", () => {
deepStrictEqual({
"text": "text",
"integer": 123,
"float": 123.456,
}, parse(SIMPLE_KV_VALUES))
})
it("should parse a single object", () => {
deepStrictEqual({
"object": {
"text": "text",
"integer": 123,
"float": 123.456,
},
}, parse(OBJECT))
})
it("should parse multiple objects", () => {
deepStrictEqual({
"object1": {
"text": "text",
"integer": 123,
"float": 123.456,
},
"object2": {
"text": "text",
"integer": 123,
"float": 123.456,
},
}, parse(OBJECTS))
})
it("should parse objects and simple values", () => {
deepStrictEqual({
"text": "text",
"integer": 123,
"float": 123.456,
"object1": {
"text": "text",
"integer": 123,
"float": 123.456,
},
"object2": {
"text": "text",
"integer": 123,
"float": 123.456,
},
}, parse(OBJECT_AND_SIMPLE_VALUES))
})
})