| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 // Dart test program for testing setting/getting/initializing static fields. | |
| 5 | |
| 6 class First { | |
| 7 First() {} | |
| 8 static var a; | |
| 9 static var b; | |
| 10 static final int c = 1; | |
| 11 static setValues() { | |
| 12 a = 24; | |
| 13 b = 10; | |
| 14 return a + b + c; | |
| 15 } | |
| 16 } | |
| 17 | |
| 18 | |
| 19 class InitializerTest { | |
| 20 static var one; | |
| 21 static var two = 2; | |
| 22 static var three = 2; | |
| 23 | |
| 24 static checkValueOfThree() { | |
| 25 // We need to keep this check separate to prevent three from | |
| 26 // getting initialized before the += is executed. | |
| 27 Expect.equals(3, three); | |
| 28 } | |
| 29 | |
| 30 static void testStaticFieldInitialization() { | |
| 31 Expect.equals(null, one); | |
| 32 Expect.equals(2, two); | |
| 33 one = 11; | |
| 34 two = 22; | |
| 35 Expect.equals(11, one); | |
| 36 Expect.equals(22, two); | |
| 37 | |
| 38 // Assignment operators exercise a different code path. Make sure | |
| 39 // that initialization works here as well. | |
| 40 three += 1; | |
| 41 checkValueOfThree(); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 | |
| 46 class StaticFieldTest { | |
| 47 static testMain() { | |
| 48 First.a = 3; | |
| 49 First.b = First.a; | |
| 50 Expect.equals(3, First.a); | |
| 51 Expect.equals(First.a, First.b); | |
| 52 First.b = (First.a = 10); | |
| 53 Expect.equals(10, First.a); | |
| 54 Expect.equals(10, First.b); | |
| 55 First.b = First.a = 15; | |
| 56 Expect.equals(15, First.a); | |
| 57 Expect.equals(15, First.b); | |
| 58 Expect.equals(35, First.setValues()); | |
| 59 Expect.equals(24, First.a); | |
| 60 Expect.equals(10, First.b); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 | |
| 65 main() { | |
| 66 StaticFieldTest.testMain(); | |
| 67 InitializerTest.testStaticFieldInitialization(); | |
| 68 } | |
| OLD | NEW |