]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/string-raw.js
1 function shouldBe(actual
, expected
) {
2 if (actual
!== expected
)
3 throw new Error(`bad value: ${actual}`);
6 function shouldThrow(func
, errorMessage
) {
7 var errorThrown
= false;
16 throw new Error('not thrown');
17 if (String(error
) !== errorMessage
)
18 throw new Error(`bad error: ${String(error)}`);
21 shouldBe(String
.raw
.name
, 'raw');
22 shouldBe(String
.raw
.length
, 1);
24 shouldThrow(function () {
26 }, "TypeError: String.raw requires template not be null or undefined");
28 shouldThrow(function () {
29 String
.raw(undefined);
30 }, "TypeError: String.raw requires template not be null or undefined");
32 shouldThrow(function () {
33 String
.raw({ raw: undefined });
34 }, "TypeError: String.raw requires template.raw not be null or undefined");
36 shouldThrow(function () {
37 String
.raw({ raw: null });
38 }, "TypeError: String.raw requires template.raw not be null or undefined");
40 shouldThrow(function () {
43 return new Error('template.length called');
48 throw new Error("template.raw.length called");
52 }, "Error: template.raw.length called");
84 function generateTemplate() {
86 cooked
.raw
= Array
.from(arguments
);
90 shouldBe(String
.raw(generateTemplate("", ",", ",", ""), "Cocoa", "Cappuccino", "Matcha"), "Cocoa,Cappuccino,Matcha");
91 shouldBe(String
.raw(generateTemplate("", ",", ",", ""), "Cocoa", "Cappuccino", "Matcha", "Hello"), "Cocoa,Cappuccino,Matcha");
92 shouldBe(String
.raw(generateTemplate("", ",", ",", ""), "Cocoa", "Cappuccino"), "Cocoa,Cappuccino,");
93 shouldBe(String
.raw(generateTemplate("", ",", ",", ""), "Cocoa"), "Cocoa,,");
94 shouldBe(String
.raw(generateTemplate("", ",", ",", "")), ",,");
105 var counter
= Counter();
106 shouldBe(String
.raw(generateTemplate(counter
, counter
, counter
, counter
)), "0123");
107 var counter
= Counter();
108 shouldBe(String
.raw(generateTemplate(counter
, counter
, counter
, counter
), counter
), "01234");
109 var counter
= Counter();
110 shouldBe(String
.raw(generateTemplate(counter
, counter
, counter
, counter
), counter
, counter
), "012345");
111 var counter
= Counter();
112 shouldBe(String
.raw(generateTemplate(counter
, counter
, counter
, counter
), counter
, counter
, counter
), "0123456");
113 var counter
= Counter();
114 shouldBe(String
.raw(generateTemplate(counter
, counter
, counter
, counter
), counter
, counter
, counter
, counter
), "0123456");
115 var counter
= Counter();
116 shouldBe(String
.raw(generateTemplate(counter
, counter
, counter
, counter
), counter
, counter
, counter
, counter
), "0123456");
117 var counter
= Counter();
118 shouldBe(String
.raw(generateTemplate(counter
, counter
, counter
, counter
), counter
, counter
, counter
, counter
, counter
), "0123456");
121 shouldBe(String
.raw({
128 }, "d", "e", "f", "g"), "adbec");
130 shouldBe(String
.raw({
137 }, "d", "e", "f", "g"), "adb");
139 shouldBe(String
.raw({
145 }, "d", "e", "f", "g"), "adundefined");
147 shouldBe(String
.raw({
154 }, undefined, "e", "f", "g"), "aundefinedb");