summaryrefslogtreecommitdiff
path: root/jstests/core/regex_util.js
blob: b0c7791b6c1008aca174609972b0579b9faecf56 (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
// 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);
    });
})();