tests: add test_new_native.nit
authorJean Privat <jean@pryen.org>
Thu, 12 Jun 2014 14:22:42 +0000 (10:22 -0400)
committerJean Privat <jean@pryen.org>
Thu, 12 Jun 2014 14:22:42 +0000 (10:22 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/sav/nitg-e/test_new_native.res [new file with mode: 0644]
tests/sav/nitg-e/test_new_native_alt1.res [new file with mode: 0644]
tests/sav/test_new_native.res [new file with mode: 0644]
tests/sav/test_new_native_alt1.res [new file with mode: 0644]
tests/test_new_native.nit [new file with mode: 0644]

diff --git a/tests/sav/nitg-e/test_new_native.res b/tests/sav/nitg-e/test_new_native.res
new file mode 100644 (file)
index 0000000..e69ef40
--- /dev/null
@@ -0,0 +1,7 @@
+NativeString
+N
+Nit
+NativeArray
+3
+1
+1,10,100
diff --git a/tests/sav/nitg-e/test_new_native_alt1.res b/tests/sav/nitg-e/test_new_native_alt1.res
new file mode 100644 (file)
index 0000000..58f1483
--- /dev/null
@@ -0,0 +1,7 @@
+NativeString
+N
+Nit
+NativeArray
+3
+1
+1,true,100
diff --git a/tests/sav/test_new_native.res b/tests/sav/test_new_native.res
new file mode 100644 (file)
index 0000000..4fd1ad6
--- /dev/null
@@ -0,0 +1,7 @@
+NativeString
+N
+Nit
+NativeArray[Int]
+3
+1
+1,10,100
diff --git a/tests/sav/test_new_native_alt1.res b/tests/sav/test_new_native_alt1.res
new file mode 100644 (file)
index 0000000..ae96edf
--- /dev/null
@@ -0,0 +1,4 @@
+Runtime error: Cast failed. Expected `NativeArray#0`, got `Bool` (../lib/standard/collection/array.nit:662)
+NativeString
+N
+Nit
diff --git a/tests/test_new_native.nit b/tests/test_new_native.nit
new file mode 100644 (file)
index 0000000..d2c35fc
--- /dev/null
@@ -0,0 +1,41 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# 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.
+
+redef class NativeArray[E]
+       new(length: Int) is intern
+end
+
+redef class NativeString
+       new(length: Int) is intern
+end
+
+var s = new NativeString(4)
+s[0] = 'N'
+s[2] = 't'
+s[1] = 'i'
+s[3] = '\0'
+print s.class_name
+print s[0]
+print s.to_s
+
+var a: NativeArray[Object] = new NativeArray[Int](3)
+a[0] = 1
+a[1] = 10
+a[2] = 100
+#alt1#a[1] = true
+print a.class_name
+print a.length
+print a[0]
+print a.to_a.join(",")
+