summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/String.raw.js
blob: 6a4e172b73be1c3edd9f940afc98acc1baf02b29 (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
load("test-common.js")

try {
    let str = String.raw`foo\nbar`;
    assert(str.length === 8 && str === "foo\\nbar");

    str = String.raw`foo ${1 + 9}\nbar${"hf!"}`;
    assert(str === "foo 10\\nbarhf!");

    str = String.raw`${10}${20}${30}`;
    assert(str === "102030");

    str = String.raw({ raw: ["foo ", "\\nbar"] }, 10, "hf!");
    assert(str === "foo 10\\nbar");

    str = String.raw({ raw: ["foo ", "\\nbar"] });
    assert(str === "foo \\nbar");

    str = String.raw({ raw: [] }, 10, "hf!");
    assert(str === "");

    str = String.raw({ raw: 1 });
    assert(str === "");

    assertThrowsError(() => {
        String.raw({});
    }, {
        error: TypeError,
        message: "Cannot convert property 'raw' to object from undefined",
    });

    console.log("PASS");
} catch (e) {
    console.log("FAIL: " + e);
}