Debian Codegraph @

yaml-types/src/null-object.test.ts

raw
1 import { test } from 'tap'
2 import { parse, parseDocument, stringify } from 'yaml'
3
4 import { nullobject } from '.'
5 test('parse valid', t => {
6 const res: { a: 1 } = parse(`!nullobject { a: 1 }`, {
7 customTags: [nullobject]
8 })
9 t.same(res, { a: 1 })
10 t.equal(Object.getPrototypeOf(res), null)
11 t.end()
12 })
13
14 test('parse invalid map', t => {
15 const doc = parseDocument(`!nullobject [1]`, { customTags: [nullobject] })
16 t.has(doc.warnings, { length: 1, 0: { code: 'TAG_RESOLVE_FAILED' } })
17 t.end()
18 })
19
20 test('stringify', t => {
21 const obj = Object.assign(Object.create(null), { a: 1 })
22 const res = stringify(obj, { customTags: [nullobject] })
23 t.equal(res, '!nullobject\na: 1\n')
24 t.end()
25 })