tests: add base_new.nit
authorJean Privat <jean@pryen.org>
Thu, 23 Oct 2014 01:51:06 +0000 (21:51 -0400)
committerJean Privat <jean@pryen.org>
Fri, 24 Oct 2014 23:55:55 +0000 (19:55 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/base_new.nit [new file with mode: 0644]
tests/sav/base_new.res [new file with mode: 0644]
tests/sav/base_new_alt1.res [new file with mode: 0644]
tests/sav/base_new_alt2.res [new file with mode: 0644]
tests/sav/base_new_alt3.res [new file with mode: 0644]
tests/sav/base_new_alt4.res [new file with mode: 0644]
tests/sav/base_new_alt5.res [new file with mode: 0644]
tests/sav/base_new_alt6.res [new file with mode: 0644]
tests/sav/base_new_alt7.res [new file with mode: 0644]
tests/sav/base_new_alt8.res [new file with mode: 0644]

diff --git a/tests/base_new.nit b/tests/base_new.nit
new file mode 100644 (file)
index 0000000..8fdf39a
--- /dev/null
@@ -0,0 +1,84 @@
+# 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.
+
+import kernel
+
+interface A
+       new do return new B(1)
+       new n2 do return new B(2)
+       new n3: B do return new B(3)
+       new n4: Int do return 4
+       new n5: Int do return new B.ni(5)
+       #alt1#new n do return 5
+       #alt2#new n do 0.output
+       #alt3#new n do return self
+       #alt4#new n: Int do return object_id
+end
+
+class B
+       super A
+       var i: Int
+       redef fun output do
+               'B'.output
+               i.output
+       end
+       new n2 do return new B(22)
+       new n3: B do return new B(33)
+       new n4: Int do return 44
+       new n5: Int do return new B.ni(55)
+       new ni(i: Int): Int do return i*10
+end
+
+class C
+       super B
+       new(i: Int): B do return new B(i)
+       redef fun output do
+               'C'.output
+               i.output
+       end
+end
+
+redef class Int
+       new z do return 0
+       new a: A do return new A
+end
+
+(new A).output
+#alt5#(new A).i.output
+(new A.n2).output
+#alt6#(new A.n2).i.output
+(new A.n3).i.output
+(new A.n4).output
+(new A.n5).output
+#alt1-4#(new A.n).output
+
+'\n'.output
+
+(new B(11)).output
+(new B.n2).i.output
+(new B.n3).i.output
+(new B.n4).output
+(new B.n5).output
+(new B.ni(66)).output
+
+'\n'.output
+
+(new C(111)).output
+#alt7#(new C.n2).output
+
+'\n'.output
+
+#alt8#(new Int).output
+(new Int.z).output
+(new Int.a).output
diff --git a/tests/sav/base_new.res b/tests/sav/base_new.res
new file mode 100644 (file)
index 0000000..fe346a1
--- /dev/null
@@ -0,0 +1,17 @@
+B1
+B2
+3
+4
+50
+
+B11
+22
+33
+44
+550
+660
+
+B111
+
+0
+B1
diff --git a/tests/sav/base_new_alt1.res b/tests/sav/base_new_alt1.res
new file mode 100644 (file)
index 0000000..e0424d3
--- /dev/null
@@ -0,0 +1 @@
+alt/base_new_alt1.nit:23,18: Type error: expected A, got Int
diff --git a/tests/sav/base_new_alt2.res b/tests/sav/base_new_alt2.res
new file mode 100644 (file)
index 0000000..0e7983c
--- /dev/null
@@ -0,0 +1 @@
+alt/base_new_alt2.nit:24,6: Control error: Reached end of function (a 'return' with a value was expected).
diff --git a/tests/sav/base_new_alt3.res b/tests/sav/base_new_alt3.res
new file mode 100644 (file)
index 0000000..bc5d6cd
--- /dev/null
@@ -0,0 +1 @@
+alt/base_new_alt3.nit:25,18--21: Error: self cannot be used in top-level method.
diff --git a/tests/sav/base_new_alt4.res b/tests/sav/base_new_alt4.res
new file mode 100644 (file)
index 0000000..d89b91e
--- /dev/null
@@ -0,0 +1 @@
+alt/base_new_alt4.nit:26,23--31: Error: 'object_id' is not a top-level method, thus need a receiver.
diff --git a/tests/sav/base_new_alt5.res b/tests/sav/base_new_alt5.res
new file mode 100644 (file)
index 0000000..15d625a
--- /dev/null
@@ -0,0 +1 @@
+alt/base_new_alt5.nit:58,1--9: Error: Method 'i' doesn't exists in A.
diff --git a/tests/sav/base_new_alt6.res b/tests/sav/base_new_alt6.res
new file mode 100644 (file)
index 0000000..53c4091
--- /dev/null
@@ -0,0 +1 @@
+alt/base_new_alt6.nit:60,1--12: Error: Method 'i' doesn't exists in A.
diff --git a/tests/sav/base_new_alt7.res b/tests/sav/base_new_alt7.res
new file mode 100644 (file)
index 0000000..698bfbf
--- /dev/null
@@ -0,0 +1 @@
+alt/base_new_alt7.nit:78,2--9: Error: Method 'n2' doesn't exists in C.
diff --git a/tests/sav/base_new_alt8.res b/tests/sav/base_new_alt8.res
new file mode 100644 (file)
index 0000000..1eed641
--- /dev/null
@@ -0,0 +1 @@
+alt/base_new_alt8.nit:82,2--8: Cannot instantiate enum Int.