2017-03-18 08:18:47 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const expect = require("chai").expect;
|
|
|
|
const parseStyle = require("../../../../../../client/js/libs/handlebars/ircmessageparser/parseStyle");
|
|
|
|
|
|
|
|
describe("parseStyle", () => {
|
|
|
|
it("should skip control codes", () => {
|
|
|
|
const input = "text\x01with\x04control\x05codes";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "textwithcontrolcodes",
|
|
|
|
|
|
|
|
start: 0,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 20,
|
2017-03-18 08:18:47 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse bold", () => {
|
|
|
|
const input = "\x02bold";
|
|
|
|
const expected = [{
|
|
|
|
bold: true,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "bold",
|
|
|
|
|
|
|
|
start: 0,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 4,
|
2017-03-18 08:18:47 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
2017-12-03 02:52:49 +00:00
|
|
|
it("should parse strikethrough", () => {
|
|
|
|
const input = "\x1estrikethrough text\x1e";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: true,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
text: "strikethrough text",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 18,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
2017-12-03 15:00:35 +00:00
|
|
|
it("should parse monospace", () => {
|
|
|
|
const input = "\x11monospace text\x1e";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: true,
|
|
|
|
text: "monospace text",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 14,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should toggle monospace correctly", () => {
|
|
|
|
const input = "toggling \x11on and \x11off and \x11on again\x11";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "toggling ",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 9,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: true,
|
|
|
|
text: "on and ",
|
|
|
|
|
|
|
|
start: 9,
|
|
|
|
end: 16,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "off and ",
|
|
|
|
|
|
|
|
start: 16,
|
|
|
|
end: 24,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: true,
|
|
|
|
text: "on again",
|
|
|
|
|
|
|
|
start: 24,
|
|
|
|
end: 32,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse monospace and underline", () => {
|
|
|
|
const input = "\x1funderline formatting \x11with monospace\x1f no underline \x11 and vanilla";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: true,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "underline formatting ",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 21,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: true,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: true,
|
|
|
|
text: "with monospace",
|
|
|
|
|
|
|
|
start: 21,
|
|
|
|
end: 35,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: true,
|
|
|
|
text: " no underline ",
|
|
|
|
|
|
|
|
start: 35,
|
|
|
|
end: 49,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: " and vanilla",
|
|
|
|
|
|
|
|
start: 49,
|
|
|
|
end: 61,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse monospace and text colors", () => {
|
|
|
|
const input = "\x037,9\x11text with color and monospace\x11\x03";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: 7,
|
|
|
|
bgColor: 9,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: true,
|
|
|
|
text: "text with color and monospace",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 29,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
2017-12-03 02:52:49 +00:00
|
|
|
it("should parse strikethrough and italics", () => {
|
|
|
|
const input = "\x1ditalic formatting \x1ewith strikethrough\x1d no italic \x1e and vanilla";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: true,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
text: "italic formatting ",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 18,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: true,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: true,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
text: "with strikethrough",
|
|
|
|
|
|
|
|
start: 18,
|
|
|
|
end: 36,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: true,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
text: " no italic ",
|
|
|
|
|
|
|
|
start: 36,
|
|
|
|
end: 47,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
text: " and vanilla",
|
|
|
|
|
|
|
|
start: 47,
|
|
|
|
end: 59,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse strikethrough and text colors", () => {
|
|
|
|
const input = "\x031,2text with color \x1eand strikethrough\x1e\x03";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: 1,
|
|
|
|
bgColor: 2,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
text: "text with color ",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 16,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: 1,
|
|
|
|
bgColor: 2,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: true,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
text: "and strikethrough",
|
|
|
|
|
|
|
|
start: 16,
|
|
|
|
end: 33,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should correctly parse multiple unclosed format tokens", () => {
|
|
|
|
const input = "\x1e\x02\x1d\x033,4string with multiple unclosed formats";
|
|
|
|
const expected = [{
|
|
|
|
bold: true,
|
|
|
|
textColor: 3,
|
|
|
|
bgColor: 4,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: true,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: true,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
text: "string with multiple unclosed formats",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 37,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should toggle strikethrough correctly", () => {
|
|
|
|
const input = "toggling \x1eon and \x1eoff and \x1eon again\x1e";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
text: "toggling ",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 9,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: true,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
text: "on and ",
|
|
|
|
|
|
|
|
start: 9,
|
|
|
|
end: 16,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
text: "off and ",
|
|
|
|
|
|
|
|
start: 16,
|
|
|
|
end: 24,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: true,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
text: "on again",
|
|
|
|
|
|
|
|
start: 24,
|
|
|
|
end: 32,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
2017-03-18 08:18:47 +00:00
|
|
|
it("should parse textColor", () => {
|
|
|
|
const input = "\x038yellowText";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: 8,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "yellowText",
|
|
|
|
|
|
|
|
start: 0,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 10,
|
2017-03-18 08:18:47 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse textColor and background", () => {
|
|
|
|
const input = "\x034,8yellowBG redText";
|
|
|
|
const expected = [{
|
|
|
|
textColor: 4,
|
|
|
|
bgColor: 8,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
bold: false,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "yellowBG redText",
|
|
|
|
|
|
|
|
start: 0,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 16,
|
2017-03-18 08:18:47 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse italic", () => {
|
|
|
|
const input = "\x1ditalic";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: true,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "italic",
|
|
|
|
|
|
|
|
start: 0,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 6,
|
2017-03-18 08:18:47 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
2017-04-28 05:28:45 +00:00
|
|
|
it("should parse hex colors", () => {
|
|
|
|
const input = "test \x04FFFFFFnice \x02\x04RES006 \x0303,04\x04ff00FFcolored\x04eeeaFF,001122 background\x04\x03\x02?";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-04-28 05:28:45 +00:00
|
|
|
text: "test ",
|
|
|
|
|
|
|
|
start: 0,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 5,
|
2017-04-28 05:28:45 +00:00
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: "FFFFFF",
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-04-28 05:28:45 +00:00
|
|
|
text: "nice ",
|
|
|
|
|
|
|
|
start: 5,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 10,
|
2017-04-28 05:28:45 +00:00
|
|
|
}, {
|
|
|
|
bold: true,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-04-28 05:28:45 +00:00
|
|
|
text: "RES006 ",
|
|
|
|
|
|
|
|
start: 10,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 17,
|
2017-04-28 05:28:45 +00:00
|
|
|
}, {
|
|
|
|
bold: true,
|
|
|
|
textColor: 3,
|
|
|
|
bgColor: 4,
|
|
|
|
hexColor: "FF00FF",
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-04-28 05:28:45 +00:00
|
|
|
text: "colored",
|
|
|
|
|
|
|
|
start: 17,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 24,
|
2017-04-28 05:28:45 +00:00
|
|
|
}, {
|
|
|
|
bold: true,
|
|
|
|
textColor: 3,
|
|
|
|
bgColor: 4,
|
|
|
|
hexColor: "EEEAFF",
|
|
|
|
hexBgColor: "001122",
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-04-28 05:28:45 +00:00
|
|
|
text: " background",
|
|
|
|
|
|
|
|
start: 24,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 35,
|
2017-04-28 05:28:45 +00:00
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-04-28 05:28:45 +00:00
|
|
|
text: "?",
|
|
|
|
|
|
|
|
start: 35,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 36,
|
2017-04-28 05:28:45 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
2017-12-04 21:12:37 +00:00
|
|
|
it("should reverse and format color", () => {
|
|
|
|
const input = "\x032,9text with fg and bg \x16with text reversed";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: 2,
|
|
|
|
bgColor: 9,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "text with fg and bg ",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 20,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: 9,
|
|
|
|
bgColor: 2,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "with text reversed",
|
|
|
|
|
|
|
|
start: 20,
|
|
|
|
end: 38,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should toggle reverse correctly", () => {
|
|
|
|
const input = "\x0305,11text \x16reversed and \x16back again and \x16reversed";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: 5,
|
|
|
|
bgColor: 11,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "text ",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 5,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: 11,
|
|
|
|
bgColor: 5,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "reversed and ",
|
|
|
|
|
|
|
|
start: 5,
|
|
|
|
end: 18,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: 5,
|
|
|
|
bgColor: 11,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "back again and ",
|
|
|
|
|
|
|
|
start: 18,
|
|
|
|
end: 33,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: 11,
|
|
|
|
bgColor: 5,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "reversed",
|
|
|
|
|
|
|
|
start: 33,
|
|
|
|
end: 41,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should escape reverse when a new style is applied", () => {
|
|
|
|
const input = "\x0311,02text \x16 reversed \x0304,05 and new style";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: 11,
|
|
|
|
bgColor: 2,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "text ",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 5,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: 2,
|
|
|
|
bgColor: 11,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: " reversed ",
|
|
|
|
|
|
|
|
start: 5,
|
|
|
|
end: 15,
|
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: 4,
|
|
|
|
bgColor: 5,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: " and new style",
|
|
|
|
|
|
|
|
start: 15,
|
|
|
|
end: 29,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not reverse if color is specified after reverse tag", () => {
|
|
|
|
const input = "\x16\x032,9text with fg and bg";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: 2,
|
|
|
|
bgColor: 9,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "text with fg and bg",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 19,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should reverse, bold, and italics", () => {
|
|
|
|
const input = "\x034,13\x16\x02some text with \x1ditalics";
|
|
|
|
const expected = [{
|
|
|
|
bold: true,
|
|
|
|
textColor: 13,
|
|
|
|
bgColor: 4,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: false,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "some text with ",
|
|
|
|
|
|
|
|
start: 0,
|
|
|
|
end: 15,
|
|
|
|
}, {
|
|
|
|
bold: true,
|
|
|
|
textColor: 13,
|
|
|
|
bgColor: 4,
|
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
|
|
|
italic: true,
|
|
|
|
underline: false,
|
|
|
|
strikethrough: false,
|
|
|
|
monospace: false,
|
|
|
|
text: "italics",
|
|
|
|
|
|
|
|
start: 15,
|
|
|
|
end: 22,
|
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
2017-08-25 15:58:16 +00:00
|
|
|
it("should carry state correctly forward", () => {
|
2017-03-18 08:18:47 +00:00
|
|
|
const input = "\x02bold\x038yellow\x02nonBold\x03default";
|
|
|
|
const expected = [{
|
|
|
|
bold: true,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "bold",
|
|
|
|
|
|
|
|
start: 0,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 4,
|
2017-03-18 08:18:47 +00:00
|
|
|
}, {
|
|
|
|
bold: true,
|
|
|
|
textColor: 8,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "yellow",
|
|
|
|
|
|
|
|
start: 4,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 10,
|
2017-03-18 08:18:47 +00:00
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: 8,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "nonBold",
|
|
|
|
|
|
|
|
start: 10,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 17,
|
2017-03-18 08:18:47 +00:00
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "default",
|
|
|
|
|
|
|
|
start: 17,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 24,
|
2017-03-18 08:18:47 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should toggle bold correctly", () => {
|
|
|
|
const input = "\x02bold\x02 \x02bold\x02";
|
|
|
|
const expected = [{
|
|
|
|
bold: true,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "bold",
|
|
|
|
|
|
|
|
start: 0,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 4,
|
2017-03-18 08:18:47 +00:00
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: " ",
|
|
|
|
|
|
|
|
start: 4,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 5,
|
2017-03-18 08:18:47 +00:00
|
|
|
}, {
|
|
|
|
bold: true,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "bold",
|
|
|
|
|
|
|
|
start: 5,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 9,
|
2017-03-18 08:18:47 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should reset all styles", () => {
|
2017-12-03 15:00:35 +00:00
|
|
|
const input = "\x11\x1e\x02\x034\x16\x1d\x1ffull\x0fnone";
|
2017-03-18 08:18:47 +00:00
|
|
|
const expected = [{
|
|
|
|
bold: true,
|
2017-12-04 21:12:37 +00:00
|
|
|
textColor: undefined,
|
|
|
|
bgColor: 4, // \x16: fg- and bg- are reversed
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: true,
|
|
|
|
underline: true,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: true,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: true,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "full",
|
|
|
|
|
|
|
|
start: 0,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 4,
|
2017-03-18 08:18:47 +00:00
|
|
|
}, {
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "none",
|
|
|
|
|
|
|
|
start: 4,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 8,
|
2017-03-18 08:18:47 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not emit empty fragments", () => {
|
|
|
|
const input = "\x031\x031,2\x031\x031,2\x031\x031,2\x03a";
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: undefined,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: "a",
|
|
|
|
|
|
|
|
start: 0,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: 1,
|
2017-03-18 08:18:47 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should optimize fragments", () => {
|
|
|
|
const rawString = "oh hi test text";
|
|
|
|
const colorCode = "\x0312";
|
|
|
|
const input = colorCode + rawString.split("").join(colorCode);
|
|
|
|
const expected = [{
|
|
|
|
bold: false,
|
|
|
|
textColor: 12,
|
|
|
|
bgColor: undefined,
|
2017-04-28 05:28:45 +00:00
|
|
|
hexColor: undefined,
|
|
|
|
hexBgColor: undefined,
|
2017-03-18 08:18:47 +00:00
|
|
|
italic: false,
|
|
|
|
underline: false,
|
2017-12-03 02:52:49 +00:00
|
|
|
strikethrough: false,
|
2017-12-03 15:00:35 +00:00
|
|
|
monospace: false,
|
2017-03-18 08:18:47 +00:00
|
|
|
text: rawString,
|
|
|
|
|
|
|
|
start: 0,
|
2017-11-15 06:35:15 +00:00
|
|
|
end: rawString.length,
|
2017-03-18 08:18:47 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
const actual = parseStyle(input);
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
});
|
|
|
|
});
|