| 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 // Check that arrays from final array literals are immutable. | 4 // Check that arrays from final array literals are immutable. |
| 5 | 5 |
| 6 class ListLiteral3Test { | 6 class ListLiteral3Test { |
| 7 | 7 |
| 8 static final List<String> canonicalJoke = const ["knock", "knock"]; | 8 static final List<String> canonicalJoke = const ["knock", "knock"]; |
| 9 | 9 |
| 10 static testMain() { | 10 static testMain() { |
| 11 | 11 |
| 12 List<String> joke = const ["knock", "knock"]; | 12 List<String> joke = const ["knock", "knock"]; |
| 13 // Elements of canonical lists are canonicalized. | 13 // Elements of canonical lists are canonicalized. |
| 14 Expect.equals(true, joke === canonicalJoke); | 14 Expect.equals(true, joke === canonicalJoke); |
| 15 Expect.equals(true, joke[0] === joke[1]); | 15 Expect.equals(true, joke[0] === joke[1]); |
| 16 Expect.equals(true, joke[0] === canonicalJoke[0]); | 16 Expect.equals(true, joke[0] === canonicalJoke[0]); |
| 17 | 17 |
| 18 // Lists from literals are immutable. | 18 // Lists from literals are immutable. |
| 19 bool caughtException = false; | 19 bool caughtException = false; |
| 20 try { | 20 try { |
| 21 joke[0] = "sock"; | 21 joke[0] = "sock"; |
| 22 } catch (UnsupportedOperationException e) { | 22 } catch (UnsupportedOperationException e) { |
| 23 caughtException = true; | 23 caughtException = true; |
| 24 } | 24 } |
| 25 Expect.equals(true, caughtException); |
| 25 Expect.equals(true, joke[0] === joke[1]); | 26 Expect.equals(true, joke[0] === joke[1]); |
| 26 Expect.equals(true, caughtException); | |
| 27 | 27 |
| 28 // Make sure lists allocated at runtime are mutable and are | 28 // Make sure lists allocated at runtime are mutable and are |
| 29 // not canonicalized. | 29 // not canonicalized. |
| 30 List<String> lame_joke = ["knock", "knock"]; // Invokes operator new. | 30 List<String> lame_joke = ["knock", "knock"]; // Invokes operator new. |
| 31 Expect.equals(true, joke[1] === lame_joke[1]); | 31 Expect.equals(true, joke[1] === lame_joke[1]); |
| 32 // Operator new creates a mutable list. | 32 // Operator new creates a mutable list. |
| 33 Expect.equals(false, joke === lame_joke); | 33 Expect.equals(false, joke === lame_joke); |
| 34 lame_joke[1] = "who"; | 34 lame_joke[1] = "who"; |
| 35 Expect.equals(true, "who" === lame_joke[1]); | 35 Expect.equals(true, "who" === lame_joke[1]); |
| 36 | 36 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 56 } catch (UnsupportedOperationException e) { | 56 } catch (UnsupportedOperationException e) { |
| 57 caughtException = true; | 57 caughtException = true; |
| 58 } | 58 } |
| 59 Expect.equals(true, caughtException); | 59 Expect.equals(true, caughtException); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 main() { | 63 main() { |
| 64 ListLiteral3Test.testMain(); | 64 ListLiteral3Test.testMain(); |
| 65 } | 65 } |
| OLD | NEW |