Debian Codegraph @

yaml-types/src/regexp.test.ts

raw
1 import { test } from 'tap'
2 import { parse, parseDocument, stringify } from 'yaml'
3
4 import { regexp } from '.'
5
6 test('parse valid', t => {
7 const res: RegExp = parse(`!re /fo./g`, { customTags: [regexp] })
8 t.type(res, RegExp)
9 t.same(res, /fo./g)
10 t.end()
11 })
12
13 test('parse invalid wrapper', t => {
14 const doc = parseDocument(`!re foo/g`, { customTags: [regexp] })
15 t.has(doc.errors, { length: 1, 0: { code: 'TAG_RESOLVE_FAILED' } })
16 t.end()
17 })
18
19 test('parse invalid contents', t => {
20 const doc = parseDocument(`!re /foo\\/g`, { customTags: [regexp] })
21 t.has(doc.errors, { length: 1, 0: { code: 'TAG_RESOLVE_FAILED' } })
22 t.end()
23 })
24
25 test('stringify', t => {
26 const res = stringify(/foo/gm, { customTags: [regexp] })
27 t.equal(res, '!re /foo/gm\n')
28 t.end()
29 })