]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/parser/parser-tests.factor
Update some copyright headers to follow the current convention
[factor.git] / basis / alien / parser / parser-tests.factor
1 ! Copyright (C) 2009 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types alien.parser alien.parser.private
4 alien.syntax compiler.units continuations debugger eval fry kernel
5 lexer namespaces parser sequences sets summary tools.test
6 vocabs.parser words ;
7 IN: alien.parser.tests
8
9 <<
10
11 : with-parsing ( lines quot -- )
12     [ <lexer> ] [ '[ _ with-compilation-unit ] ] bi* with-lexer ; inline
13
14 ! (CREATE-C-TYPE)
15 { "hello" } [
16     { "hello" } [ CREATE-C-TYPE name>> ] with-parsing
17 ] unit-test
18
19 ! Check that it deletes from old-definitions
20 { 0 } [
21     { } [
22         "hello" current-vocab create-word
23         old-definitions get first adjoin
24         "hello" (CREATE-C-TYPE) drop
25         old-definitions get first cardinality
26     ] with-parsing
27 ] unit-test
28
29 ! make-callback-type
30 { "what-type" } [
31     { } [
32         void "what-type" f { } { } make-callback-type 2drop name>>
33     ] with-parsing
34 ] unit-test
35
36 { 1 } [
37     { } [
38         "hello" current-vocab create-word
39         old-definitions get first adjoin
40         void "hello" f { } { } make-callback-type 3drop
41         old-definitions get first cardinality
42     ] with-parsing
43 ] unit-test
44
45 ! parse-enum-name
46 { t } [
47     { "ayae" } [ parse-enum-name new-definitions get first in? ] with-parsing
48 ] unit-test
49
50 ! validate-c-type-name
51 { "Cannot define a C type “hello*” that ends with an asterisk (*)" } [
52     [ "hello*" validate-c-type-name ] [ ] recover summary
53 ] unit-test
54
55 >>
56
57 TYPEDEF: char char2
58
59 SYMBOL: not-c-type
60
61 CONSTANT: eleven 11
62
63 [
64     "alien.parser.tests" use-vocab
65     "alien.c-types" use-vocab
66
67     [ int ] [ "int" parse-c-type ] unit-test
68     [ { int 5 } ] [ "int[5]" parse-c-type ] unit-test
69     [ { int 5 10 11 } ] [ "int[5][10][11]" parse-c-type ] unit-test
70     [ { int 5 10 eleven } ] [ "int[5][10][eleven]" parse-c-type ] unit-test
71     [ pointer: void ] [ "void*" parse-c-type ] unit-test
72     [ pointer: int ] [ "int*" parse-c-type ] unit-test
73     [ pointer: int* ] [ "int**" parse-c-type ] unit-test
74     [ pointer: int** ] [ "int***" parse-c-type ] unit-test
75     [ pointer: int*** ] [ "int****" parse-c-type ] unit-test
76     [ { pointer: int 3 } ] [ "int*[3]" parse-c-type ] unit-test
77     [ { pointer: void 3 } ] [ "void*[3]" parse-c-type ] unit-test
78     [ pointer: { int 3 } ] [ "int[3]*" parse-c-type ] unit-test
79     [ c-string ] [ "c-string" parse-c-type ] unit-test
80     [ char2 ] [ "char2" parse-c-type ] unit-test
81     [ pointer: char2 ] [ "char2*" parse-c-type ] unit-test
82
83     [ "void[3]" parse-c-type ] must-fail
84     [ "int[3" parse-c-type ] must-fail
85     [ "int[3][4" parse-c-type ] must-fail
86     [ "not-word" parse-c-type ] [ error>> no-word-error? ] must-fail-with
87 ] with-file-vocabs
88
89 FUNCTION: void* alien-parser-function-effect-test ( int *arg1, float arg2 )
90
91 { ( arg1 arg2 -- void* ) } [
92     \ alien-parser-function-effect-test "declared-effect" word-prop
93 ] unit-test
94
95 { t } [ \ alien-parser-function-effect-test inline? ] unit-test
96
97 FUNCTION-ALIAS: (alien-parser-function-effect-test) void* alien-parser-function-effect-test ( int *arg1, float arg2 )
98
99 { ( arg1 arg2 -- void* ) } [
100     \ (alien-parser-function-effect-test) "declared-effect" word-prop
101 ] unit-test
102
103 { t } [ \ (alien-parser-function-effect-test) inline? ] unit-test
104
105 CALLBACK: void* alien-parser-callback-effect-test ( int *arg1 float arg2 )
106
107 { ( arg1 arg2 -- void* ) } [
108     \ alien-parser-callback-effect-test "callback-effect" word-prop
109 ] unit-test
110
111 { t } [ \ alien-parser-callback-effect-test inline? ] unit-test
112
113 ! Reported by mnestic
114 TYPEDEF: int alien-parser-test-int ! reasonably unique name...
115
116 { "OK!" } [
117     [
118         "USE: specialized-arrays SPECIALIZED-ARRAY: alien-parser-test-int" eval( -- )
119         ! after restart, we end up here
120         "OK!"
121     ] [ :1 ] recover
122 ] unit-test
123
124 ! Redefinitions
125 { } [
126     [ C-TYPE: hi TYPEDEF: void* hi ] with-compilation-unit
127 ] unit-test