mirror of
https://github.com/voson-wang/toon.git
synced 2026-01-29 23:34:10 +08:00
test: reorganize validation and error handling tests
This commit is contained in:
@@ -473,7 +473,8 @@ describe('length marker option', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('error handling', () => {
|
describe('validation and error handling', () => {
|
||||||
|
describe('length and structure errors', () => {
|
||||||
it('throws on array length mismatch (inline primitives)', () => {
|
it('throws on array length mismatch (inline primitives)', () => {
|
||||||
const toon = 'tags[2]: a,b,c'
|
const toon = 'tags[2]: a,b,c'
|
||||||
expect(() => decode(toon)).toThrow()
|
expect(() => decode(toon)).toThrow()
|
||||||
@@ -507,9 +508,9 @@ describe('error handling', () => {
|
|||||||
const toon = 'items[2\t]{a\tb}:\n 1,2\n 3,4'
|
const toon = 'items[2\t]{a\tb}:\n 1,2\n 3,4'
|
||||||
expect(() => decode(toon)).toThrow()
|
expect(() => decode(toon)).toThrow()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('strict mode: indentation validation', () => {
|
describe('strict mode: indentation validation', () => {
|
||||||
describe('non-multiple indentation errors', () => {
|
describe('non-multiple indentation errors', () => {
|
||||||
it('throws when object field has non-multiple indentation', () => {
|
it('throws when object field has non-multiple indentation', () => {
|
||||||
const toon = 'a:\n b: 1' // 3 spaces with indent=2
|
const toon = 'a:\n b: 1' // 3 spaces with indent=2
|
||||||
@@ -601,10 +602,10 @@ describe('strict mode: indentation validation', () => {
|
|||||||
expect(decode(toon)).toEqual({ a: 1, b: 2 })
|
expect(decode(toon)).toEqual({ a: 1, b: 2 })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('blank lines in arrays', () => {
|
describe('strict mode: blank lines in arrays', () => {
|
||||||
describe('strict mode: errors on blank lines inside arrays', () => {
|
describe('errors on blank lines inside arrays', () => {
|
||||||
it('throws on blank line inside list array', () => {
|
it('throws on blank line inside list array', () => {
|
||||||
const teon = 'items[3]:\n - a\n\n - b\n - c'
|
const teon = 'items[3]:\n - a\n\n - b\n - c'
|
||||||
expect(() => decode(teon)).toThrow(/blank line/i)
|
expect(() => decode(teon)).toThrow(/blank line/i)
|
||||||
@@ -681,4 +682,5 @@ describe('blank lines in arrays', () => {
|
|||||||
expect(decode(teon, { strict: false })).toEqual({ items: ['a', 'b'] })
|
expect(decode(teon, { strict: false })).toEqual({ items: ['a', 'b'] })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user