source: src/tests/tupleAssign.c @ 4782b39

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 4782b39 was a29be37, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

add a few test cases for tuples

  • Property mode set to 100644
File size: 1.1 KB
Line 
1int main() {
2        {
3                // test multiple assignment and cascading assignment
4                int u = 5, v = 6, x = 10, y = 11;
5                [int, int] z = [100, 200];
6
7                // swap x, y and store the new [x, y] in [u, v] and in z;
8                printf("u=%d v=%d x=%d y=%d z=[%d, %d]\n", u, v, x, y, z);
9                z = [u, v] = [x, y] = [y, x];
10                printf("u=%d v=%d x=%d y=%d z=[%d, %d]\n", u, v, x, y, z);
11
12                // shuffle elements -- v = z.0, z.0 = z.1, z.1 = u, u = v
13                [v, z, u] = [z, u, v];
14                printf("u=%d v=%d z=[%d, %d]\n", u, v, z);
15
16                // multiple assignment with tuple expression on right
17                z = [111, 222];
18                [u, v] = [123, 456];
19                printf("u=%d v=%d z=[%d, %d]\n", u, v, z);
20        }
21
22        {
23                // test mass assignment
24                double d = 0.0;
25                int i = 0;
26                char c = '\0';
27                struct X {
28                        int z;
29                } x;
30                X ?=?(X * x, double d) {}
31                [int, double, int] t;
32
33                // no conversion from X to integral types, so this serves as a santiy
34                // check that as long as this compiles, ?=?(_, x) is not generated.
35                [t, x, d, i, c, x] = (double)-2153.12;
36                printf("d=%lg i=%d c=%d t=[%d, %lg, %d]\n", d, i, (int)c, t);
37                [x, c, i, d, x, t] = (double)-2153.12;
38                printf("d=%lg i=%d c=%d t=[%d, %lg, %d]\n", d, i, (int)c, t);
39        }
40}
Note: See TracBrowser for help on using the repository browser.