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
14 C-TYPEDEF: std::string string
16 C++-CLASS: std::string c++-root
18 GENERIC: to-string ( obj -- str )
20 C++-METHOD: std::string to-string const-char* c_str ( )
22 CM-FUNCTION: std::string* new_string ( const-char* s )
23 return new std::string(s);
28 ALIAS: <std::string> new_string
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
36 DELETE-C-LIBRARY: inheritance
37 C-LIBRARY: inheritance
46 alpha(const char* s) {
49 const char* render() {
52 virtual const char* chop() {
55 virtual int length() {
63 beta(const char* s) : alpha(s + 1) { };
64 const char* render() {
67 virtual const char* chop() {
73 C++-CLASS: alpha c++-root
76 CM-FUNCTION: alpha* new_alpha ( const-char* s )
80 CM-FUNCTION: beta* new_beta ( const-char* s )
84 ALIAS: <alpha> new_alpha
85 ALIAS: <beta> new_beta
87 GENERIC: render ( obj -- obj )
88 GENERIC: chop ( obj -- obj )
89 GENERIC: length ( obj -- n )
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 ( )
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