|
| 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 |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | +// Dart test program for testing static const fields. |
| 5 | + |
| 6 | +import "package:expect/expect.dart"; |
| 7 | + |
| 8 | +abstract class Spain { |
| 9 | + static const AG = "Antoni Gaudi"; |
| 10 | + static const SD = "Salvador Dali"; |
| 11 | +} |
| 12 | + |
| 13 | +abstract class Switzerland { |
| 14 | + static const AG = "Alberto Giacometti"; |
| 15 | + static const LC = "Le Corbusier"; |
| 16 | +} |
| 17 | + |
| 18 | +class A implements Switzerland { |
| 19 | + const A() : n = 5; |
| 20 | + final n; |
| 21 | + static const a = const A(); |
| 22 | + static const b = 3 + 5; |
| 23 | + static const c = A.b + 7; |
| 24 | + static const d = const A(); |
| 25 | + static const s1 = "hula"; |
| 26 | + static const s2 = "hula"; |
| 27 | + static const s3 = "hop"; |
| 28 | + static const d1 = 1.1; |
| 29 | + static const d2 = 0.55 + 0.55; |
| 30 | + static const artist2 = Switzerland.AG; |
| 31 | + static const architect1 = Spain.AG; |
| 32 | + static const array1 = const <int>[1, 2]; |
| 33 | + static const map1 = const { |
| 34 | + "Monday": 1, |
| 35 | + "Tuesday": 2, |
| 36 | + }; |
| 37 | +} |
| 38 | + |
| 39 | +class StaticFinalFieldTest { |
| 40 | + static testMain() { |
| 41 | + Expect.equals(15, A.c); |
| 42 | + Expect.equals(8, A.b); |
| 43 | + Expect.equals(5, A.a.n); |
| 44 | + Expect.equals(true, identical(8, A.b)); |
| 45 | + Expect.equals(true, identical(A.a, A.d)); |
| 46 | + Expect.equals(true, identical(A.s1, A.s2)); |
| 47 | + Expect.equals(false, identical(A.s1, A.s3)); |
| 48 | + Expect.equals(false, identical(A.s1, A.b)); |
| 49 | + Expect.equals(true, identical(A.d1, A.d2)); |
| 50 | + Expect.equals(true, Spain.SD == "Salvador Dali"); |
| 51 | + Expect.equals(true, A.artist2 == "Alberto Giacometti"); |
| 52 | + Expect.equals(true, A.architect1 == "Antoni Gaudi"); |
| 53 | + Expect.equals(2, A.map1["Tuesday"]); |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +main() { |
| 58 | + StaticFinalFieldTest.testMain(); |
| 59 | +} |
0 commit comments