|
| 1 | +/* |
| 2 | + Copyright © 2018 Andrew Powell |
| 3 | +
|
| 4 | + This Source Code Form is subject to the terms of the Mozilla Public |
| 5 | + License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 | + file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 | +
|
| 8 | + The above copyright notice and this permission notice shall be |
| 9 | + included in all copies or substantial portions of this Source Code Form. |
| 10 | +*/ |
| 11 | +const test = require('ava'); |
| 12 | + |
| 13 | +const { nodeToString, parse } = require('../lib'); |
| 14 | + |
| 15 | +const { snapshot, throws } = require('./fixtures/quoted'); |
| 16 | + |
| 17 | +for (const fixture of snapshot) { |
| 18 | + test(fixture, (t) => { |
| 19 | + const root = parse(fixture); |
| 20 | + const nodes = root.nodes.map((node) => { |
| 21 | + delete node.parent; // eslint-disable-line no-param-reassign |
| 22 | + return node; |
| 23 | + }); |
| 24 | + const string = nodeToString(root); |
| 25 | + |
| 26 | + t.is(string, fixture); |
| 27 | + t.is(fixture, root.toString()); |
| 28 | + t.snapshot(root.first.toString()); |
| 29 | + t.snapshot(string); |
| 30 | + t.snapshot(nodes); |
| 31 | + |
| 32 | + root.clone(); |
| 33 | + }); |
| 34 | + |
| 35 | + test(`${fixture} be should cloned`, (t) => { |
| 36 | + const root = parse(fixture); |
| 37 | + const nodes = root.nodes.map((node) => { |
| 38 | + delete node.parent; // eslint-disable-line no-param-reassign |
| 39 | + return node; |
| 40 | + }); |
| 41 | + const string = nodeToString(root); |
| 42 | + |
| 43 | + const cloned = root.clone(); |
| 44 | + |
| 45 | + t.is(string, fixture); |
| 46 | + t.is(fixture, root.toString()); |
| 47 | + t.snapshot(cloned.first.toString()); |
| 48 | + t.snapshot(string); |
| 49 | + t.snapshot(nodes); |
| 50 | + }); |
| 51 | +} |
| 52 | + |
| 53 | +for (const fixture of throws) { |
| 54 | + test(fixture, (t) => { |
| 55 | + t.throws(() => parse(fixture)); |
| 56 | + }); |
| 57 | +} |
0 commit comments