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
@@ -15,50 +15,51 @@
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
17
|
class ArgumentProcessorTest < Test::Unit::TestCase
|
18
|
-
|
18
|
+
java_import 'org.mirah.tool.MirahArguments'
|
19
19
|
def test_arg_dash_v_prints_version_and_has_exit_0
|
20
|
-
|
21
|
-
processor = Mirah::Util::ArgumentProcessor.new state, ["-v"]
|
20
|
+
arg_processor = MirahArguments.new
|
22
21
|
|
23
22
|
assert_output "Mirah v#{Mirah::VERSION}\n" do
|
24
|
-
|
23
|
+
arg_processor.apply_args(["-v"])
|
25
24
|
end
|
26
25
|
|
27
|
-
assert
|
28
|
-
assert_equal 0,
|
26
|
+
assert arg_processor.exit?
|
27
|
+
assert_equal 0, arg_processor.exit_status
|
29
28
|
end
|
30
29
|
|
31
30
|
|
32
31
|
def test_on_invalid_arg_prints_error_and_exits_1
|
33
|
-
|
34
|
-
processor = Mirah::Util::ArgumentProcessor.new state, ["--some-arg"]
|
32
|
+
arg_processor = MirahArguments.new
|
35
33
|
|
36
|
-
assert_output "
|
37
|
-
|
34
|
+
assert_output "Unrecognized flag: --some-arg\n" do
|
35
|
+
arg_processor.apply_args(["--some-arg"])
|
38
36
|
end
|
39
37
|
|
40
|
-
assert
|
41
|
-
assert_equal 1,
|
38
|
+
assert arg_processor.exit?
|
39
|
+
assert_equal 1, arg_processor.exit_status
|
42
40
|
end
|
43
41
|
|
44
|
-
def
|
42
|
+
def test_arg_bootclasspath_sets_bootclasspath_with_absolute_paths
|
45
43
|
path = "class:path"
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
arg_processor = MirahArguments.new
|
45
|
+
|
46
|
+
arg_processor.apply_args ["--bootclasspath", path]
|
49
47
|
|
50
|
-
assert_equal path
|
48
|
+
assert_equal path.split(":").map{|p|"file:%s" % File.expand_path(p) }.join(":"),
|
49
|
+
arg_processor.real_bootclasspath.map{|u| u.to_s }.join(":")
|
51
50
|
end
|
52
51
|
|
53
52
|
def test_dash_h_prints_help_and_exits
|
54
|
-
|
55
|
-
processor = Mirah::Util::ArgumentProcessor.new state, ["-h"]
|
53
|
+
arg_processor = MirahArguments.new
|
56
54
|
|
57
|
-
|
58
|
-
|
55
|
+
usage_message = capture_output do
|
56
|
+
arg_processor.apply_args ["-h"]
|
59
57
|
end
|
60
58
|
|
61
|
-
assert
|
62
|
-
|
59
|
+
assert usage_message.include? 'mirahc [flags] <files or -e SCRIPT>'
|
60
|
+
assert usage_message.include? '-h, --help'
|
61
|
+
|
62
|
+
assert arg_processor.exit?
|
63
|
+
assert_equal 0, arg_processor.exit_status
|
63
64
|
end
|
64
65
|
end
|
@@ -15,20 +15,23 @@
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
17
|
class ClassLoaderTest < Test::Unit::TestCase
|
18
|
+
java_import 'org.mirah.MirahClassLoader'
|
19
|
+
java_import 'org.mirah.IsolatedResourceLoader'
|
20
|
+
|
18
21
|
FIXTURES = File.expand_path("#{__FILE__}/../../../fixtures/") +"/"
|
19
22
|
A_CLASS = "#{FIXTURES}org/foo/A.class"
|
20
23
|
|
21
24
|
def test_mirah_class_loader_find_class_in_map_successful
|
22
25
|
class_map = {
|
23
|
-
'org.foo.A' => Mirah::Util
|
26
|
+
'org.foo.A' => Mirah::Util.binary_string(File.open(A_CLASS, 'rb') {|f| f.read })
|
24
27
|
}
|
25
|
-
class_loader =
|
28
|
+
class_loader = MirahClassLoader.new nil, class_map
|
26
29
|
cls = class_loader.load_class 'org.foo.A'
|
27
30
|
assert_equal 'org.foo.A', cls.name
|
28
31
|
end
|
29
32
|
|
30
33
|
def test_mirah_class_loader_w_missing_class_raises_class_not_found
|
31
|
-
class_loader =
|
34
|
+
class_loader = MirahClassLoader.new nil, {}
|
32
35
|
|
33
36
|
begin
|
34
37
|
klass = class_loader.find_class 'org.doesnt.exist.Class'
|
@@ -39,7 +42,7 @@ class ClassLoaderTest < Test::Unit::TestCase
|
|
39
42
|
end
|
40
43
|
|
41
44
|
def test_isolated_resource_loader_only_finds_resources_given_to_it
|
42
|
-
loader =
|
45
|
+
loader = IsolatedResourceLoader.new [java.net.URL.new("file:#{FIXTURES}")]
|
43
46
|
url = loader.get_resource "my.properties"
|
44
47
|
assert_not_nil url
|
45
48
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c)
|
1
|
+
# Copyright (c) 2014 The Mirah project authors. All Rights Reserved.
|
2
2
|
# All contributing project authors may be found in the NOTICE file.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -14,25 +14,29 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
|
18
|
+
|
19
|
+
class JvmVersionTest < Test::Unit::TestCase
|
20
|
+
java_import 'org.mirah.jvm.compiler.JvmVersion'
|
21
|
+
java_import 'org.objectweb.asm.Opcodes'
|
22
|
+
|
19
23
|
def test_defaults_to_current_java
|
20
|
-
|
24
|
+
jvm_version = JvmVersion.new
|
21
25
|
spec_version = ENV_JAVA['java.specification.version']
|
22
|
-
assert_equal spec_version,
|
23
|
-
assert_equal
|
26
|
+
assert_equal spec_version, jvm_version.version_string
|
27
|
+
assert_equal opcode(spec_version), jvm_version.bytecode_version
|
24
28
|
end
|
25
|
-
|
26
|
-
%w[1.4 1.5 1.6 1.7 1.8]
|
29
|
+
|
30
|
+
supported_versions = %w[1.4 1.5 1.6 1.7 1.8]
|
31
|
+
supported_versions.each do |version|
|
27
32
|
define_method "test_setting_version_to_#{version.tr '.', '_'}" do
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
+
jvm_version = JvmVersion.new version
|
34
|
+
assert_equal version, jvm_version.version_string
|
35
|
+
assert_equal opcode(version), jvm_version.bytecode_version
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
|
-
def
|
36
|
-
|
39
|
+
def opcode spec_version
|
40
|
+
Opcodes.const_get("V#{spec_version.sub('.','_')}")
|
37
41
|
end
|
38
|
-
end
|
42
|
+
end
|
@@ -38,21 +38,21 @@ class AnnotationsTest < Test::Unit::TestCase
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_annotation_with_an_integer
|
41
|
-
jruby_method = Java::OrgJrubyAnno::JRubyMethod.java_class
|
42
|
-
|
43
41
|
cls, = compile(<<-EOF)
|
44
|
-
import org.
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
$JRubyMethod["name" => ["bar"], "optional" => 1]
|
50
|
-
def bar(baz:int)
|
42
|
+
import org.foo.IntAnno
|
43
|
+
class IntValAnnotation
|
44
|
+
$IntAnno[name: "bar", value: 1]
|
45
|
+
def bar
|
46
|
+
end
|
51
47
|
end
|
48
|
+
method = IntValAnnotation.class.getMethod("bar")
|
49
|
+
anno = method.getAnnotation(IntAnno.class)
|
50
|
+
puts anno.value
|
52
51
|
EOF
|
53
|
-
method_annotation = cls.java_class.java_method('bar', :int).annotation(jruby_method)
|
54
52
|
|
55
|
-
|
53
|
+
assert_output "1\n" do
|
54
|
+
cls.main nil
|
55
|
+
end
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
data/test/jvm/blocks_test.rb
CHANGED
@@ -61,13 +61,13 @@ class BlocksTest < Test::Unit::TestCase
|
|
61
61
|
def test_simple_block
|
62
62
|
cls, = compile(<<-EOF)
|
63
63
|
thread = Thread.new do
|
64
|
-
|
64
|
+
puts "Hello"
|
65
65
|
end
|
66
66
|
begin
|
67
67
|
thread.run
|
68
68
|
thread.join
|
69
69
|
rescue
|
70
|
-
|
70
|
+
puts "Uh Oh!"
|
71
71
|
end
|
72
72
|
EOF
|
73
73
|
assert_output("Hello\n") do
|
@@ -85,7 +85,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
85
85
|
end
|
86
86
|
|
87
87
|
o = MyObservable.new
|
88
|
-
o.addObserver {|x, a|
|
88
|
+
o.addObserver {|x, a| puts a}
|
89
89
|
o.notifyObservers("Hello Observer")
|
90
90
|
EOF
|
91
91
|
assert_output("Hello Observer\n") do
|
@@ -98,14 +98,14 @@ class BlocksTest < Test::Unit::TestCase
|
|
98
98
|
def foo
|
99
99
|
a = "Hello"
|
100
100
|
thread = Thread.new do
|
101
|
-
|
101
|
+
puts a
|
102
102
|
end
|
103
103
|
begin
|
104
104
|
a = a + " Closures"
|
105
105
|
thread.run
|
106
106
|
thread.join
|
107
107
|
rescue
|
108
|
-
|
108
|
+
puts "Uh Oh!"
|
109
109
|
end
|
110
110
|
return
|
111
111
|
end
|
@@ -156,7 +156,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
156
156
|
String(a).compareToIgnoreCase(String(b))
|
157
157
|
end
|
158
158
|
end
|
159
|
-
list.each {|x|
|
159
|
+
list.each {|x| puts x }
|
160
160
|
EOF
|
161
161
|
|
162
162
|
assert_output("a\nABC\nb\nCats\n") do
|
@@ -186,14 +186,14 @@ class BlocksTest < Test::Unit::TestCase
|
|
186
186
|
import java.util.concurrent.Callable
|
187
187
|
def foo c:Callable
|
188
188
|
# throws Exception
|
189
|
-
|
189
|
+
puts c.call
|
190
190
|
end
|
191
191
|
begin
|
192
192
|
foo do
|
193
193
|
"an object"
|
194
194
|
end
|
195
195
|
rescue
|
196
|
-
|
196
|
+
puts "never get here"
|
197
197
|
end
|
198
198
|
EOF
|
199
199
|
assert_output("an object\n") do
|
@@ -205,13 +205,13 @@ class BlocksTest < Test::Unit::TestCase
|
|
205
205
|
cls, = compile(<<-EOF)
|
206
206
|
def foo(x:String):void
|
207
207
|
thread = Thread.new do
|
208
|
-
|
208
|
+
puts "Hello \#{x}"
|
209
209
|
end
|
210
210
|
begin
|
211
211
|
thread.run
|
212
212
|
thread.join
|
213
213
|
rescue
|
214
|
-
|
214
|
+
puts "Uh Oh!"
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
@@ -231,7 +231,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
231
231
|
b.call
|
232
232
|
end
|
233
233
|
def bar
|
234
|
-
foo {
|
234
|
+
foo {puts "Hi"}
|
235
235
|
end
|
236
236
|
EOF
|
237
237
|
assert_output("Hi\n") do
|
@@ -251,7 +251,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
251
251
|
end
|
252
252
|
|
253
253
|
def test_block_impling_interface_w_multiple_methods
|
254
|
-
|
254
|
+
begin
|
255
255
|
parse_and_type(<<-CODE)
|
256
256
|
interface RunOrRun2 do
|
257
257
|
def run:void;end
|
@@ -267,6 +267,10 @@ class BlocksTest < Test::Unit::TestCase
|
|
267
267
|
1
|
268
268
|
end
|
269
269
|
CODE
|
270
|
+
rescue => ex
|
271
|
+
assert_match /multiple abstract/i, ex.message
|
272
|
+
else
|
273
|
+
fail "No exception raised"
|
270
274
|
end
|
271
275
|
end
|
272
276
|
|
@@ -16,7 +16,7 @@
|
|
16
16
|
class ConstructorsTest < Test::Unit::TestCase
|
17
17
|
def test_constructor
|
18
18
|
cls, = compile(
|
19
|
-
"class InitializeTest;def initialize;
|
19
|
+
"class InitializeTest;def initialize;puts 'Constructed';end;end")
|
20
20
|
assert_output("Constructed\n") do
|
21
21
|
cls.new
|
22
22
|
end
|
@@ -57,14 +57,14 @@ class ConstructorsTest < Test::Unit::TestCase
|
|
57
57
|
sc_a, sc_b = compile(<<-EOF)
|
58
58
|
class SC_A
|
59
59
|
def initialize(a:int)
|
60
|
-
|
60
|
+
puts "A"
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
class SC_B < SC_A
|
65
65
|
def initialize
|
66
66
|
super(0)
|
67
|
-
|
67
|
+
puts "B"
|
68
68
|
end
|
69
69
|
end
|
70
70
|
EOF
|
@@ -77,14 +77,14 @@ class ConstructorsTest < Test::Unit::TestCase
|
|
77
77
|
sc_a, sc_b = compile(<<-EOF)
|
78
78
|
class SuperCA
|
79
79
|
def initialize(a: int)
|
80
|
-
|
80
|
+
puts "A \#{a}"
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
class SuperCB < SuperCA
|
85
85
|
def initialize a: int
|
86
86
|
super
|
87
|
-
|
87
|
+
puts "B \#{a}"
|
88
88
|
end
|
89
89
|
end
|
90
90
|
EOF
|
@@ -105,7 +105,7 @@ class ConstructorsTest < Test::Unit::TestCase
|
|
105
105
|
end
|
106
106
|
EOF
|
107
107
|
end
|
108
|
-
|
108
|
+
assert_match /Can.*t find.* method (SuperCA\.)?initialize\(\)/, error.message
|
109
109
|
end
|
110
110
|
|
111
111
|
|
@@ -118,7 +118,7 @@ class ConstructorsTest < Test::Unit::TestCase
|
|
118
118
|
end
|
119
119
|
EOF
|
120
120
|
end
|
121
|
-
|
121
|
+
assert_match /Can.*t find( instance)? method (java.util.ArrayList\.)?initialize\(java.lang.String\)/, error.message
|
122
122
|
end
|
123
123
|
|
124
124
|
def test_empty_constructor
|
@@ -141,7 +141,7 @@ class ConstructorsTest < Test::Unit::TestCase
|
|
141
141
|
t.join
|
142
142
|
rescue InterruptedException
|
143
143
|
end
|
144
|
-
|
144
|
+
puts 'ok'
|
145
145
|
end
|
146
146
|
end
|
147
147
|
EOF
|
data/test/jvm/enumerable_test.rb
CHANGED
@@ -13,6 +13,8 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
+
require 'test_helper'
|
17
|
+
|
16
18
|
class EnumerableTest < Test::Unit::TestCase
|
17
19
|
def test_for_in_int_array
|
18
20
|
cls, = compile(<<-EOF)
|
@@ -44,7 +46,7 @@ class EnumerableTest < Test::Unit::TestCase
|
|
44
46
|
cls, = compile(<<-EOF)
|
45
47
|
def foo(a:Iterable)
|
46
48
|
a.each do |x|
|
47
|
-
|
49
|
+
puts x
|
48
50
|
end
|
49
51
|
end
|
50
52
|
EOF
|
@@ -63,7 +65,7 @@ class EnumerableTest < Test::Unit::TestCase
|
|
63
65
|
import java.util.ArrayList
|
64
66
|
def foo(a:ArrayList)
|
65
67
|
a.each do |x|
|
66
|
-
|
68
|
+
puts x
|
67
69
|
end
|
68
70
|
end
|
69
71
|
EOF
|
@@ -80,7 +82,7 @@ class EnumerableTest < Test::Unit::TestCase
|
|
80
82
|
def test_each_int_arry
|
81
83
|
cls, = compile(<<-EOF)
|
82
84
|
def foo(a:int[])
|
83
|
-
a.each {|x| x += 1;
|
85
|
+
a.each {|x| x += 1;puts x; redo if x == 2}
|
84
86
|
end
|
85
87
|
EOF
|
86
88
|
|
@@ -114,7 +116,7 @@ class EnumerableTest < Test::Unit::TestCase
|
|
114
116
|
def test_downto
|
115
117
|
cls, = compile(<<-EOF)
|
116
118
|
def foo(i:int)
|
117
|
-
i.downto(1) {|x|
|
119
|
+
i.downto(1) {|x| puts x }
|
118
120
|
end
|
119
121
|
EOF
|
120
122
|
|
@@ -126,7 +128,7 @@ class EnumerableTest < Test::Unit::TestCase
|
|
126
128
|
def test_upto
|
127
129
|
cls, = compile(<<-EOF)
|
128
130
|
def foo(i:int)
|
129
|
-
i.upto(3) {|x|
|
131
|
+
i.upto(3) {|x| puts x }
|
130
132
|
end
|
131
133
|
EOF
|
132
134
|
|
@@ -138,7 +140,7 @@ class EnumerableTest < Test::Unit::TestCase
|
|
138
140
|
def test_times_with_arg
|
139
141
|
cls, = compile(<<-EOF)
|
140
142
|
def foo(i:int)
|
141
|
-
i.times {|x|
|
143
|
+
i.times {|x| puts x }
|
142
144
|
end
|
143
145
|
EOF
|
144
146
|
|
@@ -150,7 +152,7 @@ class EnumerableTest < Test::Unit::TestCase
|
|
150
152
|
def test_times_without_arg
|
151
153
|
cls, = compile(<<-EOF)
|
152
154
|
def foo(i:int)
|
153
|
-
i.times {
|
155
|
+
i.times { puts "Hi" }
|
154
156
|
end
|
155
157
|
EOF
|
156
158
|
|
@@ -248,7 +250,7 @@ class EnumerableTest < Test::Unit::TestCase
|
|
248
250
|
def test_each
|
249
251
|
cls, = compile(<<-EOF)
|
250
252
|
def foo
|
251
|
-
[1,2,3].each {|x|
|
253
|
+
[1,2,3].each {|x| puts x}
|
252
254
|
end
|
253
255
|
EOF
|
254
256
|
assert_output("1\n2\n3\n") do
|
@@ -259,7 +261,7 @@ class EnumerableTest < Test::Unit::TestCase
|
|
259
261
|
def test_each_without_block_arguments
|
260
262
|
cls, = compile(<<-EOF)
|
261
263
|
def foo
|
262
|
-
[1,2,3].each {
|
264
|
+
[1,2,3].each { puts :thrice }
|
263
265
|
end
|
264
266
|
EOF
|
265
267
|
assert_output("thrice\nthrice\nthrice\n") do
|
@@ -271,8 +273,8 @@ class EnumerableTest < Test::Unit::TestCase
|
|
271
273
|
cls, = compile(<<-EOF)
|
272
274
|
import java.lang.Integer
|
273
275
|
def foo
|
274
|
-
|
275
|
-
|
276
|
+
puts [1,2,3].any?
|
277
|
+
puts [1,2,3].any? {|x| Integer(x).intValue > 3}
|
276
278
|
end
|
277
279
|
EOF
|
278
280
|
assert_output("true\nfalse\n") do
|
@@ -284,8 +286,8 @@ class EnumerableTest < Test::Unit::TestCase
|
|
284
286
|
cls, = compile(<<-EOF)
|
285
287
|
import java.lang.Integer
|
286
288
|
def foo
|
287
|
-
|
288
|
-
|
289
|
+
puts [1,2,3].all?
|
290
|
+
puts [1,2,3].all? {|x| Integer(x).intValue > 3}
|
289
291
|
end
|
290
292
|
EOF
|
291
293
|
assert_output("true\nfalse\n") do
|
@@ -295,7 +297,7 @@ class EnumerableTest < Test::Unit::TestCase
|
|
295
297
|
def test_all_with_block_with_no_cast
|
296
298
|
cls, = compile(<<-EOF)
|
297
299
|
def foo
|
298
|
-
|
300
|
+
puts [1,2,3].all? {|x| x.intValue > 3}
|
299
301
|
end
|
300
302
|
EOF
|
301
303
|
assert_output("false\n") do
|
@@ -303,17 +305,39 @@ class EnumerableTest < Test::Unit::TestCase
|
|
303
305
|
end
|
304
306
|
end
|
305
307
|
|
306
|
-
def
|
308
|
+
def test_map_empty_literal
|
307
309
|
cls, = compile(<<-EOF)
|
308
|
-
|
309
|
-
System.out.println [1,2,3].map {|x:Integer| x.intValue + 1}
|
310
|
-
System.out.println [1,2,3].map {|x| x}
|
311
|
-
System.out.println [1].map { 'a' }
|
312
|
-
System.out.println [].map { 'b' }
|
313
|
-
end
|
310
|
+
puts [].map { 'b' }
|
314
311
|
EOF
|
315
|
-
assert_output
|
316
|
-
cls.
|
312
|
+
assert_output "[]\n" do
|
313
|
+
cls.main(nil)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_map_to_different_type
|
318
|
+
cls, = compile(<<-EOF)
|
319
|
+
puts [1].map { 'a' }
|
320
|
+
EOF
|
321
|
+
assert_output "[a]\n" do
|
322
|
+
cls.main(nil)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_map_identity
|
327
|
+
cls, = compile(<<-EOF)
|
328
|
+
puts [1,2,3].map {|x| x}
|
329
|
+
EOF
|
330
|
+
assert_output("[1, 2, 3]\n") do
|
331
|
+
cls.main(nil)
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
def test_map_with_type_declaration
|
336
|
+
cls, = compile(<<-EOF)
|
337
|
+
puts [1,2,3].map {|x:Integer| x.intValue + 1}
|
338
|
+
EOF
|
339
|
+
assert_output("[2, 3, 4]\n") do
|
340
|
+
cls.main(nil)
|
317
341
|
end
|
318
342
|
end
|
319
343
|
|
@@ -454,7 +478,7 @@ class EnumerableTest < Test::Unit::TestCase
|
|
454
478
|
end
|
455
479
|
|
456
480
|
def self.test(x:String)
|
457
|
-
MyIterator.new(x).each {|y|
|
481
|
+
MyIterator.new(x).each {|y| puts y}
|
458
482
|
end
|
459
483
|
end
|
460
484
|
EOF
|