-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganize tests; add tests; minor fixes
- Loading branch information
1 parent
b6ca2dc
commit 3f2c6b5
Showing
15 changed files
with
213 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ notifications: | |
language: node_js | ||
|
||
node_js: | ||
- "0.12" | ||
- "4.1.1" | ||
|
||
install: | ||
- npm install | ||
|
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
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
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
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
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
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
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
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
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
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,96 @@ | ||
import * as assert from 'assert'; | ||
import {Scanner} from '../../src/cmd_line/scanner'; | ||
|
||
suite("command line scanner", () => { | ||
|
||
test("ctor", () => { | ||
var state = new Scanner("dog"); | ||
assert.equal(state.input, "dog"); | ||
}); | ||
|
||
test("can detect EOF with empty input", () => { | ||
var state = new Scanner(""); | ||
assert.ok(state.isAtEof); | ||
}); | ||
|
||
test("next() returns EOF at EOF", () => { | ||
var state = new Scanner(""); | ||
assert.equal(state.next(), Scanner.EOF); | ||
assert.equal(state.next(), Scanner.EOF); | ||
assert.equal(state.next(), Scanner.EOF); | ||
}); | ||
|
||
test("can scan", () => { | ||
var state = new Scanner("dog"); | ||
assert.equal(state.next(), "d"); | ||
assert.equal(state.next(), "o"); | ||
assert.equal(state.next(), "g"); | ||
assert.equal(state.next(), Scanner.EOF); | ||
}); | ||
|
||
test("can emit", () => { | ||
var state = new Scanner("dog cat"); | ||
state.next(); | ||
state.next(); | ||
state.next(); | ||
assert.equal(state.emit(), "dog"); | ||
state.next(); | ||
state.next(); | ||
state.next(); | ||
state.next(); | ||
assert.equal(state.emit(), " cat"); | ||
}); | ||
|
||
test("can ignore", () => { | ||
var state = new Scanner("dog cat"); | ||
state.next(); | ||
state.next(); | ||
state.next(); | ||
state.next(); | ||
state.ignore(); | ||
state.next(); | ||
state.next(); | ||
state.next(); | ||
assert.equal(state.emit(), "cat"); | ||
}); | ||
|
||
test("can skip whitespace", () => { | ||
var state = new Scanner("dog cat"); | ||
state.next(); | ||
state.next(); | ||
state.next(); | ||
state.ignore(); | ||
state.skipWhiteSpace(); | ||
assert.equal(state.next(), "c"); | ||
}); | ||
|
||
test("can skip whitespace with one char before EOF", () => { | ||
var state = new Scanner("dog c"); | ||
state.next(); | ||
state.next(); | ||
state.next(); | ||
state.ignore(); | ||
state.skipWhiteSpace(); | ||
assert.equal(state.next(), "c"); | ||
}); | ||
|
||
test("can skip whitespace at EOF", () => { | ||
var state = new Scanner("dog "); | ||
state.next(); | ||
state.next(); | ||
state.next(); | ||
state.ignore(); | ||
state.skipWhiteSpace(); | ||
assert.equal(state.next(), Scanner.EOF); | ||
}); | ||
|
||
test("can expect one of a set", () => { | ||
var state = new Scanner("dog cat"); | ||
state.expectOneOf("dog", "mule", "monkey"); | ||
}); | ||
|
||
test("can expect only one of a set", () => { | ||
var state = new Scanner("dog cat"); | ||
assert.throws(() => state.expectOneOf("mule", "monkey")); | ||
}); | ||
}); |
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,44 @@ | ||
// The module 'assert' provides assertion methods from node | ||
import * as assert from 'assert'; | ||
|
||
import {commandParsers} from '../../src/cmd_line/subparser'; | ||
|
||
suite(":quit args parser", () => { | ||
|
||
test("has all aliases", () => { | ||
assert.equal(commandParsers.quit.name, commandParsers.q.name); | ||
}); | ||
|
||
test("can parse empty args", () => { | ||
var args = commandParsers.quit(""); | ||
assert.equal(args.arguments.bang, undefined); | ||
assert.equal(args.arguments.range, undefined); | ||
}); | ||
|
||
test("ignores trailing white space", () => { | ||
var args = commandParsers.quit(" "); | ||
assert.equal(args.arguments.bang, undefined); | ||
assert.equal(args.arguments.range, undefined); | ||
}); | ||
|
||
test("can parse !", () => { | ||
var args = commandParsers.quit("!"); | ||
assert.ok(args.arguments.bang); | ||
assert.equal(args.arguments.range, undefined); | ||
}); | ||
|
||
test("throws if space before !", () => { | ||
assert.throws(() => commandParsers.quit(" !")); | ||
}); | ||
|
||
test("ignores space after !", () => { | ||
|
||
var args = commandParsers.quit("! "); | ||
assert.equal(args.arguments.bang, true); | ||
assert.equal(args.arguments.range, undefined); | ||
}); | ||
|
||
test("throws if bad input", () => { | ||
assert.throws(() => commandParsers.quit("x")); | ||
}); | ||
}); |
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
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,35 @@ | ||
// The module 'assert' provides assertion methods from node | ||
import * as assert from 'assert'; | ||
import {VimError, ErrorCode} from '../src/error'; | ||
|
||
suite("ErrorCode", () => { | ||
|
||
test("contains known errors", () => { | ||
assert.equal(ErrorCode.E32, 32); | ||
assert.equal(ErrorCode.E37, 37); | ||
assert.equal(ErrorCode.E488, 488); | ||
}); | ||
}); | ||
|
||
suite("vimError", () => { | ||
|
||
test("ctor", () => { | ||
const e = new VimError(100, "whoof!"); | ||
assert.equal(e.code, 100); | ||
assert.equal(e.message, "whoof!"); | ||
}); | ||
|
||
test("can instantiate known errors", () => { | ||
var e = VimError.fromCode(ErrorCode.E32); | ||
assert.equal(e.code, 32); | ||
assert.equal(e.message, "No file name"); | ||
|
||
e = VimError.fromCode(ErrorCode.E37); | ||
assert.equal(e.code, 37); | ||
assert.equal(e.message, "No write since last change (add ! to override)"); | ||
|
||
e = VimError.fromCode(ErrorCode.E488); | ||
assert.equal(e.code, 488); | ||
assert.equal(e.message, "Trailing characters"); | ||
}); | ||
}); |
Oops, something went wrong.