Skip to content

Commit

Permalink
add test for Grammar.toJSON and fromJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
System Administrator authored and System Administrator committed Sep 8, 2020
1 parent 9623b17 commit fdd14f1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion test/grammar-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('RiTa.Grammar', () => {
ok(typeof rg.rules['noun_phrase'] !== 'undefined');
ok(rg.expand().length > 0);
});

grammars.forEach(g => { // as JS objects
rg.setRules(g);
ok(typeof rg.rules !== 'undefined');
Expand Down Expand Up @@ -397,6 +397,18 @@ describe('RiTa.Grammar', () => {
}
});

it("should correctly call toJSON and fromJSON",() => {
let json = {"$start":"$pet $iphone","$pet":"(dog | cat)","$iphone":"(iphoneSE | iphone12)"};
let rg = new Grammar(json);
let generatedJSON = rg.toJSON();
let rg2 = Grammar.fromJSON(generatedJSON);
ok(rg2 !== 'undefined');
expect(rg.toString()).eq(rg2.toString());
expect(rg.context === rg2.context);
expect(rg.rules === rg2.rules);
expect(rg === rg2);
});

function eql(a, b, c) { expect(a).eql(b, c); }
function eq(a, b, c) { expect(a).eq(b, c); }
function ok(a, m) { expect(a, m).to.be.true; }
Expand Down

0 comments on commit fdd14f1

Please sign in to comment.