2 var s
= "this is a string";
6 var o
= { prop1
: 1, prop2
: 2 };
12 "0.3f": "float with precision",
18 var functions
= ["log", "debug"];
19 for (var i
= 0; i
< functions
.length
; ++i
) {
20 console
.info("console." + functions
[i
] + "(%s)", args
);
22 eval("console." + functions
[i
] + "(" + args
+ ")");
29 function testAllSpecifiers(value
, description
) {
30 for (var specifier
in specifiers
)
31 test("'Format " + description
+ " as " + specifiers
[specifier
] + ": %" + specifier
+ "', " + value
+ "");
36 { value
: "window.noSuchVariable", description
: "undefined" },
37 { value
: "s", description
: "string" },
38 { value
: "i", description
: "positive integer" },
39 { value
: "ni", description
: "negative integer" },
40 { value
: "f", description
: "float" },
41 { value
: "o", description
: "object" },
42 { value
: "document.body", description
: "body" },
43 { value
: "/test/", description
: "RegExp" },
44 { value
: "true", description
: "boolean" },
45 { value
: "null", description
: "null" },
48 for (var i
= 0; i
< values
.length
; ++i
)
49 testAllSpecifiers(values
[i
].value
, values
[i
].description
);
53 "'multiple', 'parameters', 'should', 'be', 'concatenated'",
55 "document, document.body, window, window.location",
56 "document, document.body, 'hello', 'goodbye', window.location",
57 "'Format string with fewer specifiers than parameters: %o %i %f', document.body, i, f, ni, o",
58 "'Format string with more specifiers than parameters: %o %i %f %i %o', document.body, i, f",
61 for (var i
= 0; i
< tests
.length
; ++i
)
66 <p>Test for
<a href=
"https://bugs.webkit.org/show_bug.cgi?id=17228">Bug
17228: console.{log,warn,info,error} should support format strings, variable arguments
</a>.
</p>
67 <p>Open the Inspector (right-click and choose
"Inspect Element"), then click the
"Run Tests" button.
</p>
68 <button onclick=
"runTests()">Run Tests
</button>