Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions js/ohm/tests/test-add-command-grammar.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* Tests for the add and add/to command(s)
*/
ohm = require('ohm-js');
const ohm = require('ohm-js');
// Instantiate the grammar.
var fs = require('fs');
var g = ohm.grammar(fs.readFileSync('./js/ohm/simpletalk.ohm'));
var g = ohm.grammar(fs.readFileSync('./js/ohm/simpletalk.ohm').toString());

var chai = require('chai');
var assert = chai.assert;
Expand All @@ -29,63 +29,63 @@ const objects = [
];

describe("Add Model", () => {
it ("Basic Add (no id)", () => {
it("Basic Add (no id)", () => {
objects.forEach((d) => {
const s = `add ${d} to current card`;
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_addModelTo");
semanticMatchTest(s, "Statement");
});
});
it ("Basic Add (wth id)", () => {
it("Basic Add (wth id)", () => {
objects.forEach((d) => {
const s = `add ${d} to card 20`;
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_addModelTo");
semanticMatchTest(s, "Statement");
});
});
it ("Add to 'this'", () => {
it("Add to 'this'", () => {
objects.forEach((d) => {
const s = `add ${d} to this stack`;
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_addModelTo");
semanticMatchTest(s, "Statement");
});
});
it ("Add to 'current'", () => {
it("Add to 'current'", () => {
objects.forEach((d) => {
const s = `add ${d} to current stack`;
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_addModelTo");
semanticMatchTest(s, "Statement");
});
});
it ("Basic Add (with name, no id)", () => {
it("Basic Add (with name, no id)", () => {
objects.forEach((d) => {
const s = `add ${d} "newPart 123" to current card`;
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_addModelTo");
semanticMatchTest(s, "Statement");
});
});
it ("Basic Add (with name, wth id)", () => {
it("Basic Add (with name, wth id)", () => {
objects.forEach((d) => {
const s = `add ${d} "newPart 123" to card 20`;
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_addModelTo");
semanticMatchTest(s, "Statement");
});
});
it ("Add named to 'this'", () => {
it("Add named to 'this'", () => {
objects.forEach((d) => {
const s = `add ${d} "newPart 123" to this stack`;
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_addModelTo");
semanticMatchTest(s, "Statement");
});
});
it ("Add named to 'current'", () => {
it("Add named to 'current'", () => {
objects.forEach((d) => {
const s = `add ${d} "newPart123" to current stack`;
semanticMatchTest(s, "Command");
Expand All @@ -110,13 +110,13 @@ describe("Add Model", () => {
semanticMatchTest(s, "Statement");
});
});
it ("Bad add (world)", () => {
it("Bad add (world)", () => {
const s = "add world to card";
semanticMatchFailTest(s, "Command_addModel");
semanticMatchFailTest(s, "Command_addModelTo");
semanticMatchFailTest(s, "Command");
});
it ("Bad add (invalid context)", () => {
it("Bad add (invalid context)", () => {
const s = "add button to new stack";
semanticMatchFailTest(s, "Command_addModel");
semanticMatchFailTest(s, "Command_addModelTo");
Expand Down
18 changes: 9 additions & 9 deletions js/ohm/tests/test-arbitrary-command-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@
* Tests dealing with user-defined commands
* and messages
*/
ohm = require('ohm-js');
const ohm = require('ohm-js');
// Instantiate the grammar.
var fs = require('fs');
var g = ohm.grammar(fs.readFileSync('./js/ohm/simpletalk.ohm'));
var g = ohm.grammar(fs.readFileSync('./js/ohm/simpletalk.ohm').toString());

var chai = require('chai');
var assert = chai.assert;

const matchTest = (str) => {
const match = g.match(str);
assert.isTrue(match.succeeded());
}
};
const semanticMatchTest = (str, semanticType) => {
const typeMatch = g.match(str, semanticType);
assert.isTrue(typeMatch.succeeded());
}
};
const matchAndsemanticMatchTest = (str, semanticType) => {
matchTest(str);
const typeMatch = g.match(str, semanticType);
assert.isTrue(typeMatch.succeeded());
}
};
const semanticMatchFailTest = (str, semanticType) => {
const typeMatch = g.match(str, semanticType);
assert.isFalse(typeMatch.succeeded());
}
String.prototype.unCapitalize = function() {
};
String.prototype.unCapitalize = function () {
return this.charAt(0).toLowerCase() + this.slice(1);
}
};


describe('Basic Definitions', () => {
Expand Down Expand Up @@ -131,7 +131,7 @@ describe("Arbitrary Message Statements with literal arguments", () => {
semanticMatchTest(str, "Command_arbitraryCommand");
});
it('with one argument, negative', () => {
str = `myCustomCommand -0.034`;
const str = `myCustomCommand -0.034`;
semanticMatchTest(str, "Command");
semanticMatchTest(str, "Command_arbitraryCommand");
});
Expand Down
18 changes: 9 additions & 9 deletions js/ohm/tests/test-comment-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@
* Test Comments in the grammar
*/

ohm = require('ohm-js');
const ohm = require('ohm-js');
// Instantiate the grammar.
var fs = require('fs');
var g = ohm.grammar(fs.readFileSync('./js/ohm/simpletalk.ohm'));
var g = ohm.grammar(fs.readFileSync('./js/ohm/simpletalk.ohm').toString());

var chai = require('chai');
var assert = chai.assert;

const matchTest = (str) => {
const match = g.match(str);
assert.isTrue(match.succeeded());
}
};
const semanticMatchTest = (str, semanticType) => {
const typeMatch = g.match(str, semanticType);
assert.isTrue(typeMatch.succeeded());
}
};
const matchAndsemanticMatchTest = (str, semanticType) => {
matchTest(str);
const typeMatch = g.match(str, semanticType);
assert.isTrue(typeMatch.succeeded());
}
};
const semanticMatchFailTest = (str, semanticType) => {
const typeMatch = g.match(str, semanticType);
assert.isFalse(typeMatch.succeeded());
}
String.prototype.unCapitalize = function() {
};
String.prototype.unCapitalize = function () {
return this.charAt(0).toLowerCase() + this.slice(1);
}
};

describe("Comment Grammar Tests", () => {
describe("Basic", () => {
Expand Down Expand Up @@ -81,7 +81,7 @@ describe("Comment Grammar Tests", () => {
'answer "hello"',
'end doSomething'
].join('\n');
matchTest(str, 'Script');
matchTest(str);
});

it("Can handle comments at the inside top of a handler", () => {
Expand Down
44 changes: 22 additions & 22 deletions js/ohm/tests/test-core-commands.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ohm = require('ohm-js');
const ohm = require('ohm-js');
// Instantiate the grammar.
var fs = require('fs');
var g = ohm.grammar(fs.readFileSync('./js/ohm/simpletalk.ohm'));
var g = ohm.grammar(fs.readFileSync('./js/ohm/simpletalk.ohm').toString());

var chai = require('chai');
var assert = chai.assert;
Expand All @@ -23,7 +23,7 @@ const semanticMatchFailTest = (str, semanticType) => {
const typeMatch = g.match(str, semanticType);
assert.isFalse(typeMatch.succeeded());
};
String.prototype.unCapitalize = function() {
String.prototype.unCapitalize = function () {
return this.charAt(0).toLowerCase() + this.slice(1);
};

Expand All @@ -34,14 +34,14 @@ const objects = [

describe("Core commands", () => {
describe("Go To", () => {
it ("go to direction with no object fails", () => {
it("go to direction with no object fails", () => {
const direction = ["next", "previous"];
direction.forEach((d) => {
const s = `go to ${d}`;
semanticMatchFailTest(s, "Command");
});
});
it ("go to with object", () => {
it("go to with object", () => {
const direction = ["next", "previous"];
direction.forEach((d) => {
const s = `go to ${d} card`;
Expand All @@ -50,41 +50,41 @@ describe("Core commands", () => {
semanticMatchTest(s, "Statement");
});
});
it ("go to by index", () => {
it("go to by index", () => {
const s = "go to card 2";
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_goToByObjectSpecifier");
semanticMatchTest(s, "Statement");
});
it ("go to by id", () => {
it("go to by id", () => {
const s = "go to stack id 2";
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_goToByObjectSpecifier");
semanticMatchTest(s, "Statement");
});
it ("go to by name", () => {
it("go to by name", () => {
const s = 'go to stack "cool stack"';
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_goToByObjectSpecifier");
semanticMatchTest(s, "Statement");
});
it ("go to website", () => {
it("go to website", () => {
const s = 'go to website "http//coolsite.awesome"';
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_goToWebsite");
semanticMatchTest(s, "Statement");
});
it ("Bad go to: invalid object", () => {
it("Bad go to: invalid object", () => {
const s = "go to card";
semanticMatchFailTest(s, "Command");
});
it ("Bad go to: invalid structure", () => {
it("Bad go to: invalid structure", () => {
const s = "go to next card 42";
semanticMatchFailTest(s, "Command");
});
});
describe("Delete", () => {
it ("Basic Remove Model (no id)", () => {
it("Basic Remove Model (no id)", () => {
const direction = ["stack", "background", "card", "button"];
direction.forEach((d) => {
const s = `delete this ${d}`;
Expand All @@ -93,7 +93,7 @@ describe("Core commands", () => {
semanticMatchTest(s, "Statement");
});
});
it ("Basic Remove model (with id)", () => {
it("Basic Remove model (with id)", () => {
const direction = ["stack", "background", "card", "button"];
direction.forEach((d) => {
const s = `delete ${d} 20`;
Expand All @@ -102,38 +102,38 @@ describe("Core commands", () => {
semanticMatchTest(s, "Statement");
});
});
it ("Remove property with object specifier", () => {
it("Remove property with object specifier", () => {
const s = `delete property "MyProp" from this button`;
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_deleteProperty");
semanticMatchTest(s, "Statement");
});
it ("Remove property without object specifier", () => {
it("Remove property without object specifier", () => {
const s = `delete property "MyProp"`;
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_deleteProperty");
semanticMatchTest(s, "Statement");
});
it.skip ("Bad delete (world)", () => {
it.skip("Bad delete (world)", () => {
const s = "delete this world";
semanticMatchFailTest(s, "Command_deleteModel");
semanticMatchFailTest(s, "Command");
});
});
describe("Answer", () => {
it ("simple answer", () => {
it("simple answer", () => {
const s = "answer \"42\"";
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Command_answer");
semanticMatchTest(s, "Statement");
});
it ("bad answer", () => {
it("bad answer", () => {
const s = "answer \"42\" \"42\"";
semanticMatchFailTest(s, "Command");
});
});
describe("Set", () => {
it ("Set someProperty with id", () => {
it("Set someProperty with id", () => {

objects.forEach((d) => {
const s = `set "someProperty" to "some value" in ${d} id 10`;
Expand All @@ -142,7 +142,7 @@ describe("Core commands", () => {
semanticMatchTest(s, "Statement");
});
});
it ("Set someProperty (in context)", () => {
it("Set someProperty (in context)", () => {
objects.forEach((d) => {
const s = `set "someProperty" to "some value"`;
semanticMatchTest(s, "Command");
Expand Down Expand Up @@ -194,13 +194,13 @@ describe("Core commands", () => {
});
});
describe("Arbitrary", () => {
it ("arbitrary command", () => {
it("arbitrary command", () => {
const s = "anythinggoes";
semanticMatchTest(s, "Command");
semanticMatchTest(s, "Statement");
});
});
it ("Bad command (arbitrary with digits)", () => {
it("Bad command (arbitrary with digits)", () => {
semanticMatchFailTest("1234arrowKe", "Command");
});
});
Loading