]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/alien/cxx/syntax/syntax-tests.factor
tools.test: Make the flag public. Finish porting tester changes to fuzzer.
[factor.git] / unmaintained / alien / cxx / syntax / syntax-tests.factor
1 ! Copyright (C) 2009 Jeremy Hughes.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: tools.test alien.cxx.syntax alien.inline.syntax
4 alien.marshall.syntax alien.marshall accessors kernel ;
5 IN: alien.cxx.syntax.tests
6
7 DELETE-C-LIBRARY: test
8 C-LIBRARY: test
9
10 COMPILE-AS-C++
11
12 C-INCLUDE: <string>
13
14 C-TYPEDEF: std::string string
15
16 C++-CLASS: std::string c++-root
17
18 GENERIC: to-string ( obj -- str )
19
20 C++-METHOD: std::string to-string const-char* c_str ( )
21
22 CM-FUNCTION: std::string* new_string ( const-char* s )
23     return new std::string(s);
24 ;
25
26 ;C-LIBRARY
27
28 ALIAS: <std::string> new_string
29
30 { 1 1 } [ new_string ] must-infer-as
31 { 1 1 } [ c_str_std__string ] must-infer-as
32 [ t ] [ "abc" <std::string> std::string? ] unit-test
33 [ "abc" ] [ "abc" <std::string> to-string ] unit-test
34
35
36 DELETE-C-LIBRARY: inheritance
37 C-LIBRARY: inheritance
38
39 COMPILE-AS-C++
40
41 C-INCLUDE: <cstring>
42
43 <RAW-C
44 class alpha {
45     public:
46     alpha(const char* s) {
47         str = s;
48     };
49     const char* render() {
50         return str;
51     };
52     virtual const char* chop() {
53         return str;
54     };
55     virtual int length() {
56         return strlen(str);
57     };
58     const char* str;
59 };
60
61 class beta : alpha {
62     public:
63     beta(const char* s) : alpha(s + 1) { };
64     const char* render() {
65         return str + 1;
66     };
67     virtual const char* chop() {
68         return str + 2;
69     };
70 };
71 RAW-C>
72
73 C++-CLASS: alpha c++-root
74 C++-CLASS: beta alpha
75
76 CM-FUNCTION: alpha* new_alpha ( const-char* s )
77     return new alpha(s);
78 ;
79
80 CM-FUNCTION: beta* new_beta ( const-char* s )
81     return new beta(s);
82 ;
83
84 ALIAS: <alpha> new_alpha
85 ALIAS: <beta> new_beta
86
87 GENERIC: render ( obj -- obj )
88 GENERIC: chop ( obj -- obj )
89 GENERIC: length ( obj -- n )
90
91 C++-METHOD: alpha render const-char* render ( )
92 C++-METHOD: beta render const-char* render ( )
93 C++-VIRTUAL: alpha chop const-char* chop ( )
94 C++-VIRTUAL: beta chop const-char* chop ( )
95 C++-VIRTUAL: alpha length int length ( )
96
97 ;C-LIBRARY
98
99 { 1 1 } [ render_alpha ] must-infer-as
100 { 1 1 } [ chop_beta ] must-infer-as
101 { 1 1 } [ length_alpha ] must-infer-as
102 [ t ] [ "x" <alpha> alpha#? ] unit-test
103 [ t ] [ "x" <alpha> alpha? ] unit-test
104 [ t ] [ "x" <beta> alpha? ] unit-test
105 [ f ] [ "x" <beta> alpha#? ] unit-test
106 [ 5 ] [ "hello" <alpha> length ] unit-test
107 [ 4 ] [ "hello" <beta> length ] unit-test
108 [ "hello" ] [ "hello" <alpha> render ] unit-test
109 [ "llo" ] [ "hello" <beta> render ] unit-test
110 [ "ello" ] [ "hello" <beta> underlying>> \ alpha# new swap >>underlying render ] unit-test
111 [ "hello" ] [ "hello" <alpha> chop ] unit-test
112 [ "lo" ] [ "hello" <beta> chop ] unit-test
113 [ "lo" ] [ "hello" <beta> underlying>> \ alpha# new swap >>underlying chop ] unit-test