initial import
[vuplus_webkit] / Source / WebCore / manual-tests / inspector / console-log-formatting.html
1 <script>
2     var s = "this is a string";
3     var i = 5;
4     var ni = -5;
5     var f = 3.14159;
6     var o = { prop1: 1, prop2: 2 };
7     var specifiers = {
8         s: "string",
9         i: "integer",
10         d: "integer",
11         f: "float",
12         "0.3f": "float with precision",
13         o: "object",
14         z: "unsupported",
15     };
16
17     function test(args) {
18         var functions = ["log", "debug"];
19         for (var i = 0; i < functions.length; ++i) {
20             console.info("console." + functions[i] + "(%s)", args);
21             try {
22                 eval("console." + functions[i] + "(" + args + ")");
23             } catch (e) {
24                 console.error(e);
25             }
26         }
27     }
28
29     function testAllSpecifiers(value, description) {
30         for (var specifier in specifiers)
31             test("'Format " + description + " as " + specifiers[specifier] + ": %" + specifier + "', " + value + "");
32     }
33
34     function runTests() {
35         var values = [
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" },
46         ];
47
48         for (var i = 0; i < values.length; ++i)
49             testAllSpecifiers(values[i].value, values[i].description);
50
51         var tests = [
52             "'simple test'",
53             "'multiple', 'parameters', 'should', 'be', 'concatenated'",
54             "document",
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",
59         ];
60
61         for (var i = 0; i < tests.length; ++i)
62             test(tests[i]);
63
64     }
65 </script>
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>