Skip to content

Commit

Permalink
playing around with test file format for mdsl and json split
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolas Howard committed Feb 7, 2024
1 parent 3b60629 commit a9bc843
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 33 deletions.
6 changes: 3 additions & 3 deletions dist/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/bundle.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import State from "./State";
import { validateDefinition } from "./BehaviourTreeDefinitionValidator";
import { convertMDSLToJSON } from "./mdsl/MDSLDefinitionParser";
import { BehaviourTree, FlattenedTreeNode } from "./BehaviourTree";
import { BehaviourTreeOptions } from "./BehaviourTreeOptions";
export { BehaviourTree, State, convertMDSLToJSON, validateDefinition };
export type { FlattenedTreeNode };
export type { FlattenedTreeNode, BehaviourTreeOptions };
6 changes: 3 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/index.js.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/BehaviourTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { convertMDSLToJSON } from "./mdsl/MDSLDefinitionParser";
import { RootNodeDefinition } from "./BehaviourTreeDefinition";
import { validateJSONDefinition } from "./BehaviourTreeDefinitionValidator";
import buildRootNode from "./BehaviourTreeBuilder";
import { isNullOrUndefined } from "./BehaviourTreeDefinitionUtilities";

// Purely for outside inspection of the tree.
export type FlattenedTreeNode = {
Expand Down Expand Up @@ -46,13 +47,13 @@ export class BehaviourTree {
private options: BehaviourTreeOptions = {}
) {
// The tree definition must be defined.
if (!definition) {
throw new Error("the tree definition must be a string ro");
if (isNullOrUndefined(definition)) {
throw new Error("tree definition not defined");
}

// The agent must be defined and not null.
if (typeof agent !== "object" || agent === null) {
throw new Error("the agent must be defined and not null");
throw new Error("the agent must be an object and not null");
}

try {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import State from "./State";
import { validateDefinition } from "./BehaviourTreeDefinitionValidator";
import { convertMDSLToJSON } from "./mdsl/MDSLDefinitionParser";
import { BehaviourTree, FlattenedTreeNode } from "./BehaviourTree";
import { BehaviourTreeOptions } from "./BehaviourTreeOptions";

export { BehaviourTree, State, convertMDSLToJSON, validateDefinition };
export type { FlattenedTreeNode };
export type { FlattenedTreeNode, BehaviourTreeOptions };
45 changes: 27 additions & 18 deletions test/behaviourTree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,46 @@ const findNode = (tree, type, caption) =>
describe("A BehaviourTree instance", () => {
describe("has initialisation logic that", () => {
describe("should error when", () => {
it("the tree definition argument is not a string", () => {
it("the tree definition argument is not defined", () => {
assert.throws(() => new mistreevous.BehaviourTree(null, {}), Error, "tree definition not defined");
assert.throws(() => new mistreevous.BehaviourTree(undefined, {}), Error, "tree definition not defined");
});

it("the agent object is not defined", () => {
assert.throws(
() => new mistreevous.BehaviourTree(null, {}),
() => new mistreevous.BehaviourTree("", undefined),
Error,
"the tree definition must be a string"
"the agent must be an object and not null"
);
});

it("the tree definition argument is not a valid tree definition", () => {
assert.throws(
() => new mistreevous.BehaviourTree("", {}),
() => new mistreevous.BehaviourTree("", null),
Error,
"error parsing tree: invalid token count"
"the agent must be an object and not null"
);
});

it("the tree definition argument contains unexpected tokens", () => {
assert.throws(
() => new mistreevous.BehaviourTree("invalid-token { }", {}),
() => new mistreevous.BehaviourTree("", 42),
Error,
"error parsing tree: unexpected token 'invalid-token'"
"the agent must be an object and not null"
);
});
});

it("the agent object is not defined", () => {
assert.throws(() => new mistreevous.BehaviourTree("", undefined), Error, "the agent must be defined");
describe("should not error when the tree definition argument is a valid definition", () => {
it("(MDSL)", () => {
const definition = "root { action [test] }";
assert.doesNotThrow(() => new mistreevous.BehaviourTree(definition, {}), Error);
});
});

it("should not error when the tree definition argument is a valid definition", () => {
assert.doesNotThrow(() => new mistreevous.BehaviourTree("root { action [test] }", {}), Error);
it("(JSON)", () => {
const definition = {
type: "root",
child: {
type: "action",
call: "test"
}
};
assert.doesNotThrow(() => new mistreevous.BehaviourTree(definition, {}), Error);
});
});
});

Expand Down

0 comments on commit a9bc843

Please sign in to comment.