summaryrefslogtreecommitdiffstats
path: root/comm/chat/protocols/irc/test/test_ctcpDequote.js
blob: 1a1e7fcc9dc802b6a73e08b9015d27066f130b11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

var { CTCPMessage } = ChromeUtils.importESModule(
  "resource:///modules/ircCTCP.sys.mjs"
);

var input = [
  "ACTION",
  "ACTION test",
  "ACTION \x5Ctest",
  "ACTION te\x5Cst",
  "ACTION test\x5C",
  "ACTION \x5C\x5Ctest",
  "ACTION te\x5C\x5Cst",
  "ACTION test\x5C\x5C",
  "ACTION \x5C\x5C\x5Ctest",
  "ACTION te\x5C\x5C\x5Cst",
  "ACTION test\x5C\x5C\x5C",
  "ACTION \x5Catest",
  "ACTION te\x5Cast",
  "ACTION test\x5Ca",
  "ACTION \x5C\x5C\x5Catest",
  "ACTION \x5C\x5Catest",
];

var expectedOutputParam = [
  "",
  "test",
  "test",
  "test",
  "test",
  "\x5Ctest",
  "te\x5Cst",
  "test\x5C",
  "\x5Ctest",
  "te\x5Cst",
  "test\x5C",
  "\x01test",
  "te\x01st",
  "test\x01",
  "\x5C\x01test",
  "\x5Catest",
];

function run_test() {
  let output = input.map(aStr => CTCPMessage({}, aStr));
  // Ensure both arrays have the same length.
  equal(expectedOutputParam.length, output.length);
  // Ensure the values in the arrays are equal.
  for (let i = 0; i < output.length; ++i) {
    equal(expectedOutputParam[i], output[i].ctcp.param);
    equal("ACTION", output[i].ctcp.command);
  }
}