thelounge/test/client/js/helpers/ircmessageparser/findChannels.js

143 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-03-18 09:18:47 +01:00
"use strict";
const expect = require("chai").expect;
2022-02-10 00:27:34 +01:00
const findChannels =
require("../../../../../client/js/helpers/ircmessageparser/findChannels").default;
2017-03-18 09:18:47 +01:00
describe("findChannels", () => {
it("should find single letter channel", () => {
const input = "#a";
2019-07-17 11:33:59 +02:00
const expected = [
{
channel: "#a",
start: 0,
end: 2,
},
];
2017-03-18 09:18:47 +01:00
const actual = findChannels(input, ["#"], ["@", "+"]);
2017-03-18 09:18:47 +01:00
expect(actual).to.deep.equal(expected);
});
it("should find utf8 channels", () => {
const input = "#äöü";
2019-07-17 11:33:59 +02:00
const expected = [
{
channel: "#äöü",
start: 0,
end: 4,
},
];
2017-03-18 09:18:47 +01:00
const actual = findChannels(input, ["#"], ["@", "+"]);
2017-03-18 09:18:47 +01:00
expect(actual).to.deep.equal(expected);
});
it("should find inline channel", () => {
const input = "inline #channel text";
2019-07-17 11:33:59 +02:00
const expected = [
{
channel: "#channel",
start: 7,
end: 15,
},
];
2017-03-18 09:18:47 +01:00
const actual = findChannels(input, ["#"], ["@", "+"]);
2017-03-18 09:18:47 +01:00
expect(actual).to.deep.equal(expected);
});
it("should stop at \\0x07", () => {
const input = "#chan\x07nel";
2019-07-17 11:33:59 +02:00
const expected = [
{
channel: "#chan",
start: 0,
end: 5,
},
];
2017-03-18 09:18:47 +01:00
const actual = findChannels(input, ["#"], ["@", "+"]);
2017-03-18 09:18:47 +01:00
expect(actual).to.deep.equal(expected);
});
it("should allow classics pranks", () => {
const input = "#1,000";
2019-07-17 11:33:59 +02:00
const expected = [
{
channel: "#1,000",
start: 0,
end: 6,
},
];
2017-03-18 09:18:47 +01:00
const actual = findChannels(input, ["#"], ["@", "+"]);
2017-03-18 09:18:47 +01:00
expect(actual).to.deep.equal(expected);
});
2017-08-25 17:58:16 +02:00
it("should work with whois responses", () => {
2017-03-18 09:18:47 +01:00
const input = "@#a";
2019-07-17 11:33:59 +02:00
const expected = [
{
channel: "#a",
start: 1,
end: 3,
},
];
2017-03-18 09:18:47 +01:00
const actual = findChannels(input, ["#"], ["@", "+"]);
2017-03-18 09:18:47 +01:00
expect(actual).to.deep.equal(expected);
});
it("should work with IRCv3.1 multi-prefix", () => {
const input = "!@%+#a";
2019-07-17 11:33:59 +02:00
const expected = [
{
channel: "#a",
start: 4,
end: 6,
},
];
2017-03-18 09:18:47 +01:00
const actual = findChannels(input, ["#"], ["!", "@", "%", "+"]);
2017-03-18 09:18:47 +01:00
expect(actual).to.deep.equal(expected);
});
it("should work with custom channelPrefixes", () => {
const input = "@a";
2019-07-17 11:33:59 +02:00
const expected = [
{
channel: "@a",
start: 0,
end: 2,
},
];
2017-03-18 09:18:47 +01:00
const actual = findChannels(input, ["@"], ["#", "+"]);
2017-03-18 09:18:47 +01:00
expect(actual).to.deep.equal(expected);
});
it("should handle multiple channelPrefix correctly", () => {
const input = "##test";
2019-07-17 11:33:59 +02:00
const expected = [
{
channel: "##test",
start: 0,
end: 6,
},
];
2017-03-18 09:18:47 +01:00
const actual = findChannels(input, ["#"], ["@", "+"]);
2017-03-18 09:18:47 +01:00
expect(actual).to.deep.equal(expected);
});
});