102 lines
1.9 KiB
JavaScript
102 lines
1.9 KiB
JavaScript
|
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))
|
||
|
})
|
||
|
})
|