aboutsummaryrefslogtreecommitdiffhomepage
path: root/libslang/src/test/anytype.sl
blob: 80af7dc8eeb5cbfbe60c4424ba7fc6e54c8aee7c (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
_debug_info = 1; () = evalfile ("inc.sl");

print ("Testing Any_Type ...");

% Tests go here....

variable A = Any_Type[10];
if ((_typeof(A)) != Any_Type) failed ("_typeof");

static define eqs (a, b)
{
   variable len;
   len = length (a);
   if (len != length (b))
     return 0;
   
   len == length (where (a == b));
}

static define neqs (a, b)
{
   not (eqs (a, b));
}

static define check (a, i, value)
{
   a[i] = value;
   if (typeof (a[i]) != Any_Type)
     failed ("check typeof");
   % Because value can be an array, use neqs
   if (neqs(@a[i], value))
     failed ("a[i] = value for %S, computed: %S", value, @a[i]);
}

check (A, 0, "hello");
check (A, 0, 14);
#ifexists Double_Type
check (A, 0, 2.3);
#endif
check (A, 0, &A);
check (A, 0, [1:10]);
#ifexists Complex_Type
check (A, 0, 1+2i);
#endif
check (A, 0, String_Type);

A = ["a", "ab", "abc"];
static variable B = typecast (A, Any_Type);
if ((typeof (B) != Array_Type)
    or (_typeof(B) != Any_Type))
  failed ("typecast to Any_Type");
_for (0, length(B)-1, 1)
{
   $1 = ();
   if (A[$1] != @B[$1])
     failed ("@typecast(A,Any_Type)");
}

  
print ("Ok\n");

exit (0);