summaryrefslogtreecommitdiff
path: root/jstests/core/regex_util.js
blob: 86ba8036516ed0315ef42a8a70e162316a8850d7 (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
// Tests for RegExp.escape

(function() {
  var TEST_STRINGS = [
    "[db]",
    "{ab}",
    "<c2>",
    "(abc)",
    "^first^",
    "&addr",
    "k@10gen.com",
    "#4",
    "!b",
    "<>3",
    "****word+",
    "\t| |\n\r",
    "Mongo-db",
    "[{(<>)}]!@#%^&*+\\"
  ];

  TEST_STRINGS.forEach(function (str) {
    var escaped = RegExp.escape(str);
    var regex = new RegExp(escaped);
    assert(regex.test(str), "Wrong escape for " + str);
  });
})();