|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +import assert from "assert"; |
| 4 | +import { ftl } from "./util"; |
| 5 | +import { FluentParser } from "../src"; |
| 6 | +import * as AST from "../src/ast"; |
| 7 | + |
| 8 | +suite("BaseNode.equals", function() { |
| 9 | + setup(function() { |
| 10 | + this.parser = new FluentParser(); |
| 11 | + }); |
| 12 | + test("Identifier.equals", function() { |
| 13 | + const thisNode = new AST.Identifier("name"); |
| 14 | + const otherNode = new AST.Identifier("name"); |
| 15 | + assert.ok(thisNode.clone() instanceof AST.Identifier); |
| 16 | + assert.strictEqual(thisNode.equals(otherNode), true); |
| 17 | + assert.strictEqual(thisNode.equals(thisNode.clone()), true); |
| 18 | + assert.notStrictEqual(thisNode, thisNode.clone()); |
| 19 | + }); |
| 20 | + test("Node.type", function() { |
| 21 | + const thisNode = new AST.Identifier("name"); |
| 22 | + const otherNode = new AST.StringLiteral("name"); |
| 23 | + assert.strictEqual(thisNode.equals(otherNode), false); |
| 24 | + }); |
| 25 | + test("Array children", function() { |
| 26 | + const thisNode = new AST.Pattern([ |
| 27 | + new AST.TextElement("one"), |
| 28 | + new AST.TextElement("two"), |
| 29 | + new AST.TextElement("three"), |
| 30 | + ]); |
| 31 | + let otherNode = new AST.Pattern([ |
| 32 | + new AST.TextElement("one"), |
| 33 | + new AST.TextElement("two"), |
| 34 | + new AST.TextElement("three"), |
| 35 | + ]); |
| 36 | + assert.strictEqual(thisNode.equals(otherNode), true); |
| 37 | + }); |
| 38 | + test("Variant order matters", function() { |
| 39 | + const thisRes = this.parser.parse(ftl` |
| 40 | + msg = { $val -> |
| 41 | + [few] things |
| 42 | + [1] one |
| 43 | + *[other] default |
| 44 | + } |
| 45 | + `); |
| 46 | + const otherRes = this.parser.parse(ftl` |
| 47 | + msg = { $val -> |
| 48 | + [few] things |
| 49 | + *[other] default |
| 50 | + [1] one |
| 51 | + } |
| 52 | + `); |
| 53 | + const thisNode = thisRes.body[0]; |
| 54 | + const otherNode = otherRes.body[0]; |
| 55 | + assert.strictEqual(thisNode.equals(otherNode), false); |
| 56 | + assert.strictEqual(thisRes.equals(thisRes.clone(), []), true); |
| 57 | + assert.notStrictEqual(thisRes, thisRes.clone()); |
| 58 | + }); |
| 59 | + test("Attribute order matters", function() { |
| 60 | + const thisRes = this.parser.parse(ftl` |
| 61 | + msg = |
| 62 | + .attr1 = one |
| 63 | + .attr2 = two |
| 64 | + `); |
| 65 | + const otherRes = this.parser.parse(ftl` |
| 66 | + msg = |
| 67 | + .attr2 = two |
| 68 | + .attr1 = one |
| 69 | + `); |
| 70 | + const thisNode = thisRes.body[0]; |
| 71 | + const otherNode = otherRes.body[0]; |
| 72 | + assert.strictEqual(thisNode.equals(otherNode), false); |
| 73 | + }); |
| 74 | +}); |
0 commit comments