test: reorganize validation and error handling tests

This commit is contained in:
Johann Schopplich
2025-10-29 14:59:36 +01:00
parent 8d5e3c9758
commit df51ab0a1f

View File

@@ -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)', () => {
const toon = 'tags[2]: a,b,c'
expect(() => decode(toon)).toThrow()
@@ -507,9 +508,9 @@ describe('error handling', () => {
const toon = 'items[2\t]{a\tb}:\n 1,2\n 3,4'
expect(() => decode(toon)).toThrow()
})
})
})
describe('strict mode: indentation validation', () => {
describe('strict mode: indentation validation', () => {
describe('non-multiple indentation errors', () => {
it('throws when object field has non-multiple indentation', () => {
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 })
})
})
})
})
describe('blank lines in arrays', () => {
describe('strict mode: errors on blank lines inside arrays', () => {
describe('strict mode: blank lines in arrays', () => {
describe('errors on blank lines inside arrays', () => {
it('throws on blank line inside list array', () => {
const teon = 'items[3]:\n - a\n\n - b\n - c'
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'] })
})
})
})
})