File: is_type.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 (29 lines) | stat: -rw-r--r-- 973 bytes parent folder | download | duplicates (8)
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
int errors = 0;

void check (poly value, string type, bool got, bool want) {
    if (got != want) {
	printf ("is_type(%v, %s) = %v. should be %v\n",
		value, type, got, want);
	errors++;
    }
}

typedef struct { string a; } super_type;
typedef super_type + struct { string b; } sub_type;
super_type super_value = { .a = "a value" };
sub_type sub_value = { .a = "a value", .b = "b value" };

check(super_value, "super_type", is_type(super_value, super_type), true);
check(super_value, "sub_type", is_type (super_value, sub_type), false);
check(sub_value, "super_type", is_type (sub_value, super_type), true);
check(sub_value, "sub_type", is_type (sub_value, sub_type), true);

real real_value = pi;
real int_value = 12;

check(real_value, "real", is_type (real_value, real), true);
check(real_value, "int", is_type (real_value, int), false);
check(int_value, "real", is_type (int_value, real), true);
check(int_value, "int", is_type(int_value, int), true);

exit (errors);