Web Inspector: Breakpoint Log action should support template literals
[WebKit-https.git] / LayoutTests / inspector / unit-tests / breakpoint-log-message-lexer.html
1 <!doctype html>
2 <html>
3 <head>
4 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
5 <script src="resources/script-for-breakpoint-actions.js"></script>
6 <script>
7 function runBreakpointActions()
8 {
9     breakpointActions(42, {x:1, y:2});
10 }
11
12 function test()
13 {
14     let suite = InspectorTest.createSyncSuite("Debugger.BreakpointLogMessageLexer");
15
16     function addTestCase({name, input, expectedTokens}) {
17         suite.addTestCase({
18             name,
19             test() {
20                 let lexer = new WebInspector.BreakpointLogMessageLexer;
21                 let tokens = lexer.tokenize(input);
22                 InspectorTest.log("Input: " + input);
23                 InspectorTest.expectShallowEqual(tokens, expectedTokens, "Token stream should match expected tokens.");
24                 return true;
25             }
26         });
27     }
28
29     addTestCase({
30         name: "EmptyMessage",
31         input: "",
32         expectedTokens: []
33     });
34
35     addTestCase({
36         name: "TextOnly",
37         input: "hello world",
38         expectedTokens: [
39             {
40                 type: WebInspector.BreakpointLogMessageLexer.TokenType.PlainText,
41                 data: "hello world",
42             }
43         ]
44     });
45
46     addTestCase({
47         name: "PlaceholderOnly",
48         input: "${x}",
49         expectedTokens: [
50             {
51                 type: WebInspector.BreakpointLogMessageLexer.TokenType.Expression,
52                 data: "x",
53             }
54         ]
55     });
56
57     addTestCase({
58         name: "NestedTemplateLiteral",
59         input: "${'x' + `${'y'}`}",
60         expectedTokens: [
61             {
62                 type: WebInspector.BreakpointLogMessageLexer.TokenType.Expression,
63                 data: "'x' + `${'y'}`",
64             }
65         ]
66     });
67
68     addTestCase({
69         name: "TextBeforePlaceholder",
70         input: "abc ${x}",
71         expectedTokens: [
72             {
73                 type: WebInspector.BreakpointLogMessageLexer.TokenType.PlainText,
74                 data: "abc ",
75             },
76             {
77                 type: WebInspector.BreakpointLogMessageLexer.TokenType.Expression,
78                 data: "x",
79             },
80         ]
81     });
82
83     addTestCase({
84         name: "TextAfterPlaceholder",
85         input: "${x} abc",
86         expectedTokens: [
87             {
88                 type: WebInspector.BreakpointLogMessageLexer.TokenType.Expression,
89                 data: "x",
90             },
91             {
92                 type: WebInspector.BreakpointLogMessageLexer.TokenType.PlainText,
93                 data: " abc",
94             },
95         ]
96     });
97
98     addTestCase({
99         name: "PlaceholderWithNestedBraces",
100         input: "${({a: '${}'}).a}",
101         expectedTokens: [
102             {
103                 type: WebInspector.BreakpointLogMessageLexer.TokenType.Expression,
104                 data: "({a: '${}'}).a",
105             }
106         ]
107     });
108
109     addTestCase({
110         name: "PlaceholderWithRegExpLiteral",
111         input: "${/\\}/.test('${')}",
112         expectedTokens: [
113             {
114                 type: WebInspector.BreakpointLogMessageLexer.TokenType.Expression,
115                 data: "/\\}/.test('${')",
116             }
117         ]
118     });
119
120     addTestCase({
121         name: "MultiplePlaceholders",
122         input: "${1} ${2}",
123         expectedTokens: [
124             {
125                 type: WebInspector.BreakpointLogMessageLexer.TokenType.Expression,
126                 data: "1",
127             },
128             {
129                 type: WebInspector.BreakpointLogMessageLexer.TokenType.PlainText,
130                 data: " ",
131             },
132             {
133                 type: WebInspector.BreakpointLogMessageLexer.TokenType.Expression,
134                 data: "2",
135             }
136         ]
137     });
138
139     addTestCase({
140         name: "ExpressionFollowedByBraces",
141         input: "${1}{2}",
142         expectedTokens: [
143             {
144                 type: WebInspector.BreakpointLogMessageLexer.TokenType.Expression,
145                 data: "1",
146             },
147             {
148                 type: WebInspector.BreakpointLogMessageLexer.TokenType.PlainText,
149                 data: "{2}",
150             },
151         ]
152     });
153
154     suite.runTestCasesAndFinish();
155 }
156 </script>
157 </head>
158 <body onload="runTest()">
159     <p>Check that BreakpointLogMessageLexer correctly tokenizes breakpoint action log messages. Message text can include template literal placeholders.</p>
160 </body>
161 </html>