diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-04-09 10:38:37 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-09 10:38:37 +0900 |
commit | 1656d52d2cefb3846d968c6117484e6aefe7dabe (patch) | |
tree | ab58a99b832d2571e2168f2ee0e328bc12d9580e /test/console/commandline | |
parent | c6c2da8547891b50aef2f08e5f36d258183831ff (diff) | |
parent | 5176643e64d8f4a6be5fc73f0eb48dc65322e496 (diff) |
Merge pull request #730 from ueokande/refactor-console-and-completion
Refactor console and completions
Diffstat (limited to 'test/console/commandline')
-rw-r--r-- | test/console/commandline/CommandLineParser.test.ts | 29 | ||||
-rw-r--r-- | test/console/commandline/CommandParser.test.ts | 15 |
2 files changed, 44 insertions, 0 deletions
diff --git a/test/console/commandline/CommandLineParser.test.ts b/test/console/commandline/CommandLineParser.test.ts new file mode 100644 index 0000000..6aec682 --- /dev/null +++ b/test/console/commandline/CommandLineParser.test.ts @@ -0,0 +1,29 @@ +import CommandLineParser, {InputPhase} from "../../../src/console/commandline/CommandLineParser"; +import { Command } from "../../../src/shared/Command"; +import { expect } from "chai"; + +describe("CommandLineParser", () => { + describe("#inputPhase", () => { + it("returns parsed command-line", () => { + const sut = new CommandLineParser(); + expect(sut.inputPhase("")).to.equal(InputPhase.OnCommand); + expect(sut.inputPhase("op")).to.equal(InputPhase.OnCommand); + expect(sut.inputPhase("open ")).to.equal(InputPhase.OnArgs); + expect(sut.inputPhase("open apple")).to.equal(InputPhase.OnArgs) + }); + }); + describe("#parse", () => { + it("returns parsed command-line", () => { + const sut = new CommandLineParser(); + expect(sut.parse("open google apple")).to.deep.equal({ + command: Command.Open, + args: "google apple", + }); + + expect(sut.parse("qa")).to.deep.equal({ + command: Command.QuitAll, + args: "", + }); + }) + }) +}); diff --git a/test/console/commandline/CommandParser.test.ts b/test/console/commandline/CommandParser.test.ts new file mode 100644 index 0000000..4ad78fd --- /dev/null +++ b/test/console/commandline/CommandParser.test.ts @@ -0,0 +1,15 @@ +import CommandParser, { UnknownCommandError } from "../../../src/console/commandline/CommandParser"; +import { Command } from "../../../src/shared/Command"; +import { expect } from "chai" + +describe("CommandParser", () => { + describe("#parse", () => { + it("returns matched command with the string", () => { + const sut = new CommandParser(); + expect(sut.parse("open")).to.equal(Command.Open); + expect(sut.parse("w")).to.equal(Command.WindowOpen); + expect(sut.parse("bdelete!")).to.equal(Command.BufferDeleteForce); + expect(() => sut.parse("harakiri")).to.throw(UnknownCommandError); + }) + }) +}); |