| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Dart test program for the "is" type test operator. | 4 // Dart test program for the "is" type test operator. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 testTryCatch(x) { | 8 testTryCatch(x) { |
| 9 try { | 9 try { |
| 10 throw x; | 10 throw x; |
| 11 Expect.fail("Exception '$x' should've been thrown"); | 11 Expect.fail("Exception '$x' should've been thrown"); |
| 12 } on Object catch (obj) { | 12 } on Object catch (obj) { |
| 13 Expect.equals(obj, x); | 13 Expect.equals(obj, x); |
| 14 } | 14 } |
| 15 } | 15 } |
| 16 | 16 |
| 17 main() { | 17 main() { |
| 18 var evalCount = 0; | 18 var evalCount = 0; |
| 19 testEval(x) { evalCount++; return x; } | 19 testEval(x) { |
| 20 evalCount++; |
| 21 return x; |
| 22 } |
| 20 | 23 |
| 21 // Test that types that match JS primitive types compare correctly to Object | 24 // Test that types that match JS primitive types compare correctly to Object |
| 22 var x = 1; | 25 var x = 1; |
| 23 Expect.isTrue(x is Object); | 26 Expect.isTrue(x is Object); |
| 24 x = 'hi'; | 27 x = 'hi'; |
| 25 Expect.isTrue(x is Object); | 28 Expect.isTrue(x is Object); |
| 26 x = true; | 29 x = true; |
| 27 Expect.isTrue(x is Object); | 30 Expect.isTrue(x is Object); |
| 28 x = null; | 31 x = null; |
| 29 Expect.isTrue(x is Object); | 32 Expect.isTrue(x is Object); |
| 30 var y; | 33 var y; |
| 31 Expect.isTrue(y is Object); | 34 Expect.isTrue(y is Object); |
| 32 | 35 |
| 33 // Verify that operand is evaluated | 36 // Verify that operand is evaluated |
| 34 Expect.isTrue(testEval(123) is Object); | 37 Expect.isTrue(testEval(123) is Object); |
| 35 Expect.equals(1, evalCount); | 38 Expect.equals(1, evalCount); |
| 36 Expect.isTrue(testEval('world') is Object); | 39 Expect.isTrue(testEval('world') is Object); |
| 37 Expect.equals(2, evalCount); | 40 Expect.equals(2, evalCount); |
| 38 Expect.isTrue(testEval(false) is Object); | 41 Expect.isTrue(testEval(false) is Object); |
| 39 Expect.equals(3, evalCount); | 42 Expect.equals(3, evalCount); |
| 40 Expect.isTrue(testEval(null) is Object); | 43 Expect.isTrue(testEval(null) is Object); |
| 41 Expect.equals(4, evalCount); | 44 Expect.equals(4, evalCount); |
| 42 | 45 |
| 43 // Verify that these objects are catchable | 46 // Verify that these objects are catchable |
| 44 testTryCatch(444); | 47 testTryCatch(444); |
| 45 testTryCatch('abc'); | 48 testTryCatch('abc'); |
| 46 testTryCatch(true); | 49 testTryCatch(true); |
| 47 } | 50 } |
| OLD | NEW |