akaalias_extract-highlights.../test/ToggleHighlightTest.ts

78 lines
2.7 KiB
TypeScript
Raw Permalink Normal View History

2020-12-04 11:48:13 +00:00
import 'mocha';
2020-12-05 09:13:04 +00:00
import {assert} from 'chai';
2020-12-04 11:48:13 +00:00
import ToggleHighlight from "../src/ToggleHighlight";
let subject: ToggleHighlight = null;
describe("Toggle Highlights", () => {
before(async () => {
subject = new ToggleHighlight();
});
2020-12-05 13:44:41 +00:00
describe("Empty input", () => {
2020-12-04 11:48:13 +00:00
it("Returns an empty string", () => {
const result = subject.toggleHighlight("");
assert.equal(result, "");
});
});
2020-12-05 09:13:04 +00:00
describe("Turning Highlights ON", () => {
it("Returns everything when there is no period", () => {
const result = subject.toggleHighlight("Foo", 0);
2020-12-04 11:48:13 +00:00
assert.equal(result, "==Foo==");
2020-12-05 09:13:04 +00:00
});
2020-12-04 11:48:13 +00:00
2020-12-05 09:13:04 +00:00
it("Returns first highlighted sentence", () => {
const result = subject.toggleHighlight("Foo.", 0);
assert.equal(result, "==Foo.==");
2020-12-04 11:48:13 +00:00
});
it("Returns first highlighted sentence with cursor position 0", () => {
2020-12-05 09:13:04 +00:00
const result = subject.toggleHighlight("Foo. Bar. Baz.", 0);
assert.equal(result, "==Foo.== Bar. Baz.");
2020-12-04 11:48:13 +00:00
});
2020-12-05 09:13:04 +00:00
it("Returns first highlighted sentence with cursor position 1", () => {
const result = subject.toggleHighlight("Foo. Bar. Baz.", 1);
assert.equal(result, "==Foo.== Bar. Baz.");
2020-12-04 11:48:13 +00:00
});
it("Returns second highlighted sentence with cursor position 6", () => {
2020-12-05 09:13:04 +00:00
const result = subject.toggleHighlight("Foo. Bar. Baz.", 6);
assert.equal(result, "Foo. ==Bar.== Baz.");
});
it("Returns second highlighted sentence with cursor position 8", () => {
const result = subject.toggleHighlight("Foo. Bar. Baz.", 8);
assert.equal(result, "Foo. ==Bar.== Baz.");
});
it("Returns second highlighted sentence with cursor position 10", () => {
const result = subject.toggleHighlight("==Foo.== Bar. Baz.", 10);
assert.equal(result, "==Foo.== ==Bar.== Baz.");
});
});
describe("Turning Highlights OFF", () => {
it("Returns sentence", () => {
const result = subject.toggleHighlight("==Foo.==", 2);
assert.equal(result, "Foo.");
2020-12-04 11:48:13 +00:00
});
2020-12-05 09:13:04 +00:00
it("Returns first un-highlighted and second sentence", () => {
const result = subject.toggleHighlight("==Foo.== Bar.", 2);
2020-12-04 11:48:13 +00:00
assert.equal(result, "Foo. Bar.");
});
2020-12-05 09:13:04 +00:00
it("Returns first sentence un-highlighted", () => {
const result = subject.toggleHighlight("==Foo.== ==Bar.==", 2);
assert.equal(result, "Foo. ==Bar.==");
});
it("Returns second sentence un-highlighted", () => {
const result = subject.toggleHighlight("==Foo.== ==Bar.==", 11);
assert.equal(result, "==Foo.== Bar.");
});
2020-12-04 11:48:13 +00:00
});
});