Skip to content

Commit

Permalink
nitin: add some tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jean Privat <[email protected]>
  • Loading branch information
privat committed Aug 23, 2024
1 parent f67dd0f commit e853f92
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 1 deletion.
3 changes: 2 additions & 1 deletion contrib/nitin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ bin/nitin: $(shell $(NITLS) -M nitin.nit)
$(NITC) --semi-global nitin.nit -m readline -o bin/nitin

.PHONY: check
check:
check: all
$(NITUNIT) .
./tests.sh

.PHONY: doc
doc:
Expand Down
70 changes: 70 additions & 0 deletions contrib/nitin/tests.sav
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

* tests/attribute_initialization.nit
-->class A
...var hello = "Hello"
...end
-->var a1 = new A
-->print a1.hello
Hello
-->redef class A
...var world = "World"
...end
-->var a2 = new A
-->print a2.hello
Hello
-->print a2.world
World
-->print a1.world
12,7--14: Runtime error: Uninitialized attribute _world
print a1.world
^
,---- Stack trace -- - - -
| input-8$Sys$main (12,7--14)
`------------------- - - -
-->a1.world = "Monde"
-->print a1.world
Monde
-->
* tests/hello.nit
-->print "Hello, World!"
Hello, World!
-->
* tests/importation.nit
-->var h = "Hello, world!"
-->import base64
-->print h.encode_base64
SGVsbG8sIHdvcmxkIQ==
-->
* tests/refinement.nit
-->var i = 42
-->redef class Int
...fun foo: Int do return self + 1
...end
-->print(i.foo)
43
-->
* tests/specialization_refinement.nit
-->class A
...end
-->class B
...end
-->var b: Object = new B
-->print b isa A
false
-->redef class B
...super A
...end
-->print b isa A
true
-->
* tests/variables.nit
-->var i = 42
-->print(i)
42
-->i += 1
-->print(i)
43
-->i += 1
-->print(i)
44
-->
9 changes: 9 additions & 0 deletions contrib/nitin/tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

> tests.out
for i in tests/*nit; do
echo "* $i"
printf "\n* $i\n" >> tests.out
bin/nitin < "$i" >> tests.out
done
diff -u tests.sav tests.out
14 changes: 14 additions & 0 deletions contrib/nitin/tests/attribute_initialization.nit
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class A
var hello = "Hello"
end
var a1 = new A
print a1.hello
redef class A
var world = "World"
end
var a2 = new A
print a2.hello
print a2.world
print a1.world
a1.world = "Monde"
print a1.world
1 change: 1 addition & 0 deletions contrib/nitin/tests/hello.nit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print "Hello, World!"
3 changes: 3 additions & 0 deletions contrib/nitin/tests/importation.nit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var h = "Hello, world!"
import base64
print h.encode_base64
Empty file.
5 changes: 5 additions & 0 deletions contrib/nitin/tests/refinement.nit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var i = 42
redef class Int
fun foo: Int do return self + 1
end
print(i.foo)
10 changes: 10 additions & 0 deletions contrib/nitin/tests/specialization_refinement.nit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class A
end
class B
end
var b: Object = new B
print b isa A
redef class B
super A
end
print b isa A
6 changes: 6 additions & 0 deletions contrib/nitin/tests/variables.nit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var i = 42
print(i)
i += 1
print(i)
i += 1
print(i)

0 comments on commit e853f92

Please sign in to comment.