mirah 0.1.2-java → 0.1.3-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +225 -0
- data/Rakefile +108 -315
- data/TODO.md +100 -0
- data/bin/bundler +16 -0
- data/bin/rake +16 -0
- data/dist/mirahc.jar +0 -0
- data/examples/appengine/Readme +0 -1
- data/examples/literals.mirah +17 -0
- data/examples/macros/string_each_char.mirah +1 -1
- data/lib/mirah.rb +11 -21
- data/lib/mirah/transform/transformer.rb +1 -2
- data/lib/mirah/util/class_loader.rb +1 -1
- data/lib/mirah/util/logging.rb +0 -63
- data/lib/mirah/util/process_errors.rb +1 -0
- data/lib/mirah/version.rb +1 -1
- data/{examples/simple_class.mirah~ → test/artifacts/jar_test.rb} +7 -11
- data/{lib/mirah/commands.rb → test/artifacts/jruby_test.rb} +8 -5
- data/test/core/typer_test.rb +29 -11
- data/test/core/util/argument_processor_test.rb +24 -23
- data/test/core/util/class_loader_test.rb +7 -4
- data/test/core/util/{compilation_state_test.rb → jvm_version_test.rb} +20 -16
- data/test/fixtures/org/foo/ImplicitClassRetAnno.java +4 -0
- data/test/fixtures/org/foo/IntAnno.java +9 -0
- data/test/jvm/annotations_test.rb +11 -11
- data/test/jvm/blocks_test.rb +16 -12
- data/test/jvm/constructors_test.rb +8 -8
- data/test/jvm/enumerable_test.rb +48 -24
- data/test/jvm/generics_test.rb +3 -7
- data/test/jvm/import_test.rb +14 -0
- data/test/jvm/interface_test.rb +9 -24
- data/test/jvm/jvm_commands_test.rb +22 -4
- data/test/jvm/jvm_compiler_test.rb +124 -79
- data/test/jvm/list_extensions_test.rb +1 -1
- data/test/jvm/macros_test.rb +67 -14
- data/test/jvm/main_method_test.rb +1 -1
- data/test/jvm/new_backend_test_helper.rb +100 -3
- data/{lib/mirah/jvm/types/bitescript_ext.rb → test/jvm/static_fields_test.rb} +22 -21
- data/test/mirrors/base_type_test.rb +4 -3
- data/test/mirrors/bytecode_mirror_test.rb +35 -15
- data/test/mirrors/generics_test.rb +14 -5
- data/test/mirrors/member_test.rb +2 -1
- data/test/mirrors/method_lookup_test.rb +18 -6
- data/test/mirrors/mirrors_test.rb +87 -20
- data/test/mirrors/simple_async_mirror_loader_test.rb +7 -3
- data/test/mirrors/simple_mirror_loader_test.rb +5 -5
- data/test/test_helper.rb +25 -1
- metadata +18 -78
- data/bin/mirahp +0 -27
- data/bin/mirahp.cmd +0 -16
- data/examples/Fib.class +0 -0
- data/javalib/mirah-bootstrap.jar +0 -0
- data/javalib/mirah-builtins.jar +0 -0
- data/javalib/mirah-compiler.jar +0 -0
- data/javalib/mirah-mirrors.jar +0 -0
- data/javalib/mirah-newast-transitional.jar +0 -0
- data/javalib/mirah-parser.jar +0 -0
- data/javalib/mirah-util.jar +0 -0
- data/lib/mirah/ast.rb +0 -43
- data/lib/mirah/ast/scope.rb +0 -262
- data/lib/mirah/commands/base.rb +0 -59
- data/lib/mirah/commands/compile.rb +0 -39
- data/lib/mirah/commands/parse.rb +0 -36
- data/lib/mirah/commands/run.rb +0 -78
- data/lib/mirah/generator.rb +0 -150
- data/lib/mirah/jvm/compiler.rb +0 -50
- data/lib/mirah/jvm/compiler/base.rb +0 -421
- data/lib/mirah/jvm/compiler/jvm_bytecode.rb +0 -1194
- data/lib/mirah/jvm/method_lookup.rb +0 -307
- data/lib/mirah/jvm/types.rb +0 -45
- data/lib/mirah/jvm/types/array_type.rb +0 -60
- data/lib/mirah/jvm/types/ast_ext.rb +0 -31
- data/lib/mirah/jvm/types/basic_types.rb +0 -41
- data/lib/mirah/jvm/types/block_type.rb +0 -15
- data/lib/mirah/jvm/types/boolean.rb +0 -70
- data/lib/mirah/jvm/types/enumerable.rb +0 -80
- data/lib/mirah/jvm/types/extensions.rb +0 -110
- data/lib/mirah/jvm/types/factory.rb +0 -830
- data/lib/mirah/jvm/types/floats.rb +0 -99
- data/lib/mirah/jvm/types/generic_type.rb +0 -72
- data/lib/mirah/jvm/types/implicit_nil_type.rb +0 -29
- data/lib/mirah/jvm/types/integers.rb +0 -131
- data/lib/mirah/jvm/types/interface_definition.rb +0 -20
- data/lib/mirah/jvm/types/intrinsics.rb +0 -385
- data/lib/mirah/jvm/types/literals.rb +0 -89
- data/lib/mirah/jvm/types/meta_type.rb +0 -54
- data/lib/mirah/jvm/types/methods.rb +0 -946
- data/lib/mirah/jvm/types/null_type.rb +0 -39
- data/lib/mirah/jvm/types/number.rb +0 -184
- data/lib/mirah/jvm/types/primitive_type.rb +0 -76
- data/lib/mirah/jvm/types/source_mirror.rb +0 -274
- data/lib/mirah/jvm/types/type.rb +0 -311
- data/lib/mirah/jvm/types/type_definition.rb +0 -72
- data/lib/mirah/jvm/types/void_type.rb +0 -19
- data/lib/mirah/util/compilation_state.rb +0 -60
- data/test/core/commands_test.rb +0 -89
- data/test/core/generator_test.rb +0 -26
- data/test/fixtures/org/foo/LowerCaseInnerClass$inner.class +0 -0
- data/test/fixtures/org/foo/LowerCaseInnerClass.class +0 -0
- data/test/jvm/bytecode_test_helper.rb +0 -193
- data/test/jvm/factory_test.rb +0 -28
- data/test/jvm/java_typer_test.rb +0 -283
data/test/jvm/generics_test.rb
CHANGED
@@ -14,12 +14,8 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
16
|
require 'test_helper'
|
17
|
-
require 'jvm/bytecode_test_helper'
|
18
|
-
class TestGenerics < Test::Unit::TestCase
|
19
17
|
|
20
|
-
|
21
|
-
parse_and_resolve_types name, code
|
22
|
-
end
|
18
|
+
class GenericsTest < Test::Unit::TestCase
|
23
19
|
|
24
20
|
def test_generics_calls_collections
|
25
21
|
cls, = compile(<<-EOF)
|
@@ -28,7 +24,7 @@ class TestGenerics < Test::Unit::TestCase
|
|
28
24
|
foo = ArrayList.new()
|
29
25
|
foo.add("first string")
|
30
26
|
foo.add("second string")
|
31
|
-
|
27
|
+
puts(foo.get(1).substring(2))
|
32
28
|
EOF
|
33
29
|
|
34
30
|
assert_output("cond string\n") do
|
@@ -45,7 +41,7 @@ class TestGenerics < Test::Unit::TestCase
|
|
45
41
|
foo.add("second string")
|
46
42
|
bar = ArrayList.new()
|
47
43
|
bar.add(foo)
|
48
|
-
|
44
|
+
puts(bar.get(0).get(1).substring(2))
|
49
45
|
EOF
|
50
46
|
|
51
47
|
assert_output("cond string\n") do
|
data/test/jvm/import_test.rb
CHANGED
@@ -78,4 +78,18 @@ class ImportTest < Test::Unit::TestCase
|
|
78
78
|
assert_equal(["1", "2", "3"], list.to_a)
|
79
79
|
end
|
80
80
|
|
81
|
+
def test_static_import_late_resolve
|
82
|
+
cls, = compile(<<-EOF)
|
83
|
+
import static StaticImports2.*
|
84
|
+
doFoo()
|
85
|
+
|
86
|
+
class StaticImports2
|
87
|
+
def self.doFoo
|
88
|
+
puts :hi
|
89
|
+
end
|
90
|
+
end
|
91
|
+
EOF
|
92
|
+
assert_output("hi\n") { cls.main(nil) }
|
93
|
+
end
|
94
|
+
|
81
95
|
end
|
data/test/jvm/interface_test.rb
CHANGED
@@ -83,31 +83,16 @@ class InterfaceTest < Test::Unit::TestCase
|
|
83
83
|
EOF
|
84
84
|
end
|
85
85
|
|
86
|
-
def
|
86
|
+
def test_interface_implementation_with_array_params_doesnt_requires_type_information
|
87
87
|
interface, a_impl = compile(<<-EOF)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
class ExplicitArrImpl implements InterfaceWithArrays
|
93
|
-
def blah(s:String[]) s.length ; end
|
94
|
-
def arr(messages:String[]) blah messages ; end
|
95
|
-
end
|
96
|
-
EOF
|
97
|
-
|
98
|
-
# this is the current behavior. I think we should fix it. nh
|
99
|
-
error = assert_raises Mirah::MirahError do
|
100
|
-
interface, a_impl = compile(<<-EOF)
|
101
|
-
interface InterfaceWithArrays
|
102
|
-
def arr(messages:String[]):int; end
|
103
|
-
end
|
88
|
+
interface InterfaceWithArrays
|
89
|
+
def arr(messages:String[]):int; end
|
90
|
+
end
|
104
91
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
111
|
-
assert_equal "Cannot find instance method blah(java.lang.String) on ImplicitArrImpl", error.message
|
92
|
+
class ImplicitArrImpl implements InterfaceWithArrays
|
93
|
+
def blah(s:String[]) s.length ; end
|
94
|
+
def arr(messages) blah messages ; end
|
95
|
+
end
|
96
|
+
EOF
|
112
97
|
end
|
113
98
|
end
|
@@ -16,19 +16,37 @@ require 'test_helper'
|
|
16
16
|
|
17
17
|
|
18
18
|
class JVMCommandsTest < Test::Unit::TestCase
|
19
|
+
|
19
20
|
def test_dash_e_eval
|
20
21
|
assert_output "1\n" do
|
21
|
-
Mirah
|
22
|
+
Mirah.run('-e','puts 1')
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
26
|
+
def test_force_verbose_has_logging
|
27
|
+
out = capture_output do
|
28
|
+
Mirah.run('-V', '-e','puts 1')
|
29
|
+
end
|
30
|
+
assert out.include? "Finished class DashE"
|
31
|
+
end
|
32
|
+
|
25
33
|
def test_runtime_classpath_modifications
|
26
34
|
assert_output "1234\n" do
|
27
|
-
Mirah
|
35
|
+
Mirah.run('-cp', FIXTURE_TEST_DEST,
|
36
|
+
'-e',
|
37
|
+
'import org.foo.LowerCaseInnerClass
|
38
|
+
puts LowerCaseInnerClass.inner.field'
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_dash_c_is_deprecated
|
44
|
+
assert_output "WARN: option -c is deprecated.\n1234\n" do
|
45
|
+
Mirah.run('-c', FIXTURE_TEST_DEST,
|
28
46
|
'-e',
|
29
47
|
'import org.foo.LowerCaseInnerClass
|
30
|
-
puts LowerCaseInnerClass.inner.field'
|
31
|
-
)
|
48
|
+
puts LowerCaseInnerClass.inner.field'
|
49
|
+
)
|
32
50
|
end
|
33
51
|
end
|
34
52
|
end
|
@@ -34,6 +34,14 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
34
34
|
assert_equal(3.0, cls.foo)
|
35
35
|
end
|
36
36
|
|
37
|
+
def test_unary_negation
|
38
|
+
cls, = compile("def foo; a = 1; -a; end")
|
39
|
+
assert_equal(-1, cls.foo)
|
40
|
+
|
41
|
+
cls, = compile("def foo; a = 1; 1 + -a; end")
|
42
|
+
assert_equal(0, cls.foo)
|
43
|
+
end
|
44
|
+
|
37
45
|
def test_subtraction
|
38
46
|
cls, = compile("def foo; a = 3; b = 2; a - b; end")
|
39
47
|
assert_equal(1, cls.foo)
|
@@ -101,6 +109,25 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
101
109
|
assert_equal(6, cls.foo)
|
102
110
|
end
|
103
111
|
|
112
|
+
def test_negate
|
113
|
+
cls, = compile("def foo; a = 5; -a; end")
|
114
|
+
assert_equal(-5, cls.foo)
|
115
|
+
cls, = compile("def foo; a = 7.5; -a; end")
|
116
|
+
assert_equal(-7.5, cls.foo)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_nan
|
120
|
+
cls, = compile("def foo(a:double); if a < 0 then 1 else 2 end; end")
|
121
|
+
assert_equal(1, cls.foo(-1))
|
122
|
+
assert_equal(2, cls.foo(0))
|
123
|
+
assert_equal(2, cls.foo(java.lang.Double::NaN))
|
124
|
+
|
125
|
+
cls, = compile("def foo(a:double); a > 0 ? 1 : 2; end")
|
126
|
+
assert_equal(1, cls.foo(1))
|
127
|
+
assert_equal(2, cls.foo(-1))
|
128
|
+
assert_equal(2, cls.foo(java.lang.Double::NaN))
|
129
|
+
end
|
130
|
+
|
104
131
|
def test_return
|
105
132
|
cls, = compile("def foo; return 1; end")
|
106
133
|
assert_equal(1, cls.foo)
|
@@ -193,9 +220,11 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
193
220
|
end
|
194
221
|
|
195
222
|
def test_object_array
|
196
|
-
|
197
|
-
|
198
|
-
|
223
|
+
pend_on_jruby("1.7.13") do
|
224
|
+
cls, = compile("import java.lang.Object;def foo; a = Object[2];end")
|
225
|
+
assert_equal(Java::JavaLang::Object[].java_class, cls.foo.class.java_class)
|
226
|
+
assert_equal([nil, nil], cls.foo.to_a)
|
227
|
+
end
|
199
228
|
end
|
200
229
|
|
201
230
|
def test_void_selfcall
|
@@ -218,12 +247,12 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
218
247
|
a, b = compile(<<-EOF)
|
219
248
|
class VoidBase
|
220
249
|
def foo:void
|
221
|
-
|
250
|
+
puts "foo"
|
222
251
|
end
|
223
252
|
end
|
224
253
|
class VoidChain < VoidBase
|
225
254
|
def bar:void
|
226
|
-
|
255
|
+
puts "bar"
|
227
256
|
end
|
228
257
|
|
229
258
|
def self.foobar
|
@@ -241,12 +270,12 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
241
270
|
end
|
242
271
|
|
243
272
|
def test_class_name_from_file_with_underscore
|
244
|
-
foo, = compile("
|
273
|
+
foo, = compile("puts 'blah'", :name => 'class_name_test.mirah')
|
245
274
|
assert_equal('ClassNameTest', foo.java_class.name)
|
246
275
|
end
|
247
276
|
|
248
277
|
def test_class_name_from_file_with_dash
|
249
|
-
foo, = compile("
|
278
|
+
foo, = compile("puts 'blah'", :name => 'class-dash-test.mirah')
|
250
279
|
assert_equal('ClassDashTest', foo.java_class.name)
|
251
280
|
end
|
252
281
|
|
@@ -415,25 +444,25 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
415
444
|
|
416
445
|
def test_loop
|
417
446
|
cls, = compile(
|
418
|
-
'def foo(a:int);while a > 0; a -= 1;
|
447
|
+
'def foo(a:int);while a > 0; a -= 1; puts ".";end;end')
|
419
448
|
assert_equal('', capture_output{cls.foo(0)})
|
420
449
|
assert_equal(".\n", capture_output{cls.foo(1)})
|
421
450
|
assert_equal(".\n.\n", capture_output{cls.foo(2)})
|
422
451
|
|
423
452
|
cls, = compile(
|
424
|
-
'def foo(a:int);begin;a -= 1;
|
453
|
+
'def foo(a:int);begin;a -= 1; puts ".";end while a > 0;end')
|
425
454
|
assert_equal(".\n", capture_output{cls.foo(0)})
|
426
455
|
assert_equal(".\n", capture_output{cls.foo(1)})
|
427
456
|
assert_equal(".\n.\n", capture_output{cls.foo(2)})
|
428
457
|
|
429
458
|
cls, = compile(
|
430
|
-
'def foo(a:int);until a <= 0; a -= 1;
|
459
|
+
'def foo(a:int);until a <= 0; a -= 1; puts ".";end;end')
|
431
460
|
assert_equal('', capture_output{cls.foo(0)})
|
432
461
|
assert_equal(".\n", capture_output{cls.foo(1)})
|
433
462
|
assert_equal(".\n.\n", capture_output{cls.foo(2)})
|
434
463
|
|
435
464
|
cls, = compile(
|
436
|
-
'def foo(a:int);begin;a -= 1;
|
465
|
+
'def foo(a:int);begin;a -= 1; puts ".";end until a <= 0;end')
|
437
466
|
assert_equal(".\n", capture_output{cls.foo(0)})
|
438
467
|
assert_equal(".\n", capture_output{cls.foo(1)})
|
439
468
|
assert_equal(".\n.\n", capture_output{cls.foo(2)})
|
@@ -857,7 +886,7 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
857
886
|
def test_and
|
858
887
|
cls, = compile(<<-EOF)
|
859
888
|
def bool(n:String, x:boolean)
|
860
|
-
|
889
|
+
puts n
|
861
890
|
x
|
862
891
|
end
|
863
892
|
|
@@ -866,7 +895,7 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
866
895
|
end
|
867
896
|
|
868
897
|
def str(n:String, x:String)
|
869
|
-
|
898
|
+
puts n
|
870
899
|
x
|
871
900
|
end
|
872
901
|
|
@@ -976,7 +1005,7 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
976
1005
|
def test_or
|
977
1006
|
cls, = compile(<<-EOF)
|
978
1007
|
def bool(n:String, x:boolean)
|
979
|
-
|
1008
|
+
puts n
|
980
1009
|
x
|
981
1010
|
end
|
982
1011
|
|
@@ -985,7 +1014,7 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
985
1014
|
end
|
986
1015
|
|
987
1016
|
def str(n:String, x:String)
|
988
|
-
|
1017
|
+
puts n
|
989
1018
|
x
|
990
1019
|
end
|
991
1020
|
|
@@ -1097,45 +1126,48 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1097
1126
|
end
|
1098
1127
|
|
1099
1128
|
def test_op_elem_assign
|
1100
|
-
|
1101
|
-
class Foo4
|
1102
|
-
def initialize
|
1103
|
-
@i = -1
|
1104
|
-
end
|
1129
|
+
pend_on_jruby("1.7.13") do
|
1105
1130
|
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1131
|
+
foo, = compile(<<-EOF)
|
1132
|
+
class Foo4
|
1133
|
+
def initialize
|
1134
|
+
@i = -1
|
1135
|
+
end
|
1109
1136
|
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1137
|
+
def i
|
1138
|
+
@i += 1
|
1139
|
+
end
|
1113
1140
|
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1141
|
+
def a
|
1142
|
+
@a
|
1143
|
+
end
|
1117
1144
|
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1145
|
+
def a=(a:String[])
|
1146
|
+
@a = a
|
1147
|
+
end
|
1121
1148
|
|
1122
|
-
|
1123
|
-
|
1149
|
+
def foo(x:String)
|
1150
|
+
a[i] ||= x
|
1151
|
+
end
|
1152
|
+
|
1153
|
+
def bar(x:String)
|
1154
|
+
a[i] &&= x
|
1155
|
+
end
|
1124
1156
|
end
|
1125
|
-
|
1126
|
-
EOF
|
1157
|
+
EOF
|
1127
1158
|
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1159
|
+
f = foo.new
|
1160
|
+
f.a_set([nil, nil, nil].to_java(:string))
|
1161
|
+
assert_equal(nil, f.bar("x"))
|
1162
|
+
assert_equal([nil, nil, nil], f.a.to_a)
|
1163
|
+
assert_equal("x", f.foo("x"))
|
1164
|
+
assert_equal([nil, "x", nil], f.a.to_a)
|
1165
|
+
end
|
1134
1166
|
end
|
1135
1167
|
|
1136
1168
|
def test_literal_array
|
1137
1169
|
cls, = compile(<<-EOF)
|
1138
|
-
def foo;
|
1170
|
+
def foo; puts "hello"; nil; end
|
1139
1171
|
def expr
|
1140
1172
|
[foo]
|
1141
1173
|
end
|
@@ -1177,7 +1209,7 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1177
1209
|
/foo/.split('barfoobaz')
|
1178
1210
|
end
|
1179
1211
|
def puts
|
1180
|
-
|
1212
|
+
puts split
|
1181
1213
|
end
|
1182
1214
|
EOF
|
1183
1215
|
|
@@ -1202,8 +1234,8 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1202
1234
|
end
|
1203
1235
|
end
|
1204
1236
|
|
1205
|
-
|
1206
|
-
|
1237
|
+
puts A1.new.foo("Hi")
|
1238
|
+
puts B1.new.foo("There")
|
1207
1239
|
EOF
|
1208
1240
|
|
1209
1241
|
assert_output("Hi\nThere\n") do
|
@@ -1241,7 +1273,7 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1241
1273
|
def test_optional_args
|
1242
1274
|
cls, = compile(<<-EOF)
|
1243
1275
|
def foo(a:int, b:int = 1, c:int = 2)
|
1244
|
-
|
1276
|
+
puts a; puts b; puts c
|
1245
1277
|
end
|
1246
1278
|
foo(0)
|
1247
1279
|
foo(0,0)
|
@@ -1254,7 +1286,7 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1254
1286
|
|
1255
1287
|
def test_field_read
|
1256
1288
|
cls, = compile(<<-EOF)
|
1257
|
-
|
1289
|
+
puts System.out.getClass.getName
|
1258
1290
|
EOF
|
1259
1291
|
assert_output("java.io.PrintStream\n") do
|
1260
1292
|
cls.main([].to_java :String)
|
@@ -1457,10 +1489,10 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1457
1489
|
abstract_class, concrete_class = compile(<<-EOF)
|
1458
1490
|
abstract class Abstract
|
1459
1491
|
abstract def foo:void; end
|
1460
|
-
def bar;
|
1492
|
+
def bar; puts "bar"; end
|
1461
1493
|
end
|
1462
1494
|
class Concrete < Abstract
|
1463
|
-
def foo;
|
1495
|
+
def foo; puts :foo; end
|
1464
1496
|
end
|
1465
1497
|
EOF
|
1466
1498
|
|
@@ -1477,7 +1509,7 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1477
1509
|
def test_return_void
|
1478
1510
|
script, = compile(<<-EOF)
|
1479
1511
|
def foo:void
|
1480
|
-
|
1512
|
+
puts :hi
|
1481
1513
|
return
|
1482
1514
|
end
|
1483
1515
|
EOF
|
@@ -1533,10 +1565,10 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1533
1565
|
begin
|
1534
1566
|
raise "Foo"
|
1535
1567
|
rescue => b
|
1536
|
-
|
1537
|
-
|
1568
|
+
puts a
|
1569
|
+
puts b.getMessage
|
1538
1570
|
end
|
1539
|
-
|
1571
|
+
puts b
|
1540
1572
|
end
|
1541
1573
|
EOF
|
1542
1574
|
|
@@ -1594,7 +1626,7 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1594
1626
|
|
1595
1627
|
def test_covariant_arrays
|
1596
1628
|
cls, = compile(<<-EOF)
|
1597
|
-
|
1629
|
+
puts java::util::Arrays.toString(String[5])
|
1598
1630
|
EOF
|
1599
1631
|
|
1600
1632
|
assert_output("[null, null, null, null, null]\n") do
|
@@ -1604,7 +1636,7 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1604
1636
|
|
1605
1637
|
def test_getClass_on_object_array
|
1606
1638
|
cls, = compile(<<-EOF)
|
1607
|
-
|
1639
|
+
puts Object[0].getClass.getName
|
1608
1640
|
EOF
|
1609
1641
|
|
1610
1642
|
assert_output("[Ljava.lang.Object;\n") do
|
@@ -1625,7 +1657,7 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1625
1657
|
|
1626
1658
|
cls, = compile(<<-EOF)
|
1627
1659
|
a = nil
|
1628
|
-
|
1660
|
+
puts Object(a)
|
1629
1661
|
EOF
|
1630
1662
|
|
1631
1663
|
assert_output("null\n") do
|
@@ -1636,7 +1668,7 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1636
1668
|
def test_long_generation
|
1637
1669
|
cls, = compile(<<-EOF)
|
1638
1670
|
c = 2_000_000_000_000
|
1639
|
-
|
1671
|
+
puts c
|
1640
1672
|
EOF
|
1641
1673
|
end
|
1642
1674
|
|
@@ -1649,14 +1681,14 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1649
1681
|
end
|
1650
1682
|
|
1651
1683
|
def test_bool_equality
|
1652
|
-
cls, = compile("
|
1684
|
+
cls, = compile("puts true == false")
|
1653
1685
|
assert_output("false\n") do
|
1654
1686
|
cls.main(nil)
|
1655
1687
|
end
|
1656
1688
|
end
|
1657
1689
|
|
1658
1690
|
def test_bool_inequality
|
1659
|
-
cls, = compile("
|
1691
|
+
cls, = compile("puts true != false")
|
1660
1692
|
assert_output("true\n") do
|
1661
1693
|
cls.main(nil)
|
1662
1694
|
end
|
@@ -1664,9 +1696,11 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1664
1696
|
|
1665
1697
|
def test_field_setter_with_nil
|
1666
1698
|
cls, = compile(<<-EOF)
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1699
|
+
class FieldSetter
|
1700
|
+
attr_accessor field: String
|
1701
|
+
end
|
1702
|
+
a = FieldSetter.new
|
1703
|
+
a.field = nil
|
1670
1704
|
print "OK"
|
1671
1705
|
EOF
|
1672
1706
|
|
@@ -1763,28 +1797,39 @@ class JVMCompilerTest < Test::Unit::TestCase
|
|
1763
1797
|
end
|
1764
1798
|
end
|
1765
1799
|
|
1766
|
-
def
|
1800
|
+
def test_incompatible_meta_change
|
1767
1801
|
cls, = compile(<<-EOF)
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1802
|
+
class A < B
|
1803
|
+
def foo(a:Object)
|
1804
|
+
a.kind_of?(A)
|
1805
|
+
end
|
1806
|
+
end
|
1771
1807
|
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1808
|
+
class B
|
1809
|
+
end
|
1810
|
+
EOF
|
1811
|
+
|
1812
|
+
a = cls.new
|
1813
|
+
assert(a.foo(a))
|
1775
1814
|
end
|
1776
1815
|
|
1777
|
-
def
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1816
|
+
def test_local_method_conflict
|
1817
|
+
cls, arg = compile(<<-EOF)
|
1818
|
+
def a; ArgType.new; end
|
1819
|
+
def foo(a:ArgType):void
|
1820
|
+
x = Object[ a ? a.bar : 0]
|
1821
|
+
puts x.length
|
1822
|
+
end
|
1823
|
+
|
1824
|
+
class ArgType
|
1825
|
+
def bar
|
1826
|
+
2
|
1827
|
+
end
|
1828
|
+
end
|
1782
1829
|
EOF
|
1783
1830
|
|
1784
|
-
assert_output
|
1785
|
-
|
1786
|
-
end
|
1787
|
-
}
|
1831
|
+
assert_output("0\n") { cls.foo(nil)}
|
1832
|
+
assert_output("2\n") { cls.foo(arg.new)}
|
1788
1833
|
end
|
1789
1834
|
|
1790
1835
|
end
|