Chromium Code Reviews| Index: tests/language/rewrite_swap.dart |
| diff --git a/tests/language/rewrite_swap.dart b/tests/language/rewrite_swap.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8633df68c01cea0a84deac30c0cfd2e9b824643e |
| --- /dev/null |
| +++ b/tests/language/rewrite_swap.dart |
| @@ -0,0 +1,68 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import "package:expect/expect.dart"; |
| + |
| +swap1(x,y,b) { |
| + if (b) { |
| + var t = x; |
| + x = y; |
| + y = t; |
| + } |
| + Expect.equals(2, x); |
| + Expect.equals(1, y); |
| +} |
| + |
| +swap2(x,y,z,w,b) { |
| + if (b) { |
| + var t = x; |
| + x = y; |
| + y = t; |
| + |
| + var q = z; |
| + z = w; |
| + w = q; |
| + } |
| + Expect.equals(2, x); |
| + Expect.equals(1, y); |
| + Expect.equals(4, z); |
| + Expect.equals(3, w); |
| +} |
| + |
| +swap3(x,y,z,b) { |
| + if (b) { |
| + var t = x; |
| + x = y; |
| + y = z; |
| + z = t; |
| + } |
| + Expect.equals(2, x); |
| + Expect.equals(3, y); |
| + Expect.equals(1, z); |
| +} |
| + |
| +swap4(x,y,z,b) { |
| + if (b) { |
| + var t = x; |
| + x = y; |
| + y = z; // swap cycle involves unused variable 'y' |
| + z = t; |
| + } |
| + Expect.equals(2, x); |
| + Expect.equals(1, z); |
| +} |
| + |
| +main() { |
| + swap1(1,2,true); |
| + swap1(2,1,false); |
| + |
| + swap2(1,2,3,4,true); |
| + swap2(2,1,4,3,false); |
| + |
| + swap3(1,2,3,true); |
| + swap3(2,3,1,false); |
| + |
| + swap4(1,2,3,true); |
| + swap4(2,3,1,false); |
| +} |