|
1 | 1 | import { test } from 'tap'
|
2 |
| -import { parse, stringify } from 'yaml' |
| 2 | +import { Document, type Scalar, parse, stringify } from 'yaml' |
3 | 3 |
|
4 |
| -import { sharedSymbol } from '.' |
| 4 | +import { sharedSymbol, symbol } from '.' |
5 | 5 |
|
6 |
| -test('parse', t => { |
| 6 | +test('parse shared', t => { |
7 | 7 | const res: symbol = parse(`!symbol/shared foo`, {
|
8 |
| - customTags: [sharedSymbol] |
| 8 | + customTags: [sharedSymbol, symbol] |
9 | 9 | })
|
10 | 10 | t.type(res, 'symbol')
|
11 | 11 | t.same(Symbol.keyFor(res), 'foo')
|
12 | 12 | t.end()
|
13 | 13 | })
|
14 | 14 |
|
15 | 15 | test('stringify shared', t => {
|
16 |
| - const res = stringify(Symbol.for('some\nsymbol'), { |
17 |
| - customTags: [sharedSymbol] |
| 16 | + const doc = new Document<Scalar, false>(Symbol.for('some\nsymbol'), { |
| 17 | + customTags: [sharedSymbol, symbol] |
18 | 18 | })
|
19 |
| - t.equal(res, '!symbol/shared |-\nsome\nsymbol\n') |
20 |
| - t.end() |
21 |
| -}) |
| 19 | + t.equal(doc.toString(), '!symbol/shared |-\nsome\nsymbol\n') |
| 20 | + |
| 21 | + doc.contents.value = Symbol('foo') |
| 22 | + t.throws(() => doc.toString(), { name: 'TypeError' }) |
| 23 | + |
| 24 | + doc.contents.value = 42 |
| 25 | + t.throws(() => doc.toString(), { name: 'TypeError' }) |
22 | 26 |
|
23 |
| -test('stringify private', t => { |
24 | 27 | t.throws(() =>
|
25 | 28 | stringify(Symbol('some\nsymbol'), { customTags: [sharedSymbol] })
|
26 | 29 | )
|
| 30 | + |
| 31 | + t.end() |
| 32 | +}) |
| 33 | + |
| 34 | +test('parse private', t => { |
| 35 | + const res: symbol = parse(`!symbol foo`, { |
| 36 | + customTags: [sharedSymbol, symbol] |
| 37 | + }) |
| 38 | + t.type(res, 'symbol') |
| 39 | + t.notOk(Symbol.keyFor(res)) |
| 40 | + t.end() |
| 41 | +}) |
| 42 | + |
| 43 | +test('stringify private', t => { |
| 44 | + const doc = new Document<Scalar, false>(Symbol('some\nsymbol'), { |
| 45 | + customTags: [sharedSymbol, symbol] |
| 46 | + }) |
| 47 | + t.equal(doc.toString(), '!symbol |-\nsome\nsymbol\n') |
| 48 | + |
| 49 | + doc.contents.value = Symbol.for('foo') |
| 50 | + t.equal(doc.toString(), '!symbol foo\n') |
| 51 | + |
| 52 | + doc.contents.value = 'foo' |
| 53 | + t.throws(() => doc.toString(), { name: 'TypeError' }) |
| 54 | + |
27 | 55 | t.end()
|
28 | 56 | })
|
0 commit comments