mirah 0.1.4-java → 0.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/History.txt +531 -0
- data/README.md +23 -10
- data/Rakefile +239 -156
- data/TODO.md +71 -10
- data/bin/mirah +1 -1
- data/bin/mirahc +1 -1
- data/dist/mirahc.jar +0 -0
- data/examples/bintrees.mirah +2 -2
- data/examples/construction.mirah +2 -2
- data/examples/fields.mirah +1 -1
- data/examples/fractal.mirah +1 -1
- data/examples/fractal.rb +70 -0
- data/examples/interfaces.mirah +1 -1
- data/examples/java_thing.mirah +1 -1
- data/examples/macros/square.mirah +3 -3
- data/examples/macros/square_int.mirah +3 -3
- data/examples/macros/string_each_char.mirah +6 -6
- data/examples/rosettacode/100-doors.mirah +0 -2
- data/examples/rosettacode/count-occurrences-of-a-substring.mirah +3 -3
- data/examples/rosettacode/empty-string.mirah +1 -1
- data/examples/rosettacode/fizz-buzz.mirah +4 -4
- data/examples/rosettacode/is-string-numeric.mirah +7 -7
- data/examples/rosettacode/palindrome.mirah +2 -2
- data/examples/rosettacode/reverse-a-string.mirah +1 -1
- data/examples/rosettacode/rot-13.mirah +1 -1
- data/examples/{edb.mirah → rosettacode/simple_character_math.mirah} +13 -4
- data/examples/rosettacode/string-case.mirah +2 -2
- data/examples/rosettacode/string-length.mirah +1 -1
- data/examples/swing.mirah +9 -14
- data/extensions_and_macros.md +117 -0
- data/lib/mirah.rb +1 -1
- data/lib/mirah/errors.rb +3 -1
- data/lib/mirah/transform/ast_ext.rb +3 -2
- data/lib/mirah/util/process_errors.rb +1 -2
- data/lib/mirah/version.rb +1 -1
- data/test/A.class +0 -0
- data/test/core/util/jvm_version_test.rb +10 -0
- data/test/core/util/mirah_arguments_test.rb +51 -4
- data/test/fixtures/cp1251_test.mirah +7 -0
- data/test/fixtures/org/foo/AbstractExecutorJava8.java +30 -0
- data/test/fixtures/org/foo/ClassWithSelfReferencingTypeParameter.java +24 -0
- data/test/fixtures/org/foo/InnerInterfaceClass.java +12 -0
- data/test/fixtures/org/foo/IntAnno.class +0 -0
- data/test/fixtures/org/foo/TypeFixtureJava8.java +10 -0
- data/test/fixtures/utf8_test.mirah +7 -0
- data/test/jvm/access_levels_test.rb +31 -0
- data/test/jvm/annotations_test.rb +3 -6
- data/test/jvm/blocks_test.rb +303 -120
- data/test/jvm/cast_test.rb +123 -50
- data/test/jvm/closure_test.rb +242 -0
- data/test/jvm/constructors_test.rb +1 -3
- data/test/jvm/example_test.rb +6 -2
- data/test/jvm/extensions/array_extensions_test.rb +181 -0
- data/test/jvm/extensions/collection_extensions_test.rb +195 -0
- data/test/jvm/{enumerable_test.rb → extensions/enumerable_test.rb} +81 -13
- data/test/jvm/extensions/hash_extensions_test.rb +56 -0
- data/test/jvm/extensions/list_extensions_test.rb +143 -0
- data/test/jvm/extensions/lock_extensions_test.rb +43 -0
- data/test/jvm/{numeric_extensions_test.rb → extensions/numeric_extensions_test.rb} +0 -0
- data/test/jvm/extensions/numeric_operators_test.rb +86 -0
- data/test/jvm/extensions/object_extensions_test.rb +122 -0
- data/test/jvm/{string_builder_extensions_test.rb → extensions/string_builder_extensions_test.rb} +0 -0
- data/test/jvm/{string_extensions_test.rb → extensions/string_extensions_test.rb} +57 -4
- data/test/jvm/generics_test.rb +14 -6
- data/test/jvm/import_test.rb +38 -1
- data/test/jvm/interface_test.rb +17 -0
- data/test/jvm/jvm_commands_test.rb +9 -0
- data/test/jvm/jvm_compiler_test.rb +568 -43
- data/test/jvm/macros_test.rb +343 -19
- data/test/jvm/main_method_test.rb +1 -3
- data/test/jvm/new_backend_test_helper.rb +54 -7
- data/test/jvm/rescue_test.rb +20 -5
- data/test/jvm/static_fields_test.rb +52 -10
- data/test/jvm/{mirror_compilation_test_helper.rb → string_test.rb} +10 -9
- data/test/jvm/varargs_test.rb +6 -16
- data/test/mirrors/base_type_test.rb +20 -7
- data/test/mirrors/bytecode_mirror_test.rb +8 -3
- data/test/mirrors/generics_test.rb +89 -10
- data/test/mirrors/member_test.rb +1 -1
- data/test/mirrors/method_lookup_test.rb +10 -3
- data/test/mirrors/mirrors_test.rb +20 -20
- data/test/mirrors/simple_async_mirror_loader_test.rb +1 -1
- data/test/mirrors/simple_mirror_loader_test.rb +1 -1
- data/test/newMirahClass$Closure2.class +0 -0
- data/test/newMirahClass.class +0 -0
- data/test/test_helper.rb +8 -1
- metadata +31 -16
- data/bin/bundler +0 -16
- data/bin/rake +0 -16
- data/examples/ant/example-build.xml~ +0 -7
- data/examples/test.edb +0 -9
- data/lib/mirah/compiler.rb +0 -67
- data/lib/mirah/parser.rb +0 -224
- data/lib/mirah/util/delegate.rb +0 -65
- data/test/jvm/list_extensions_test.rb +0 -23
@@ -0,0 +1,56 @@
|
|
1
|
+
# Copyright (c) 2013 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
class HashExtensionsTest < Test::Unit::TestCase
|
17
|
+
|
18
|
+
def test_hash_each_untyped
|
19
|
+
cls, = compile(%q{
|
20
|
+
res = java::util::TreeSet.new # stable sort order of the results
|
21
|
+
|
22
|
+
{
|
23
|
+
a: "b",
|
24
|
+
"c" => "d",
|
25
|
+
"e" => 3,
|
26
|
+
[4] => "h"
|
27
|
+
}.each do |k,v|
|
28
|
+
res.add("#{v},#{k}")
|
29
|
+
end
|
30
|
+
|
31
|
+
res.each do |r|
|
32
|
+
puts r
|
33
|
+
end
|
34
|
+
})
|
35
|
+
assert_run_output("3,e\nb,a\nd,c\nh,[4]\n", cls)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_hash_each_typed
|
39
|
+
cls, = compile(%q{
|
40
|
+
res = java::util::TreeSet.new # stable sort order of the results
|
41
|
+
|
42
|
+
{
|
43
|
+
"a" => 3,
|
44
|
+
"b" => 2
|
45
|
+
}.each do |k:String,v:int|
|
46
|
+
res.add("#{v+1},#{k}")
|
47
|
+
end
|
48
|
+
|
49
|
+
res.each do |r|
|
50
|
+
puts r
|
51
|
+
end
|
52
|
+
})
|
53
|
+
assert_run_output("3,b\n4,a\n", cls)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,143 @@
|
|
1
|
+
class ListExtensionsTest < Test::Unit::TestCase
|
2
|
+
def test_empty_q
|
3
|
+
cls, = compile(<<-EOF)
|
4
|
+
x = []
|
5
|
+
puts x.empty?
|
6
|
+
EOF
|
7
|
+
assert_run_output("true\n", cls)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_bracket_getter
|
11
|
+
cls, = compile(<<-EOF)
|
12
|
+
x = [1,2]
|
13
|
+
puts x[0]
|
14
|
+
EOF
|
15
|
+
assert_run_output("1\n", cls)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_bracket_assignment
|
19
|
+
cls, = compile(<<-EOF)
|
20
|
+
import java.util.ArrayList
|
21
|
+
x = ArrayList.new
|
22
|
+
x[0]= "2"
|
23
|
+
puts x
|
24
|
+
EOF
|
25
|
+
assert_run_output("[2]\n", cls)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_sort_with_block
|
29
|
+
cls, = compile(<<-EOF)
|
30
|
+
puts ([3,1,2].sort do |o0:Comparable,o1:Comparable|
|
31
|
+
-o0.compareTo(o1)
|
32
|
+
end)
|
33
|
+
EOF
|
34
|
+
assert_run_output("[3, 2, 1]\n", cls)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_sort_bang_with_block
|
38
|
+
cls, = compile(<<-EOF)
|
39
|
+
puts ([3,1,2].sort! do |o0:Comparable,o1:Comparable|
|
40
|
+
-o0.compareTo(o1)
|
41
|
+
end)
|
42
|
+
EOF
|
43
|
+
assert_run_output("[3, 2, 1]\n", cls)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_sort_with_comparator
|
47
|
+
cls, = compile(<<-EOF)
|
48
|
+
class Co implements java::util::Comparator
|
49
|
+
def compare(o0:Object,o1:Object)
|
50
|
+
compare(Comparable(o0),Comparable(o1))
|
51
|
+
end
|
52
|
+
def compare(o0:Comparable,o1:Comparable)
|
53
|
+
-o0.compareTo(o1)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
puts [3,1,2].sort(Co.new)
|
57
|
+
EOF
|
58
|
+
assert_run_output("[3, 2, 1]\n", cls)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_sort_bang_with_comparator
|
62
|
+
cls, = compile(<<-EOF)
|
63
|
+
class Co implements java::util::Comparator
|
64
|
+
def compare(o0:Object,o1:Object)
|
65
|
+
compare(Comparable(o0),Comparable(o1))
|
66
|
+
end
|
67
|
+
def compare(o0:Comparable,o1:Comparable)
|
68
|
+
-o0.compareTo(o1)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
puts [3,1,2].sort!(Co.new)
|
72
|
+
EOF
|
73
|
+
assert_run_output("[3, 2, 1]\n", cls)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_sort_without_comparator
|
77
|
+
cls, = compile(<<-EOF)
|
78
|
+
puts [5,1,3].sort
|
79
|
+
EOF
|
80
|
+
assert_run_output("[1, 3, 5]\n", cls)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_first
|
84
|
+
cls, = compile(<<-EOF)
|
85
|
+
puts [5,1,3].first
|
86
|
+
EOF
|
87
|
+
assert_run_output("5\n", cls)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_empty_list_first
|
91
|
+
cls, = compile(<<-EOF)
|
92
|
+
puts [].first
|
93
|
+
EOF
|
94
|
+
assert_run_output("null\n", cls)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_last
|
98
|
+
cls, = compile(<<-EOF)
|
99
|
+
puts [5,1,3].last
|
100
|
+
EOF
|
101
|
+
assert_run_output("3\n", cls)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_empty_list_last
|
105
|
+
cls, = compile(<<-EOF)
|
106
|
+
puts [].last
|
107
|
+
EOF
|
108
|
+
assert_run_output("null\n", cls)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_first!
|
112
|
+
cls, = compile(<<-EOF)
|
113
|
+
puts [5,1,3].first!
|
114
|
+
EOF
|
115
|
+
assert_run_output("5\n", cls)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_empty_list_first!
|
119
|
+
cls, = compile(<<-EOF)
|
120
|
+
puts [].first!
|
121
|
+
EOF
|
122
|
+
assert_raise_java(java.lang.IndexOutOfBoundsException) do
|
123
|
+
cls.main nil
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_last!
|
128
|
+
cls, = compile(<<-EOF)
|
129
|
+
puts [5,1,3].last!
|
130
|
+
EOF
|
131
|
+
assert_run_output("3\n", cls)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_empty_list_last!
|
135
|
+
cls, = compile(<<-EOF)
|
136
|
+
puts [].last!
|
137
|
+
EOF
|
138
|
+
assert_raise_java(java.lang.ArrayIndexOutOfBoundsException) do
|
139
|
+
cls.main nil
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Copyright (c) 2015 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require 'test_helper'
|
17
|
+
|
18
|
+
class LockExtensionsTest < Test::Unit::TestCase
|
19
|
+
|
20
|
+
def test_synchronize_happy
|
21
|
+
cls, = compile(<<-EOF)
|
22
|
+
import java.util.concurrent.locks.ReentrantLock
|
23
|
+
lock = ReentrantLock.new
|
24
|
+
lock.synchronize do
|
25
|
+
puts "synchronized. Yay!"
|
26
|
+
end
|
27
|
+
EOF
|
28
|
+
assert_run_output("synchronized. Yay!\n", cls)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_synchronize_lock_unlocks_after_exception
|
32
|
+
cls, = compile(<<-EOF)
|
33
|
+
import java.util.concurrent.locks.ReentrantLock
|
34
|
+
lock = ReentrantLock.new
|
35
|
+
begin
|
36
|
+
lock.synchronize { raise "wut" }
|
37
|
+
rescue
|
38
|
+
end
|
39
|
+
Thread.new { puts lock.tryLock }.start.join
|
40
|
+
EOF
|
41
|
+
assert_run_output("true\n", cls)
|
42
|
+
end
|
43
|
+
end
|
File without changes
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# Copyright (c) 2015 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require 'test_helper'
|
17
|
+
|
18
|
+
class NumericOperatorsTest < Test::Unit::TestCase
|
19
|
+
|
20
|
+
OPERATORS = ['+', '-', '/', '*', '%', '>', '<', '!=', '==', '>=', '<=']
|
21
|
+
# Note! signed right shift is not supported due to parser issue:
|
22
|
+
# macro def >>>(n);end
|
23
|
+
# wont parse
|
24
|
+
BITWISE_OPERATORS = ['&', '|', '&', '^']
|
25
|
+
SHIFT_OPERATORS = ['>>', '<<']
|
26
|
+
# mirah fixnum constants defaults to int
|
27
|
+
FIXNUM_TYPES = ['Integer', 'Short', 'Byte', 'Long']
|
28
|
+
# need to cast constants to primitives
|
29
|
+
FLOAT_TYPES = ['Float', 'Double']
|
30
|
+
|
31
|
+
def self.define_test_methods(cast, i, numeric_class, operator , assert)
|
32
|
+
define_method "test_#{numeric_class}_left_arithmetic_#{i}".to_sym do
|
33
|
+
cls, = compile(<<-EOF)
|
34
|
+
puts #{numeric_class}.new(#{cast}(5)) #{operator} #{cast}(7)
|
35
|
+
EOF
|
36
|
+
assert_run_output("#{assert}\n", cls)
|
37
|
+
end
|
38
|
+
define_method "test_#{numeric_class}_right_arithmetic_#{i}".to_sym do
|
39
|
+
cls, = compile(<<-EOF)
|
40
|
+
puts #{cast}(5) #{operator} #{numeric_class}.new(#{cast}(7))
|
41
|
+
EOF
|
42
|
+
assert_run_output("#{assert}\n", cls)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.define_shift_test_methods(cast, i, numeric_class, operator , assert)
|
47
|
+
define_method "test_#{numeric_class}_left_arithmetic_#{i}".to_sym do
|
48
|
+
cls, = compile(<<-EOF)
|
49
|
+
puts #{numeric_class}.new(#{cast}(5)) #{operator} 7
|
50
|
+
EOF
|
51
|
+
assert_run_output("#{assert}\n", cls)
|
52
|
+
end
|
53
|
+
define_method "test_#{numeric_class}_right_arithmetic_#{i}".to_sym do
|
54
|
+
cls, = compile(<<-EOF)
|
55
|
+
puts 5 #{operator} #{numeric_class}.new(#{cast}(7)).intValue
|
56
|
+
EOF
|
57
|
+
assert_run_output("#{assert}\n", cls)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
FIXNUM_TYPES.each do |numeric_class|
|
62
|
+
test_num = 0
|
63
|
+
cast = ('Integer' == numeric_class ? 'int' : numeric_class.downcase)
|
64
|
+
(OPERATORS + BITWISE_OPERATORS).each do |operator|
|
65
|
+
assert = eval "5#{operator}7"
|
66
|
+
define_test_methods(cast, test_num+=1, numeric_class, operator, assert)
|
67
|
+
end
|
68
|
+
SHIFT_OPERATORS.each do |operator|
|
69
|
+
assert = eval "5#{operator}7"
|
70
|
+
define_shift_test_methods(cast, test_num+=1, numeric_class, operator, assert)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# have to
|
75
|
+
FLOAT_TYPES.each do |numeric_class|
|
76
|
+
OPERATORS.each_with_index do |operator, i|
|
77
|
+
cast = numeric_class.downcase
|
78
|
+
assert = eval "5.0#{operator}7.0"
|
79
|
+
if numeric_class == 'Float' and operator == '/'
|
80
|
+
assert = '0.71428573'
|
81
|
+
end
|
82
|
+
define_test_methods(cast, i, numeric_class, operator, assert)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# Copyright (c) 2015 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
class ObjectExtensionsTest < Test::Unit::TestCase
|
17
|
+
|
18
|
+
def test_tap
|
19
|
+
cls, = compile(%q[
|
20
|
+
def taptest
|
21
|
+
StringBuilder.new("abc").tap do |sb|
|
22
|
+
sb.append("xyz")
|
23
|
+
StringBuilder.new("ijk")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
])
|
27
|
+
assert_equal("abcxyz", cls.taptest.toString)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_equals_each_side_is_evaluated_exactly_once
|
31
|
+
cls, = compile(%q[
|
32
|
+
def foo
|
33
|
+
puts "foo"
|
34
|
+
"1"
|
35
|
+
end
|
36
|
+
|
37
|
+
def bar
|
38
|
+
puts "bar"
|
39
|
+
"2"
|
40
|
+
end
|
41
|
+
|
42
|
+
puts foo==bar
|
43
|
+
puts nil==bar # right side is always evaluated exactly once, even in the presence of nil on the other side
|
44
|
+
puts bar==nil # left side is always evaluated exactly once, even in the presence of nil on the other side
|
45
|
+
])
|
46
|
+
assert_run_output("foo\nbar\nfalse\nbar\nfalse\nbar\nfalse\n", cls)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_equals_method_is_evaluated_as_necessary
|
50
|
+
cls, = compile(%q[
|
51
|
+
class Foo
|
52
|
+
attr_accessor counter:int
|
53
|
+
def equals(o:Object)
|
54
|
+
self.counter += 1
|
55
|
+
true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class Bar < Foo
|
60
|
+
end
|
61
|
+
|
62
|
+
class Baz < Foo
|
63
|
+
end
|
64
|
+
|
65
|
+
bar = Bar.new
|
66
|
+
baz = Baz.new
|
67
|
+
puts bar==baz
|
68
|
+
puts bar.counter
|
69
|
+
puts baz.counter
|
70
|
+
puts nil==bar
|
71
|
+
puts bar.counter
|
72
|
+
puts bar==nil
|
73
|
+
puts bar.counter
|
74
|
+
puts bar==bar
|
75
|
+
puts bar.counter
|
76
|
+
])
|
77
|
+
assert_run_output("true\n1\n0\nfalse\n1\ntrue\n2\ntrue\n3\n", cls)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_equals_method_is_evaluated_exactly_once_even_on_identical_objects
|
81
|
+
cls, = compile(%q[
|
82
|
+
class NaN
|
83
|
+
def equals(o:Object)
|
84
|
+
false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
nan = NaN.new
|
89
|
+
puts nan==nan
|
90
|
+
])
|
91
|
+
assert_run_output("false\n", cls)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_boxing_for_equals
|
95
|
+
cls, = compile(%q[
|
96
|
+
puts true==true
|
97
|
+
puts false==true
|
98
|
+
puts nil==true
|
99
|
+
|
100
|
+
obj = Boolean true
|
101
|
+
puts obj == true
|
102
|
+
puts obj == false
|
103
|
+
|
104
|
+
b = true
|
105
|
+
puts obj == b
|
106
|
+
puts obj == 1
|
107
|
+
puts true == obj
|
108
|
+
])
|
109
|
+
assert_run_output("true\nfalse\nfalse\ntrue\nfalse\ntrue\nfalse\ntrue\n", cls)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_boxing_for_numerics
|
113
|
+
cls, = compile(%q[
|
114
|
+
puts 1==Long.new(1)
|
115
|
+
puts Long(nil)==Long.new(1)
|
116
|
+
puts 1==Long.new(2)
|
117
|
+
puts nil == Long.new(2)
|
118
|
+
])
|
119
|
+
assert_run_output("true\nfalse\nfalse\nfalse\n", cls)
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|