From: Lucas Bajolet Date: Mon, 10 Jun 2013 23:48:37 +0000 (-0400) Subject: stdlib : String, added test for copy constructor X-Git-Tag: v0.6~38^2~1 X-Git-Url: http://nitlanguage.org stdlib : String, added test for copy constructor Signed-off-by: Lucas Bajolet --- diff --git a/tests/sav/string_ffi_ref_test.sav b/tests/sav/string_ffi_ref_test.sav new file mode 100644 index 0000000..e9856d5 --- /dev/null +++ b/tests/sav/string_ffi_ref_test.sav @@ -0,0 +1,3 @@ +This is a test string +This is a test string +Do the strings have the same NativeString reference ? False diff --git a/tests/string_ffi_ref_test.nit b/tests/string_ffi_ref_test.nit new file mode 100644 index 0000000..d2c6277 --- /dev/null +++ b/tests/string_ffi_ref_test.nit @@ -0,0 +1,67 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2013 Lucas Bajolet +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module string_ffi_ref_test + +class StringTest + + var copied_str: nullable String + + var referenced_str: nullable String + + init + do + copied_str = null + referenced_str = null + end + + fun get_c_string import String::items, String::from_cstring, String::copy_from_native, StringTest::ref_test, StringTest::copy_test `{ + char* string = "This is a test string"; + + String ref_string = new_String_from_cstring(string); + StringTest_ref_test(recv, ref_string); + + String copy_string = new_String_copy_from_native(string); + StringTest_copy_test(recv, copy_string); + + int same_refs = String_items(copy_string) == String_items(ref_string); + + printf("Do the strings have the same NativeString reference ? "); + + if(same_refs){ + printf("True\n"); + }else{ + printf("False\n"); + } + `} + + private fun ref_test(referenced: String) + do + print referenced + referenced_str = referenced + end + + private fun copy_test(copied: String) + do + print copied + copied_str = copied + end + +end + +var str_test = new StringTest + +str_test.get_c_string