Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.ruby.test/src/com/oracle/truffle/ruby/test/language/MultipleAssignmentTests.java @ 13514:0fbee3eb71f0
Ruby: import project.
author | Chris Seaton <chris.seaton@oracle.com> |
---|---|
date | Mon, 06 Jan 2014 17:12:09 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13513:64a23ce736a0 | 13514:0fbee3eb71f0 |
---|---|
1 /* | |
2 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. This | |
3 * code is released under a tri EPL/GPL/LGPL license. You can use it, | |
4 * redistribute it and/or modify it under the terms of the: | |
5 * | |
6 * Eclipse Public License version 1.0 | |
7 * GNU General Public License version 2 | |
8 * GNU Lesser General Public License version 2.1 | |
9 */ | |
10 package com.oracle.truffle.ruby.test.language; | |
11 | |
12 import org.junit.*; | |
13 | |
14 import com.oracle.truffle.ruby.test.*; | |
15 | |
16 /** | |
17 * Test multiple assignment, which is sort of like pattern matching for arrays. The arrays can be | |
18 * implicit on the RHS. | |
19 */ | |
20 public class MultipleAssignmentTests extends RubyTests { | |
21 | |
22 @Test | |
23 public void testToLocal() { | |
24 assertPrints("1\n2\n", "x, y = [1, 2]; puts x, y"); | |
25 assertPrints("1\n2\n", "x, y = 1, 2; puts x, y"); | |
26 assertPrints("1\n2\n", "x = [1, 2]; y, z = x; puts y, z"); | |
27 } | |
28 | |
29 @Test | |
30 public void testToArrayIndex() { | |
31 assertPrints("1\n2\n", "x = []; x[0], x[1] = 1, 2; puts x"); | |
32 } | |
33 | |
34 @Test | |
35 public void testSwap() { | |
36 assertPrints("2\n1\n", "a = [1]; b = [2]; a[0], b[0] = b[0], a[0]; puts a, b"); | |
37 } | |
38 | |
39 @Test | |
40 public void testProducesArray() { | |
41 assertPrints("1\n2\n", "puts((a, b = 1, 2))"); | |
42 } | |
43 | |
44 @Test | |
45 public void testWithSplat() { | |
46 assertPrints("1\n[2, 3]\n", "a, *b = [1, 2, 3]; puts a; puts b.to_s"); | |
47 } | |
48 | |
49 @Test | |
50 public void testWithSplatEmpty() { | |
51 assertPrints("1\n[]\n", "a, *b = [1]; puts a.to_s; puts b.to_s"); | |
52 } | |
53 | |
54 @Test | |
55 public void testWithSingleValueRHS() { | |
56 assertPrints("14\n\n\n", "a, b, c = 14; puts a; puts b; puts c"); | |
57 assertPrints("\n\n\n", "a, b, c = nil; puts a; puts b; puts c"); | |
58 } | |
59 | |
60 @Test | |
61 public void testWithSingleSplatLHSAndSingleValueRHS() { | |
62 assertPrints("[14]\n", "a = *14; puts a.to_s"); | |
63 } | |
64 | |
65 } |