1 | const path = require('path')
|
2 | const test = require('ava')
|
3 | const visit = require('unist-util-visit')
|
4 | const {parse, jsonify} = require('..')
|
5 |
|
6 | const fixture = (...args) => path.resolve(__dirname, 'fixtures', ...args)
|
7 |
|
8 | test('it preserves anything with a value', t => {
|
9 | t.is(jsonify({value: 'foo'}), 'foo')
|
10 | t.is(jsonify({type: 'unknown', value: 'foo'}), 'foo')
|
11 | })
|
12 |
|
13 | test('it transforms lists to arrays', t => {
|
14 | visit(parse('$foo: (a, 1)'), 'list', list => {
|
15 | t.deepEqual(jsonify(list), ['a', 1])
|
16 | t.pass()
|
17 | })
|
18 | })
|
19 |
|
20 | test('it transforms map to objects', t => {
|
21 | visit(parse('$foo: (a: 1, b: 2)'), 'map', map => {
|
22 | t.deepEqual(jsonify(map), {a: 1, b: 2})
|
23 | t.pass()
|
24 | })
|
25 | })
|
26 |
|
27 | test('it transforms lists in maps', t => {
|
28 | visit(parse('$foo: (a: (1, 2))'), 'map', map => {
|
29 | t.deepEqual(jsonify(map), {a: [1, 2]})
|
30 | t.pass()
|
31 | })
|
32 | })
|
33 |
|
34 | test('it transforms maps in lists', t => {
|
35 | visit(parse('$foo: ((a: 1), (b: 2))'), 'list', list => {
|
36 | t.deepEqual(jsonify(list), [{a: 1}, {b: 2}])
|
37 | t.pass()
|
38 | })
|
39 | })
|