Skip to content

Commit

Permalink
add context test, unresolved
Browse files Browse the repository at this point in the history
  • Loading branch information
dhowe committed Jan 24, 2024
1 parent b737bfb commit 7b2bd65
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion test/grammar.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,37 @@ describe(title, function () {
expect(res).to.be.oneOf(['Lucy', 'Sam']);
});


LTR && it('Should reference context from transforms', function () {
const context = {
characters: [{
name: 'Lucy',
pronoun: 'she',
car: 'Acura'
},
{
name: 'Sam',
pronoun: 'he',
car: 'Subaru'
}],
chooseChar: function () {
console.log('chooseChar:', typeof this);
let chars = this.visitor.context.characters;
return chars[Math.floor(Math.random() * chars.length)];
}
}
const rules = {
start: "{$person=$chooseChar()} $sentence",
sentence: "$Meet $person.name. $person.pronoun.cap() drives $person.car",
"#person": "$sam | $lucy"
}
let result = RiGrammar.expand(rules, context);
expect(result).to.be.oneOf([
'Meet Lucy. She drives a Acura.',
'Meet Sam. He drives a Subaru.',
]);
});


it('Handles time-based gated example', function () {
let context = { hours: new Date().getHours() };
let grammar = {
Expand Down

0 comments on commit 7b2bd65

Please sign in to comment.