2019-02-19 14:21:54 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const expect = require("chai").expect;
|
2019-10-23 09:42:01 +00:00
|
|
|
const stub = require("sinon").stub;
|
|
|
|
const log = require("../../src/log");
|
2019-02-19 14:21:54 +00:00
|
|
|
const Client = require("../../src/client");
|
2019-10-23 09:42:01 +00:00
|
|
|
const TestUtil = require("../util");
|
2019-02-19 14:21:54 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("Custom highlights", function () {
|
2019-10-23 09:42:01 +00:00
|
|
|
let userLoadedLog = "";
|
|
|
|
stub(log, "info").callsFake(TestUtil.sanitizeLog((str) => (userLoadedLog += str)));
|
|
|
|
|
2019-10-31 09:24:19 +00:00
|
|
|
const client = new Client(
|
|
|
|
{
|
|
|
|
clients: [],
|
2019-12-18 09:06:20 +00:00
|
|
|
getDataToSave() {
|
|
|
|
return {
|
|
|
|
newUser: "",
|
|
|
|
newHash: "",
|
|
|
|
};
|
|
|
|
},
|
2019-10-31 09:24:19 +00:00
|
|
|
},
|
|
|
|
"test",
|
|
|
|
{
|
|
|
|
clientSettings: {highlights: "foo, @all, sp ace , 고"},
|
|
|
|
}
|
|
|
|
);
|
2019-10-23 09:42:01 +00:00
|
|
|
|
|
|
|
log.info.restore();
|
|
|
|
expect(userLoadedLog).to.equal("User test loaded\n");
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should NOT highlight", function () {
|
2019-02-19 14:21:54 +00:00
|
|
|
const teststrings = [
|
|
|
|
"and foos stuff",
|
|
|
|
"test foobar",
|
|
|
|
"testfoo bar",
|
|
|
|
"fooö",
|
|
|
|
"wtf@all",
|
|
|
|
"foo고",
|
|
|
|
"test고",
|
|
|
|
"space",
|
|
|
|
"sp:ace",
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const teststring of teststrings) {
|
|
|
|
expect(teststring).to.not.match(client.highlightRegex);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should highlight", function () {
|
2019-02-19 14:21:54 +00:00
|
|
|
const teststrings = [
|
|
|
|
"Hey foo hello",
|
|
|
|
"hey Foo: hi",
|
|
|
|
"hey Foo, hi",
|
|
|
|
"<foo> testing",
|
|
|
|
"foo",
|
|
|
|
"hey @all test",
|
|
|
|
"testing foo's stuff",
|
2019-07-17 09:33:59 +00:00
|
|
|
'"foo"',
|
|
|
|
'"@all"',
|
2019-02-19 14:21:54 +00:00
|
|
|
"foo!",
|
|
|
|
"www.foo.bar",
|
|
|
|
"www.bar.foo/page",
|
|
|
|
"고",
|
|
|
|
"test 고",
|
|
|
|
"고!",
|
|
|
|
"www.고.com",
|
|
|
|
"hey @Foo",
|
|
|
|
"hey ~Foo",
|
|
|
|
"hey +Foo",
|
|
|
|
"hello &foo",
|
|
|
|
"@all",
|
|
|
|
"@all wtf",
|
|
|
|
"wtf @all",
|
|
|
|
"@@all",
|
|
|
|
"@고",
|
|
|
|
"f00 sp ace: bar",
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const teststring of teststrings) {
|
|
|
|
expect(teststring).to.match(client.highlightRegex);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should trim custom highlights in the compiled regex", function () {
|
2019-02-19 14:21:54 +00:00
|
|
|
expect(client.highlightRegex).to.match(/\(\?:foo\|@all\|sp ace\|고\)/);
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should NOT compile a regex", function () {
|
2019-02-19 14:21:54 +00:00
|
|
|
// test updating the regex and invalid custom hl inputs
|
|
|
|
client.config.clientSettings.highlights = ",,";
|
|
|
|
client.compileCustomHighlights();
|
|
|
|
expect(client.highlightRegex).to.be.null;
|
|
|
|
|
|
|
|
client.config.clientSettings.highlights = " ";
|
|
|
|
client.compileCustomHighlights();
|
|
|
|
expect(client.highlightRegex).to.be.null;
|
|
|
|
});
|
|
|
|
});
|