|
1 | 1 | import { describe, it } from 'node:test' |
2 | 2 | import assert from 'node:assert/strict' |
3 | | -import { dump, JSON_SCHEMA, CORE_SCHEMA, defineMappingTag, realMapTag, YAMLException } from 'js-yaml' |
| 3 | +import { dump, load, JSON_SCHEMA, CORE_SCHEMA, defineMappingTag, realMapTag, YAMLException } from 'js-yaml' |
4 | 4 |
|
5 | 5 | describe('dump options', () => { |
6 | 6 | it('schema — decides which plain scalars need quoting', () => { |
@@ -96,6 +96,16 @@ describe('dump options', () => { |
96 | 96 | assert.equal(dump({ a: [1, 2] }, { flowLevel: 1 }), 'a: [1, 2]\n') |
97 | 97 | }) |
98 | 98 |
|
| 99 | + it('flowLevel — quotes a colon followed by a flow indicator', () => { |
| 100 | + // In flow context a `:` followed by a flow indicator ({ } [ ] ,) is not |
| 101 | + // plain-safe (ns-plain-safe-in excludes c-flow-indicator), so the value |
| 102 | + // must be quoted for the output to re-parse. |
| 103 | + for (const value of [':{', ':[', ':,', ':}', ':]', 'x:{']) { |
| 104 | + assert.deepStrictEqual(load(dump([value], { flowLevel: 0 })), [value]) |
| 105 | + assert.deepStrictEqual(load(dump({ k: value }, { flowLevel: 0 })), { k: value }) |
| 106 | + } |
| 107 | + }) |
| 108 | + |
99 | 109 | it('transform — mutates the generated documents before presentation', () => { |
100 | 110 | const output = dump({ values: [1, 2] }, { |
101 | 111 | flowLevel: 1, |
|
0 commit comments