File: arraytest.5c

package info (click to toggle)
nickle 2.107
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 3,756 kB
  • sloc: ansic: 27,954; yacc: 1,874; lex: 954; sh: 204; makefile: 13; lisp: 1
file content (30 lines) | stat: -rw-r--r-- 844 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* Make sure array initalizers work as expected */

void check (poly value, poly correct)
{
    if (is_number (value) && !is_rational (value))
    {
	real	error = abs (value - correct);
	if (error < abs(value) / 1e7)
	    return;
    }
    if (value != correct)
	abort ("check failed (was %v, should be %v)", value, correct);
}

check (([10]) { 1, 2, ... }[9], 2);
check (([*,*]) { { 1, 2, ...}, { 3, 4, 5, 6}} [0,3], 2);
check (([*,*,*]) { { { 1, 2, 3 } ... }, { { 4, 5, 6}, {7, 8, 9}, {10, 11, 12}}}[0,1,2], 3);
check (([10]) { [i] = i ** 2 + 1 }[9], 82);

/* These should all generate compile errors, but shouldn't crash */
file save_stderr = stderr;
stderr = File::open("/dev/null", "w");
([*,*]) { { [i] = i ** 2 + 1 }, { 4, 5, 6, 7, 8 }};
([*]) { 1 ... };
([*,*]) {1};
int[*,*] x = {1};
int[] x = {{1},2};
stderr = save_stderr;

exit(0);