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

Side by Side Diff: test/preparser/duplicate-property.pyt

Issue 7168016: Add duplicate parameter detection to preparser. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Update to tip of bleeding_edge Created 9 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « test/preparser/duplicate-parameter.pyt ('k') | test/preparser/testcfg.py » ('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 # Tests of duplicate properties in object literals.
29
30 # ----------------------------------------------------------------------
31 # Utility functions to generate a number of tests for each property
32 # name pair.
33
34 def PropertyTest(name, propa, propb):
35 replacement = {"id1": propa, "id2": propb, "name": name}
36
37 def StrictTest(name, source, replacement, expectation):
38 Template("strict-" + name,
39 "\"use strict\";\n" + source)(replacement, expectation)
40 Template(name, source)(replacement, expectation)
41
42 Template("strict-$name-data-data", """
43 "use strict";
44 var o = {$id1: 42, $id2: 42};
45 """)(replacement, "strict_duplicate_property")
46
47 Template("$name-data-data", """
48 var o = {$id1: 42, $id2: 42};
49 """)(replacement, None)
50
51 StrictTest("$name-data-get", """
52 var o = {$id1: 42, get $id2(){}};
53 """, replacement, "accessor_data_property")
54
55 StrictTest("$name-data-set", """
56 var o = {$id1: 42, set $id2(v){}};
57 """, replacement, "accessor_data_property")
58
59 StrictTest("$name-get-data", """
60 var o = {get $id1(){}, $id2: 42};
61 """, replacement, "accessor_data_property")
62
63 StrictTest("$name-set-data", """
64 var o = {set $id1(v){}, $id2: 42};
65 """, replacement, "accessor_data_property")
66
67 StrictTest("$name-get-get", """
68 var o = {get $id1(){}, get $id2(){}};
69 """, replacement, "accessor_get_set")
70
71 StrictTest("$name-set-set", """
72 var o = {set $id1(v){}, set $id2(v){}};
73 """, replacement, "accessor_get_set")
74
75 StrictTest("$name-nested-get", """
76 var o = {get $id1(){}, o: {get $id2(){} } };
77 """, replacement, None)
78
79 StrictTest("$name-nested-set", """
80 var o = {set $id1(){}, o: {set $id2(){} } };
81 """, replacement, None)
82
83
84 def TestBothWays(name, propa, propb):
85 PropertyTest(name + "-1", propa, propb)
86 PropertyTest(name + "-2", propb, propa)
87
88 def TestSame(name, prop):
89 PropertyTest(name, prop, prop)
90
91 #-----------------------------------------------------------------------
92
93 # Simple identifier property
94 TestSame("a", "a")
95
96 # Get/set identifiers
97 TestSame("get-id", "get")
98 TestSame("set-id", "set")
99
100 # Number properties
101 TestSame("0", "0")
102 TestSame("0.1", "0.1")
103 TestSame("1.0", "1.0")
104 TestSame("42.33", "42.33")
105 TestSame("2^32-2", "4294967294")
106 TestSame("2^32", "4294967296")
107 TestSame("2^53", "9007199254740992")
108 TestSame("Hex20", "0x20")
109 TestSame("exp10", "1e10")
110 TestSame("exp20", "1e20")
111
112 # String properties
113 TestSame("str-a", '"a"')
114 TestSame("str-0", '"0"')
115 TestSame("str-42", '"42"')
116 TestSame("str-empty", '""')
117
118 # Keywords
119 TestSame("if", "if")
120 TestSame("case", "case")
121
122 # Future reserved keywords
123 TestSame("public", "public")
124 TestSame("class", "class")
125
126
127 # Test that numbers are converted to string correctly.
128
129 TestBothWays("hex-int", "0x20", "32")
130 TestBothWays("dec-int", "32.00", "32")
131 TestBothWays("dec-underflow-int",
132 "32.00000000000000000000000000000000000000001", "32")
133 TestBothWays("exp-int", "3.2e1", "32")
134 TestBothWays("exp-int", "3200e-2", "32")
135 TestBothWays("overflow-inf", "1e2000", "Infinity")
136 TestBothWays("underflow-0", "1e-2000", "0")
137 TestBothWays("precission-loss-high", "9007199254740992", "9007199254740993")
138 TestBothWays("precission-loss-low", "1.9999999999999998", "1.9999999999999997")
139
140 TestBothWays("hex-int-str", "0x20", '"32"')
141 TestBothWays("dec-int-str", "32.00", '"32"')
142 TestBothWays("exp-int-str", "3.2e1", '"32"')
143 TestBothWays("overflow-inf-str", "1e2000", '"Infinity"')
144 TestBothWays("underflow-0-str", "1e-2000", '"0"')
OLDNEW
« no previous file with comments | « test/preparser/duplicate-parameter.pyt ('k') | test/preparser/testcfg.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698