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

Side by Side Diff: test/webkit/comparison-operators-less.js

Issue 18068003: Migrated several tests from blink to V8 repository. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions
6 // are met:
7 // 1. Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // 2. Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 //
13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
24 description("test that comparison operators work correctly.")
25
26 function makeTest(start, end, expression, relationship, override, invert) {
27 var resultValue = eval(relationship + expression + 0) || !!override;
28 if (invert)
29 resultValue = !resultValue;
30 var expr = start + expression + end;
31 var result = [];
32 function func(content) { var f = new Function(content); f.toString = functio n(){ return content}; return f; }
33 result.push([new func("return " + expr + ";"), resultValue]);
34 result.push([new func("if (" + expr + ") return true; return false;"), resul tValue]);
35 result.push([new func("var k = 0; while (" + expr + ") if (k++) return true; return false;"), resultValue]);
36 result.push([new func("var k = 0; for (; " + expr + "; ) if (k++) return tru e; return false;"), resultValue]);
37 return result;
38 }
39 function doTest(lhs, rhs, relationship) {
40 var expressionParts = [["(",")"],["(", ") || 1", true],["(", ") && 1"],["(", ") || 1", true],["1 || (",")", true],["1 && (",")"]];
41 var expressions = [];
42 var tests = [];
43 for (var i = 0; i < expressionParts.length; i++) {
44 var start = expressionParts[i][0] + lhs;
45 var end = String(rhs) + expressionParts[i][1];
46 tests.push.apply(tests, makeTest(start, end, "<", relationship, expressi onParts[i][2]));
47 tests.push.apply(tests, makeTest(start, end, "<=", relationship, express ionParts[i][2]));
48 }
49 for (var i = 0; i < tests.length; i++) {
50 if ((r=tests[i][0]()) == tests[i][1])
51 testPassed(tests[i][0] + " is " + tests[i][1]);
52 else
53 testFailed(tests[i][0] + " is " + r + " and should be " + tests[i][1 ] + ".");
54 }
55 }
56
57 var letterA = "a";
58 var letterB = "b";
59 var letter0 = "0";
60 var One = 1;
61 var Zero = 0;
62 doTest('"a"', '"b"', -1);
63 doTest('"a"', '"a"', 0);
64 doTest('"b"', '"a"', 1);
65 doTest('letterA', '"b"', -1);
66 doTest('letterA', '"a"', 0);
67 doTest('"b"', '"a"', 1);
68 doTest('letterA', '"b"', -1);
69 doTest('letterA', 'letterA', 0);
70 doTest('"b"', 'letterA', 1);
71 doTest('"a"', '"b"', -1);
72 doTest('"a"', 'letterA', 0);
73 doTest('"b"', 'letterA', 1);
74
75 doTest('"a"', '0', NaN);
76 doTest('0', '"a"', NaN);
77 doTest('letterA', '0', NaN);
78 doTest('letterA', '"a"', 0);
79 doTest('0', '"a"', NaN);
80 doTest('letterA', 'letterA', 0);
81 doTest('0', 'letterA', NaN);
82 doTest('"a"', 'letterA', 0);
83 doTest('0', 'letterA', NaN);
84
85
86 doTest('0', '"0"', 0);
87 doTest('Zero', 'letter0', 0);
88 doTest('0', 'letter0', 0);
89 doTest('Zero', '"0"', 0);
90 doTest('-1', '"0"', -1);
91 doTest('1', '"0"', 1);
92 doTest('0', '"-1"', 1);
93 doTest('0', '"1"', -1);
94
95 doTest('0', '1', -1);
96 doTest('0', '0', 0);
97 doTest('1', '0', 1);
98 doTest('Zero', '1', -1);
99 doTest('Zero', '0', 0);
100 doTest('1', 'Zero', 1);
101 doTest('0', 'One', -1);
102 doTest('One', '0', 1);
103
104 shouldBeTrue("0 <= 0");
105 shouldBeTrue("0 <= 1");
106 shouldBeTrue("1 <= 1");
107 shouldBeTrue("0 < 1");
108 shouldBeFalse("1 <= 0");
109 shouldBeFalse("2 <= 1");
110 shouldBeFalse("1 < 1");
111 shouldBeFalse("2 < 1");
112
113 shouldBeTrue("if (0 <= 0 || 0) true; else false");
114 shouldBeTrue("if (0 <= 1 || 0) true; else false");
115 shouldBeTrue("if (1 <= 1 || 0) true; else false");
116 shouldBeTrue("if (0 < 1 || 0) true; else false");
117 shouldBeFalse("if (1 <= 0 || 0) true; else false");
118 shouldBeFalse("if (2 <= 1 || 0) true; else false");
119 shouldBeFalse("if (1 < 1 || 0) true; else false");
120 shouldBeFalse("if (2 < 1 || 0) true; else false");
121
122 shouldBeTrue("0 <= 0.5");
123 shouldBeTrue("0 <= 1.5");
124 shouldBeTrue("1 <= 1.5");
125 shouldBeTrue("0 < 1.5");
126 shouldBeFalse("1 <= 0.5");
127 shouldBeFalse("2 <= 1.5");
128 shouldBeTrue("1 < 1.5");
129 shouldBeFalse("2 < 1.5");
130
131 shouldBeTrue("if (0 <= 0.5 || 0) true; else false");
132 shouldBeTrue("if (0 <= 1.5 || 0) true; else false");
133 shouldBeTrue("if (1 <= 1.5 || 0) true; else false");
134 shouldBeTrue("if (0 < 1.5 || 0) true; else false");
135 shouldBeFalse("if (1 <= 0.5 || 0) true; else false");
136 shouldBeFalse("if (2 <= 1.5 || 0) true; else false");
137 shouldBeTrue("if (1 < 1.5 || 0) true; else false");
138 shouldBeFalse("if (2 < 1.5 || 0) true; else false");
139
140 var zero = 0;
141 var one = 1;
142 var two = 2;
143 var p5 = 0.5;
144 var p15 = 1.5;
145
146
147 shouldBeTrue("zero <= zero");
148 shouldBeTrue("zero <= 1");
149 shouldBeTrue("1 <= 1");
150 shouldBeTrue("zero < 1");
151 shouldBeFalse("1 <= zero");
152 shouldBeFalse("2 <= 1");
153 shouldBeFalse("1 < 1");
154 shouldBeFalse("2 < 1");
155
156 shouldBeTrue("if (zero <= zero || 0) true; else false");
157 shouldBeTrue("if (zero <= 1 || zero) true; else false");
158 shouldBeTrue("if (1 <= 1 || zero) true; else false");
159 shouldBeTrue("if (zero < 1 || zero) true; else false");
160 shouldBeFalse("if (1 <= zero || zero) true; else false");
161 shouldBeFalse("if (2 <= 1 || zero) true; else false");
162 shouldBeFalse("if (1 < 1 || zero) true; else false");
163 shouldBeFalse("if (2 < 1 || zero) true; else false");
164
165 shouldBeTrue("0 <= p5");
166 shouldBeTrue("0 <= p15");
167 shouldBeTrue("1 <= p15");
168 shouldBeTrue("0 < p15");
169 shouldBeFalse("1 <= p5");
170 shouldBeFalse("2 <= p15");
171 shouldBeTrue("1 < p15");
172 shouldBeFalse("2 < p15");
173
174 shouldBeTrue("if (0 <= p5 || 0) true; else false");
175 shouldBeTrue("if (0 <= p15 || 0) true; else false");
176 shouldBeTrue("if (1 <= p15 || 0) true; else false");
177 shouldBeTrue("if (0 < p15 || 0) true; else false");
178 shouldBeFalse("if (1 <= p5 || 0) true; else false");
179 shouldBeFalse("if (2 <= p15 || 0) true; else false");
180 shouldBeTrue("if (1 < p15 || 0) true; else false");
181 shouldBeFalse("if (2 < p15 || 0) true; else false");
182
183
184 shouldBeTrue("zero <= zero");
185 shouldBeTrue("zero <= one");
186 shouldBeTrue("one <= one");
187 shouldBeTrue("zero < one");
188 shouldBeFalse("one <= zero");
189 shouldBeFalse("two <= one");
190 shouldBeFalse("one < one");
191 shouldBeFalse("two < one");
192
193 shouldBeTrue("if (zero <= zero || 0) true; else false");
194 shouldBeTrue("if (zero <= one || zero) true; else false");
195 shouldBeTrue("if (one <= one || zero) true; else false");
196 shouldBeTrue("if (zero < one || zero) true; else false");
197 shouldBeFalse("if (one <= zero || zero) true; else false");
198 shouldBeFalse("if (two <= one || zero) true; else false");
199 shouldBeFalse("if (one < one || zero) true; else false");
200 shouldBeFalse("if (two < one || zero) true; else false");
201
202 shouldBeTrue("0 <= p5");
203 shouldBeTrue("0 <= p15");
204 shouldBeTrue("one <= p15");
205 shouldBeTrue("0 < p15");
206 shouldBeFalse("one <= p5");
207 shouldBeFalse("two <= p15");
208 shouldBeTrue("one < p15");
209 shouldBeFalse("two < p15");
210
211 shouldBeTrue("if (0 <= p5 || 0) true; else false");
212 shouldBeTrue("if (0 <= p15 || 0) true; else false");
213 shouldBeTrue("if (one <= p15 || 0) true; else false");
214 shouldBeTrue("if (0 < p15 || 0) true; else false");
215 shouldBeFalse("if (one <= p5 || 0) true; else false");
216 shouldBeFalse("if (two <= p15 || 0) true; else false");
217 shouldBeTrue("if (one < p15 || 0) true; else false");
218 shouldBeFalse("if (two < p15 || 0) true; else false");
219
220
221 shouldBeFalse(" 0 < NaN");
222 shouldBeFalse(" NaN < NaN");
223 shouldBeFalse(" 0 <= NaN");
224 shouldBeFalse(" NaN <= NaN");
225 shouldBeFalse(" 0.5 < NaN");
226 shouldBeFalse(" NaN < NaN");
227 shouldBeFalse(" 0.5 <= NaN");
228 shouldBeFalse(" NaN <= NaN");
229 shouldBeFalse(" zero < NaN");
230 shouldBeFalse("zero <= NaN");
231 shouldBeFalse(" NaN <= NaN");
232 shouldBeFalse(" p5 < NaN");
233 shouldBeFalse("NaN < NaN");
234 shouldBeFalse("p5 <= NaN");
235 shouldBeFalse("NaN <= NaN");
236
237
238 shouldBeFalse("if ( 0 < NaN) true; else false;");
239 shouldBeFalse("if ( NaN < NaN) true; else false;");
240 shouldBeFalse("if ( 0 <= NaN) true; else false;");
241 shouldBeFalse("if ( NaN <= NaN) true; else false;");
242 shouldBeFalse("if ( 0.5 < NaN) true; else false;");
243 shouldBeFalse("if ( NaN < NaN) true; else false;");
244 shouldBeFalse("if ( 0.5 <= NaN) true; else false;");
245 shouldBeFalse("if ( NaN <= NaN) true; else false;");
246 shouldBeFalse("if ( zero < NaN) true; else false;");
247 shouldBeFalse("if (zero <= NaN) true; else false;");
248 shouldBeFalse("if ( NaN <= NaN) true; else false;");
249 shouldBeFalse("if ( p5 < NaN) true; else false;");
250 shouldBeFalse("if (NaN < NaN) true; else false;");
251 shouldBeFalse("if (p5 <= NaN) true; else false;");
252 shouldBeFalse("if (NaN <= NaN) true; else false;");
OLDNEW
« no previous file with comments | « test/webkit/comparison-operators-greater-expected.txt ('k') | test/webkit/comparison-operators-less-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698