]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/alien/inline/syntax/syntax-tests.factor
tools.test: Make the flag public. Finish porting tester changes to fuzzer.
[factor.git] / unmaintained / alien / inline / syntax / syntax-tests.factor
1 ! Copyright (C) 2009 Jeremy Hughes.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.inline alien.inline.syntax io.directories io.files
4 kernel namespaces tools.test alien.c-types alien.data alien.structs ;
5 IN: alien.inline.syntax.tests
6
7 DELETE-C-LIBRARY: test
8 C-LIBRARY: test
9
10 C-FUNCTION: const-int add ( int a, int b )
11     return a + b;
12 ;
13
14 C-TYPEDEF: double bigfloat
15
16 C-FUNCTION: bigfloat smaller ( bigfloat a )
17     return a / 10;
18 ;
19
20 C-STRUCTURE: rectangle
21     { "int" "width" }
22     { "int" "height" } ;
23
24 C-FUNCTION: int area ( rectangle c )
25     return c.width * c.height;
26 ;
27
28 ;C-LIBRARY
29
30 { 2 1 } [ add ] must-infer-as
31 [ 5 ] [ 2 3 add ] unit-test
32
33 [ t ] [ "double" "bigfloat" [ resolve-typedef ] same? ] unit-test
34 { 1 1 } [ smaller ] must-infer-as
35 [ 1.0 ] [ 10 smaller ] unit-test
36
37 [ t ] [ "rectangle" resolve-typedef struct-type? ] unit-test
38 { 1 1 } [ area ] must-infer-as
39 [ 20 ] [
40     "rectangle" <c-object>
41     4 over set-rectangle-width
42     5 over set-rectangle-height
43     area
44 ] unit-test
45
46
47 DELETE-C-LIBRARY: cpplib
48 C-LIBRARY: cpplib
49
50 COMPILE-AS-C++
51
52 C-INCLUDE: <string>
53
54 C-FUNCTION: const-char* hello ( )
55     std::string s("hello world");
56     return s.c_str();
57 ;
58
59 ;C-LIBRARY
60
61 { 0 1 } [ hello ] must-infer-as
62 [ "hello world" ] [ hello ] unit-test
63
64
65 DELETE-C-LIBRARY: compile-error
66 C-LIBRARY: compile-error
67
68 C-FUNCTION: char* breakme ( )
69     return not a string;
70 ;
71
72 << [ compile-c-library ] must-fail >>