1 module test.experimental.stdcpp..string; 2 3 import core.experimental.stdcpp.string; 4 5 alias std_string = basic_string!char; 6 alias std_wstring = basic_string!wchar; 7 8 unittest 9 { 10 version(Windows) 11 { 12 std_string str = std_string("Hello"); 13 14 assert(str.size == 5); 15 assert(str.length == 5); 16 assert(str.empty == false); 17 18 assert(sumOfElements_val(str) == 1000);//1500); 19 assert(sumOfElements_ref(str) == 500); 20 21 std_string str2 = std_string(Default); 22 assert(str2.size == 0); 23 assert(str2.length == 0); 24 assert(str2.empty == true); 25 assert(str2[] == []); 26 27 // test local instantiations... 28 // there's no basic_string<char16_t> instantiation in C++ 29 std_wstring str3 = std_wstring("Hello"w); 30 31 assert(str3.size == 5); 32 assert(str3.length == 5); 33 assert(str3.empty == false); 34 } 35 else 36 { 37 pragma(msg, "std.string implementation not yet done for linux - gcc/clang"); 38 } 39 } 40 41 42 extern(C++): 43 44 // test the ABI for calls to C++ 45 int sumOfElements_val(std_string); 46 int sumOfElements_ref(ref const(std_string)); 47 48 // test the ABI for calls from C++ 49 int fromC_val(std_string str) 50 { 51 assert(str[] == "Hello"); 52 assert(str.front == 'H'); 53 assert(str.back == 'o'); 54 assert(str.at(2) == 'l'); 55 56 // str.fill(2); 57 58 int r; 59 foreach (e; str[]) 60 r += e; 61 62 assert(r == 500); 63 return r; 64 } 65 66 int fromC_ref(ref const(std_string) str) 67 { 68 int r; 69 foreach (e; str[]) 70 r += e; 71 return r; 72 }