-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: switch to midori, add and fix unit tests
- Loading branch information
1 parent
01fa40a
commit a24f654
Showing
6 changed files
with
121 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { TestProps } from "@rbxts/midori"; | ||
import { CommandPath } from "./path"; | ||
|
||
export = (x: TestProps) => { | ||
x.test("create a path from a string", () => { | ||
const testString = "root/part1/part2"; | ||
const path = CommandPath.fromString(testString); | ||
x.assertEqual(path.toString(), testString); | ||
}); | ||
|
||
x.nested("operations", () => { | ||
x.test("append parts to the path", () => { | ||
const path = CommandPath.fromString("root/part1/part2"); | ||
path.append("part3"); | ||
x.assertEqual(path.getPart(path.getSize() - 1), "part3"); | ||
|
||
path.append("part4"); | ||
x.assertEqual(path.getPart(path.getSize() - 1), "part4"); | ||
}); | ||
|
||
x.test("remove parts from the path", () => { | ||
const path = CommandPath.fromString("root/part1/part2"); | ||
path.remove(0); | ||
x.assertEqual(path.getPart(0), "part1"); | ||
|
||
path.remove(path.getSize() - 1); | ||
x.assertEqual(path.getPart(path.getSize() - 1), "part1"); | ||
}); | ||
|
||
x.test("remove all parts from the path", () => { | ||
const path = CommandPath.fromString("root/part1/part"); | ||
path.clear(); | ||
x.assertEqual(path.getSize(), 0); | ||
}); | ||
|
||
x.test("return a slice of the path", () => { | ||
let path = CommandPath.fromString("root/part1/part2/part3"); | ||
path = path.slice(1, 2); | ||
x.assertEqual(path.toString(), "part1/part2"); | ||
}); | ||
}); | ||
|
||
x.nested("descendant operations", () => { | ||
x.test("check if a path is a child of another", () => { | ||
const path = CommandPath.fromString("root/part1/part2"); | ||
const path2 = CommandPath.fromString("root/part1/part2/part3"); | ||
x.assertEqual(path2.isChildOf(path), true); | ||
x.assertEqual(path.isChildOf(path2), false); | ||
}); | ||
|
||
x.test("check if a path is a descendant of another", () => { | ||
const path = CommandPath.fromString("root/part1/part2"); | ||
const path2 = CommandPath.fromString("root/part1/part2/part3/part4"); | ||
x.assertEqual(path2.isDescendantOf(path), true); | ||
x.assertEqual(path.isDescendantOf(path2), false); | ||
}); | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { TestProps } from "@rbxts/midori"; | ||
import { endsWithSpace, formatPartsAsPath, splitStringBySpace } from "./string"; | ||
|
||
export = (x: TestProps) => { | ||
x.nested("split string", () => { | ||
x.test("splits one space", () => { | ||
const testString = "part1 part2 part3"; | ||
const parts = splitStringBySpace(testString); | ||
x.assertEqual(parts.size(), 3); | ||
}); | ||
|
||
x.test("splits multiple spaces", () => { | ||
const testString = "part1 part2 part3 part4 "; | ||
const parts = splitStringBySpace(testString); | ||
x.assertEqual(parts.size(), 4); | ||
}); | ||
|
||
x.test("takes into account quoted sentences", () => { | ||
const testString = `part1 "part2 but quoted" part3 'part4' "part5"`; | ||
const parts = splitStringBySpace(testString); | ||
x.assertEqual(parts.size(), 5); | ||
x.assertEqual(parts[1], "part2 but quoted"); | ||
x.assertEqual(parts[3], "part4"); | ||
x.assertEqual(parts[4], "part5"); | ||
}); | ||
}); | ||
|
||
x.test("determines if a string ends in a space", () => { | ||
x.assertEqual(endsWithSpace("test"), false); | ||
x.assertEqual(endsWithSpace("test "), true); | ||
}); | ||
|
||
x.test("formats string array as a path string", () => { | ||
const pathString = "part1/part2/part3"; | ||
const parts = pathString.split("/"); | ||
x.assertEqual(formatPartsAsPath(parts), pathString); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters