Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(905)

Side by Side Diff: test/preparser/strict-identifiers.pyt

Issue 7061008: Create template system for strict-mode tests. (Closed)
Patch Set: Remove debug print. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/preparser/strict-eval-var.js ('k') | test/preparser/strict-yield-argument.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2011 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are
4 # met:
5 #
6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided
11 # with the distribution.
12 # * Neither the name of Google Inc. nor the names of its
13 # contributors may be used to endorse or promote products derived
14 # from this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 # Templatated tests with eval/arguments/future reserved words.
29
30 # ----------------------------------------------------------------------
31 # Constants and utility functions
32
33 reserved_words = [
34 'class',
35 'const', # Has other error message than other reserved words.
36 'enum',
37 'export',
38 'extends',
39 'import',
40 'super'
41 ]
42
43 strict_reserved_words = [
44 'implements',
45 'interface',
46 'let',
47 'package',
48 'private',
49 'protected',
50 'public',
51 'static',
52 'yield'
53 ]
54
55 assign_ops = {
56 "=": "assign",
57 "+=": "addeq",
58 "-=": "subeq",
59 "*=": "muleq",
60 "/=": "diveq",
61 "%=": "modeq",
62 "&=": "andeq",
63 "|=": "oreq",
64 "^=": "xoreq",
65 "<<=": "shleq",
66 ">>=": "asreq",
67 ">>>=": "lsreq"
68 }
69
70
71 # A template that performs the same strict-mode test in different
72 # scopes (global scope, function scope, and nested function scope).
73 def StrictTemplate(name, source):
74 def MakeTests(replacement, expectation):
75 Template(name, '"use strict";\n' + source)(replacement, expectation)
76 Template(name + '-infunc',
77 'function foo() {\n "use strict";\n' + source +'\n}\n')(
78 replacement, expectation)
79 Template(name + '-infunc2',
80 'function foo() {\n "use strict";\n function bar() {\n' +
81 source +'\n }\n}\n')(replacement, expectation)
82 return MakeTests
83
84 # ----------------------------------------------------------------------
85 # Test templates
86
87 arg_name_own = Template("argument-name-own-$id", """
88 function foo($id) {
89 "use strict";
90 }
91 """)
92
93 arg_name_nested = Template("argument-name-nested-$id", """
94 function foo() {
95 "use strict";
96 function bar($id) { }
97 }
98 """)
99
100 func_name_own = Template("function-name-own-$id", """
101 function $id(foo) {
102 "use strict";
103 }
104 """)
105
106 func_name_nested = Template("function-name-nested-$id", """
107 function foo() {
108 "use strict";
109 function $id(bar) { }
110 }
111 """)
112
113 catch_var = StrictTemplate("catch-$id", """
114 try { } catch ($id) { }
115 """)
116
117 declare_var = StrictTemplate("var-$id", """
118 var $id = 42;
119 """)
120
121 assign_var = StrictTemplate("assign-$id-$opname", """
122 var x = $id $op 42;
123 """)
124
125 prefix_var = StrictTemplate("prefix-$opname-$id", """
126 var x = $op$id;
127 """)
128
129 postfix_var = StrictTemplate("postfix-$opname-$id", """
130 var x = $id$op;
131 """)
132
133 read_var = StrictTemplate("read-reserved-$id", """
134 var x = $id;
135 """)
136
137 non_strict_use = Template("nonstrict-$id", """
138 var $id = 42;
139 $id++;
140 $id--;
141 ++$id;
142 --$id;
143 $id += 10;
144 $id -= 10;
145 try {} catch ($id) { }
146 function $id($id) { }
147 function foo() { "use strict;" }
148 var $id = 42;
149 $id++;
150 $id--;
151 ++$id;
152 --$id;
153 $id += 10;
154 $id -= 10;
155 try {} catch ($id) { }
156 function $id($id) { }
157 """)
158
159 # ----------------------------------------------------------------------
160 # Run tests
161
162 # eval and arguments have specific exceptions for different uses.
163 for id in ["eval", "arguments"]:
164 arg_name_own({"id": id}, "strict_param_name")
165 arg_name_nested({"id": id}, "strict_param_name")
166 func_name_own({"id": id}, "strict_function_name")
167 func_name_nested({"id": id}, "strict_function_name")
168 for op in assign_ops.keys():
169 assign_var({"id": id, "op":op, "opname": assign_ops[op]},
170 "strict_lhs_assignment")
171 catch_var({"id": id}, "strict_catch_variable")
172 declare_var({"id": id}, "strict_var_name")
173 prefix_var({"id": id, "op":"++", "opname":"inc"}, "strict_lhs_prefix")
174 prefix_var({"id": id, "op":"--", "opname":"dec"}, "strict_lhs_prefix")
175 postfix_var({"id": id, "op":"++", "opname":"inc"}, "strict_lhs_postfix")
176 postfix_var({"id": id, "op":"--", "opname":"dec"}, "strict_lhs_postfix")
177 non_strict_use({"id": id}, None)
178
179
180 # Reserved words just throw the same exception in all cases
181 # (with "const" being special, as usual).
182 for reserved_word in reserved_words + strict_reserved_words:
183 message = "strict_reserved_word"
184 if (reserved_word == "const"): message = "unexpected_token"
185 arg_name_own({"id":reserved_word}, message)
186 arg_name_nested({"id":reserved_word}, message)
187 func_name_own({"id":reserved_word}, message)
188 func_name_nested({"id":reserved_word}, message)
189 for op in assign_ops.keys():
190 assign_var({"id":reserved_word, "op":op, "opname": assign_ops[op]}, message)
191 catch_var({"id":reserved_word}, message)
192 declare_var({"id":reserved_word}, message)
193 prefix_var({"id":reserved_word, "op":"++", "opname":"inc"}, message)
194 prefix_var({"id":reserved_word, "op":"--", "opname":"dec"}, message)
195 postfix_var({"id":reserved_word, "op":"++", "opname":"inc"}, message)
196 postfix_var({"id":reserved_word, "op":"--", "opname":"dec"}, message)
197 read_var({"id": reserved_word}, message)
198
199
OLDNEW
« no previous file with comments | « test/preparser/strict-eval-var.js ('k') | test/preparser/strict-yield-argument.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698