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 for testing access to private fields. | 4 // Dart test for testing access to private fields. |
5 | 5 |
6 main() { | 6 main() { |
7 PrivateMain.main(); | 7 PrivateMain.main(); |
8 } | 8 } |
9 | 9 |
10 class PrivateMain { | 10 class PrivateMain { |
11 | 11 |
12 static const _myPrecious = "A Ring"; | 12 static const _myPrecious = "A Ring"; |
13 | 13 |
14 static accessMyPrivates() { | 14 static accessMyPrivates() { |
15 var value = 0; | 15 var value = 0; |
16 try { | 16 try { |
17 value = _myPrecious; | 17 value = _myPrecious; |
18 } catch (var e) { | 18 } catch (e) { |
19 value = -1; | 19 value = -1; |
20 } | 20 } |
21 Expect.equals("A Ring", value); | 21 Expect.equals("A Ring", value); |
22 } | 22 } |
23 | 23 |
24 static accessMyLibPrivates() { | 24 static accessMyLibPrivates() { |
25 var value = 0; | 25 var value = 0; |
26 var the_other = new PrivateOther(); | 26 var the_other = new PrivateOther(); |
27 try { | 27 try { |
28 value = the_other._myPrecious; | 28 value = the_other._myPrecious; |
29 } catch (var e, var trace) { | 29 } catch (e, trace) { |
30 print(e); | 30 print(e); |
31 print(trace); | 31 print(trace); |
32 Expect.equals(true, e is NoSuchMethodException); | 32 Expect.equals(true, e is NoSuchMethodException); |
33 value = -1; | 33 value = -1; |
34 } | 34 } |
35 Expect.equals("Another Ring", value); | 35 Expect.equals("Another Ring", value); |
36 } | 36 } |
37 | 37 |
38 static accessOtherLibPrivates() { | 38 static accessOtherLibPrivates() { |
39 var value = 0; | 39 var value = 0; |
40 var the_other = new PrivateLib(); | 40 var the_other = new PrivateLib(); |
41 try { | 41 try { |
42 value = the_other._myPrecious; | 42 value = the_other._myPrecious; |
43 } catch (var e, var trace) { | 43 } catch (e, trace) { |
44 print(e); | 44 print(e); |
45 print(trace); | 45 print(trace); |
46 Expect.equals(true, e is NoSuchMethodException); | 46 Expect.equals(true, e is NoSuchMethodException); |
47 value = -1; | 47 value = -1; |
48 } | 48 } |
49 Expect.equals(-1, value); | 49 Expect.equals(-1, value); |
50 } | 50 } |
51 | 51 |
52 static main() { | 52 static main() { |
53 accessMyPrivates(); | 53 accessMyPrivates(); |
54 accessMyLibPrivates(); | 54 accessMyLibPrivates(); |
55 accessOtherLibPrivates(); | 55 accessOtherLibPrivates(); |
56 } | 56 } |
57 } | 57 } |
OLD | NEW |