Report number of passed and failed tests
[voodoo-lang.git] / test / auto-words.voo
blobee7f5705146ab6f8d194cbd6763d53816cb931f0
1 #### Test program for auto-words
3 section data
5 print_word_space_fmt:
6 string "%d \x00"
8 print_int_fmt:
9 string "%d\n\x00"
11 section functions
12 export main
13 import printf
15 align
16 print_words:
17 function words n
18     # Prints n words.
19     let max sub n 1
20     let i 0
21     let x 0
22 print_words_loop:
23     iflt i max
24         set x get-word words i
25         call printf print_word_space_fmt x
26         set i add i 1
27         goto print_words_loop
28     end if
29     set x get-word words max
30     call printf print_int_fmt x
31     return 0        
32 end function
34 align
35 test:
36 function
37     let words auto-words 17
38     let i 0
39 test_loop:
40     iflt i 17
41         set-word words i i
42         set i add i 1
43         goto test_loop
44     end if
45     call print_words words 17
46     call test_pass words
48     block
49         let a 42
50         let more-words auto-words 19
51         let b 0
52         let c 72
53 test_loop1:
54         iflt b 19
55             set-word more-words b c
56             set b add b 1
57             set c add c 1
58             goto test_loop1
59         end if
60         call print_words more-words 19
61         call printf print_int_fmt a
62         call printf print_int_fmt b
63         call printf print_int_fmt c
64     end block
66     call printf print_int_fmt i
67     call print_words words 17
69     # Allocate memory in a block inside a loop. The memory
70     # should be freed on each iteration, so this should not
71     # run out of memory.
72     set i 0
73 test_loop2:
74     iflt i 262144
75         block
76             set words auto-words 16384
77         end block
78         set i add i 1
79         goto test_loop2
80     end if
82     return 0
83 end function
85 align
86 test_pass:
87 function text
88     call print_words text 17
89     let words auto-words 4
90     set-word words 0 48
91     set-word words 1 49
92     set-word words 2 50
93     set-word words 3 0
94     call print_words words 4
95     return 0
96 end function
98 align
99 main:
100 function argc argv
101     call test
102     return 0
103 end function