Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / test_explain_assert.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 class MyClass
16 var i = 12
17 var s = "asdf"
18 redef fun to_s do return "<{class_name} i:{i} s:{s}>"
19 end
20
21 fun foo(v: nullable Int): nullable Int do
22 print "foo"
23 return v
24 end
25
26 assert 1 == 1
27 #alt1#assert 1 == "some string"
28 #alt2#assert 1 == null
29 #alt3#assert foo(12) == null
30 #alt4#assert foo(null) != null
31
32 #alt5#var x = 0.0
33 #alt5#var y = 1.0
34 #alt5#assert x.is_approx(y, 0.5)
35
36 #alt6#assert not true
37
38 #alt7#var a = [true, false, true]
39 #alt7#assert a[1]
40
41 #alt8#assert [0, 1, 2].is_empty
42
43 #alt9#assert (new MyClass) == 0
44
45 #alt10#var n = foo(null)
46 #alt10#assert n != null and n.to_s == "crash" # Not explained
47
48 #alt11#assert not 1 == 1
49 #alt12#assert 4 isa MyClass
50
51 #alt13#var f = false
52 #alt13#assert f # Not explained