]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/parser/parser-tests.factor
ecbb92a03efbdd75e2129b52435c7923d0f9db0e
[factor.git] / basis / alien / parser / parser-tests.factor
1 ! (c)2009 Joe Groff bsd license
2 USING: accessors alien.c-types alien.parser alien.syntax
3 continuations debugger eval parser tools.test vocabs.parser
4 words ;
5 IN: alien.parser.tests
6
7 TYPEDEF: char char2
8
9 SYMBOL: not-c-type
10
11 CONSTANT: eleven 11
12
13 [
14     "alien.parser.tests" use-vocab
15     "alien.c-types" use-vocab
16
17     [ int ] [ "int" parse-c-type ] unit-test
18     [ { int 5 } ] [ "int[5]" parse-c-type ] unit-test
19     [ { int 5 10 11 } ] [ "int[5][10][11]" parse-c-type ] unit-test
20     [ { int 5 10 eleven } ] [ "int[5][10][eleven]" parse-c-type ] unit-test
21     [ pointer: void ] [ "void*" parse-c-type ] unit-test
22     [ pointer: int ] [ "int*" parse-c-type ] unit-test
23     [ pointer: int* ] [ "int**" parse-c-type ] unit-test
24     [ pointer: int** ] [ "int***" parse-c-type ] unit-test
25     [ pointer: int*** ] [ "int****" parse-c-type ] unit-test
26     [ { pointer: int 3 } ] [ "int*[3]" parse-c-type ] unit-test
27     [ { pointer: void 3 } ] [ "void*[3]" parse-c-type ] unit-test
28     [ pointer: { int 3 } ] [ "int[3]*" parse-c-type ] unit-test
29     [ c-string ] [ "c-string" parse-c-type ] unit-test
30     [ char2 ] [ "char2" parse-c-type ] unit-test
31     [ pointer: char2 ] [ "char2*" parse-c-type ] unit-test
32
33     [ "void[3]" parse-c-type ] must-fail
34     [ "int[3" parse-c-type ] must-fail
35     [ "int[3][4" parse-c-type ] must-fail
36     [ "not-word" parse-c-type ] [ error>> no-word-error? ] must-fail-with
37 ] with-file-vocabs
38
39 FUNCTION: void* alien-parser-function-effect-test ( int *arg1 float arg2 ) ;
40
41 [ ( arg1 arg2 -- void* ) ] [
42     \ alien-parser-function-effect-test "declared-effect" word-prop
43 ] unit-test
44
45 [ t ] [ \ alien-parser-function-effect-test inline? ] unit-test
46
47 FUNCTION-ALIAS: (alien-parser-function-effect-test) void* alien-parser-function-effect-test ( int *arg1 float arg2 ) ;
48
49 [ ( arg1 arg2 -- void* ) ] [
50     \ (alien-parser-function-effect-test) "declared-effect" word-prop
51 ] unit-test
52
53 [ t ] [ \ (alien-parser-function-effect-test) inline? ] unit-test
54
55 CALLBACK: void* alien-parser-callback-effect-test ( int *arg1 float arg2 ) ;
56
57 [ ( arg1 arg2 -- void* ) ] [
58     \ alien-parser-callback-effect-test "callback-effect" word-prop
59 ] unit-test
60
61 [ t ] [ \ alien-parser-callback-effect-test inline? ] unit-test
62
63 ! Reported by mnestic
64 TYPEDEF: int alien-parser-test-int ! reasonably unique name...
65
66 [ "OK!" ] [
67     [
68         "USE: specialized-arrays SPECIALIZED-ARRAY: alien-parser-test-int" eval( -- )
69         ! after restart, we end up here
70         "OK!"
71     ] [ :1 ] recover
72 ] unit-test