mirah 0.1.4-java → 0.2.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/test/jvm/example_test.rb
CHANGED
@@ -23,14 +23,18 @@ class ExampleTest < Test::Unit::TestCase
|
|
23
23
|
|
24
24
|
def example_test name, output
|
25
25
|
cls = compile_ex name
|
26
|
-
|
26
|
+
assert_run_output(output, cls)
|
27
27
|
end
|
28
28
|
|
29
29
|
{
|
30
30
|
'simple_class' => "constructor\nHello, \nMirah\n",
|
31
31
|
'macros/square' => "2.0\n8.0\n",
|
32
32
|
'macros/square_int' => "2.0\n8.0\n",
|
33
|
-
'macros/string_each_char' => "l\na\na\nt\n \nd\ne\n \nl\ne\ne\ne\nu\nw\n \nn\ni\ne\nt\n \ni\nn\n \nz\ni\nj\nn\n \nh\ne\nm\np\ni\ne\n \ns\nt\na\na\nn\n"
|
33
|
+
'macros/string_each_char' => "l\na\na\nt\n \nd\ne\n \nl\ne\ne\ne\nu\nw\n \nn\ni\ne\nt\n \ni\nn\n \nz\ni\nj\nn\n \nh\ne\nm\np\ni\ne\n \ns\nt\na\na\nn\n",
|
34
|
+
'sort_closure' =>
|
35
|
+
"unsorted: [9, 5, 2, 6, 8, 5, 0, 3, 6, 1, 8, 3, 6, 4, 7, 5, 0, 8, 5, 6, 7, 2, 3]\n" +
|
36
|
+
"sorted: [0, 0, 1, 2, 2, 3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9]\n",
|
37
|
+
'rosettacode/fizz-buzz' => "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nFizzBuzz\n31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43\n44\nFizzBuzz\n46\n47\nFizz\n49\nBuzz\nFizz\n52\n53\nFizz\nBuzz\n56\nFizz\n58\n59\nFizzBuzz\n61\n62\nFizz\n64\nBuzz\nFizz\n67\n68\nFizz\nBuzz\n71\nFizz\n73\n74\nFizzBuzz\n76\n77\nFizz\n79\nBuzz\nFizz\n82\n83\nFizz\nBuzz\n86\nFizz\n88\n89\nFizzBuzz\n91\n92\nFizz\n94\nBuzz\nFizz\n97\n98\nFizz\nBuzz\n1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nFizzBuzz\n31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43\n44\nFizzBuzz\n46\n47\nFizz\n49\nBuzz\nFizz\n52\n53\nFizz\nBuzz\n56\nFizz\n58\n59\nFizzBuzz\n61\n62\nFizz\n64\nBuzz\nFizz\n67\n68\nFizz\nBuzz\n71\nFizz\n73\n74\nFizzBuzz\n76\n77\nFizz\n79\nBuzz\nFizz\n82\n83\nFizz\nBuzz\n86\nFizz\n88\n89\nFizzBuzz\n91\n92\nFizz\n94\nBuzz\nFizz\n97\n98\nFizz\nBuzz\n",
|
34
38
|
}.each do |example,output|
|
35
39
|
define_method "test_#{example}" do
|
36
40
|
example_test example, output
|
@@ -0,0 +1,181 @@
|
|
1
|
+
class ArrayExtensionsTest < Test::Unit::TestCase
|
2
|
+
def test_empty_q
|
3
|
+
cls, = compile(<<-EOF)
|
4
|
+
x = int[0]
|
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 = int[2]
|
13
|
+
x[0] = 1
|
14
|
+
x[1] = 2
|
15
|
+
puts x[0]
|
16
|
+
EOF
|
17
|
+
assert_run_output("1\n", cls)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_bracket_assignment
|
21
|
+
cls, = compile(<<-EOF)
|
22
|
+
x = String[1]
|
23
|
+
x[0]= "2"
|
24
|
+
puts java::util::Arrays.toString(x)
|
25
|
+
EOF
|
26
|
+
assert_run_output("[2]\n", cls)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_size
|
30
|
+
cls, = compile(%q{
|
31
|
+
puts int[4].size
|
32
|
+
})
|
33
|
+
assert_run_output("4\n", cls)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_each_with_index
|
37
|
+
cls, = compile(%q{
|
38
|
+
x = int[3]
|
39
|
+
x[0] = 9
|
40
|
+
x[1] = 7
|
41
|
+
x[2] = 5
|
42
|
+
x.each_with_index do |value,index|
|
43
|
+
puts "#{value} #{index}"
|
44
|
+
end
|
45
|
+
})
|
46
|
+
assert_run_output("9 0\n7 1\n5 2\n", cls)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_sort_with_comparator_block # comparators are only support for non-primitive types
|
50
|
+
cls, = compile(%q{
|
51
|
+
x = Integer[3]
|
52
|
+
x[0] = 3
|
53
|
+
x[1] = 1
|
54
|
+
x[2] = 2
|
55
|
+
y = x.sort do |a:Integer,b:Integer|
|
56
|
+
-(a.intValue-b.intValue)
|
57
|
+
end
|
58
|
+
puts java::util::Arrays.toString(y)
|
59
|
+
})
|
60
|
+
assert_run_output("[3, 2, 1]\n", cls)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_sort_without_comparator
|
64
|
+
cls, = compile(<<-EOF)
|
65
|
+
x = int[3]
|
66
|
+
x[0] = 5
|
67
|
+
x[1] = 1
|
68
|
+
x[2] = 3
|
69
|
+
puts java::util::Arrays.toString(x.sort)
|
70
|
+
EOF
|
71
|
+
assert_run_output("[1, 3, 5]\n", cls)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_first!
|
75
|
+
cls, = compile(<<-EOF)
|
76
|
+
x = int[3]
|
77
|
+
x[0] = 5
|
78
|
+
x[1] = 1
|
79
|
+
x[2] = 3
|
80
|
+
puts x.first!
|
81
|
+
EOF
|
82
|
+
assert_run_output("5\n", cls)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_empty_array_first!
|
86
|
+
cls, = compile(<<-EOF)
|
87
|
+
x = int[0]
|
88
|
+
puts x.first!
|
89
|
+
EOF
|
90
|
+
assert_raise_java(java.lang.ArrayIndexOutOfBoundsException) do
|
91
|
+
cls.main nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_last!
|
96
|
+
cls, = compile(<<-EOF)
|
97
|
+
x = int[3]
|
98
|
+
x[0] = 5
|
99
|
+
x[1] = 1
|
100
|
+
x[2] = 3
|
101
|
+
puts x.last!
|
102
|
+
EOF
|
103
|
+
assert_run_output("3\n", cls)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_empty_array_last!
|
107
|
+
cls, = compile(<<-EOF)
|
108
|
+
x = int[0]
|
109
|
+
puts x.last!
|
110
|
+
EOF
|
111
|
+
assert_raise_java(java.lang.ArrayIndexOutOfBoundsException) do
|
112
|
+
cls.main nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_array_join
|
117
|
+
cls, = compile(<<-EOF)
|
118
|
+
x = int[3]
|
119
|
+
x[0] = 5
|
120
|
+
x[1] = 1
|
121
|
+
x[2] = 3
|
122
|
+
puts x.join(':')
|
123
|
+
EOF
|
124
|
+
assert_run_output("5:1:3\n", cls)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_array_join_empty
|
128
|
+
cls, = compile(<<-EOF)
|
129
|
+
x = int[0]
|
130
|
+
puts x.join(':')
|
131
|
+
EOF
|
132
|
+
assert_run_output("\n", cls)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_array_join_single
|
136
|
+
cls, = compile(<<-EOF)
|
137
|
+
x = int[1]
|
138
|
+
x[0] = 4
|
139
|
+
puts x.join(':')
|
140
|
+
EOF
|
141
|
+
assert_run_output("4\n", cls)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_array_join_direct
|
145
|
+
cls, = compile(<<-EOF)
|
146
|
+
x = int[3]
|
147
|
+
x[0] = 5
|
148
|
+
x[1] = 1
|
149
|
+
x[2] = 3
|
150
|
+
puts x.join
|
151
|
+
EOF
|
152
|
+
assert_run_output("513\n", cls)
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_array_join_direct_empty
|
156
|
+
cls, = compile(<<-EOF)
|
157
|
+
x = int[0]
|
158
|
+
puts x.join
|
159
|
+
EOF
|
160
|
+
assert_run_output("\n", cls)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_array_join_direct_single
|
164
|
+
cls, = compile(<<-EOF)
|
165
|
+
x = int[1]
|
166
|
+
x[0] = 4
|
167
|
+
puts x.join
|
168
|
+
EOF
|
169
|
+
assert_run_output("4\n", cls)
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_array_new
|
173
|
+
cls, = compile(<<-EOF)
|
174
|
+
x = int[].new(5) do |i|
|
175
|
+
i*2+1
|
176
|
+
end
|
177
|
+
puts x.join(",")
|
178
|
+
EOF
|
179
|
+
assert_run_output("1,3,5,7,9\n", cls)
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
class CollectionExtensionsTest < Test::Unit::TestCase
|
2
|
+
def test_mirah_array_join_empty
|
3
|
+
cls, = compile(<<-EOF)
|
4
|
+
x = [].join
|
5
|
+
puts x
|
6
|
+
EOF
|
7
|
+
assert_run_output("\n", cls)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_mirah_array_join_single
|
11
|
+
cls, = compile(<<-EOF)
|
12
|
+
x = ["a"].join
|
13
|
+
puts x
|
14
|
+
EOF
|
15
|
+
assert_run_output("a\n", cls)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_mirah_array_join_multiple
|
19
|
+
cls, = compile(<<-EOF)
|
20
|
+
x = ["a",1,"c"].join
|
21
|
+
puts x
|
22
|
+
EOF
|
23
|
+
assert_run_output("a1c\n", cls)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_java_array_join_empty
|
27
|
+
cls, = compile(<<-EOF)
|
28
|
+
x = int[0].join
|
29
|
+
puts x
|
30
|
+
EOF
|
31
|
+
assert_run_output("\n", cls)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_java_array_join_single
|
35
|
+
cls, = compile(<<-EOF)
|
36
|
+
x = ["a"].to_array(String).join
|
37
|
+
puts x
|
38
|
+
EOF
|
39
|
+
assert_run_output("a\n", cls)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_java_array_join_multiple
|
43
|
+
cls, = compile(<<-EOF)
|
44
|
+
x = ["a",1,"c"].to_array(Object).join
|
45
|
+
puts x
|
46
|
+
EOF
|
47
|
+
assert_run_output("a1c\n", cls)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_primitve_java_array_join_multiple
|
51
|
+
cls, = compile(<<-EOF)
|
52
|
+
x = int[4].join
|
53
|
+
puts x
|
54
|
+
EOF
|
55
|
+
assert_run_output("0000\n", cls)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_mirah_array_join_separator_empty
|
59
|
+
cls, = compile(<<-EOF)
|
60
|
+
x = [].join(",")
|
61
|
+
puts x
|
62
|
+
EOF
|
63
|
+
assert_run_output("\n", cls)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_mirah_array_join_separator_single
|
67
|
+
cls, = compile(<<-EOF)
|
68
|
+
x = ["a"].join(",")
|
69
|
+
puts x
|
70
|
+
EOF
|
71
|
+
assert_run_output("a\n", cls)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_mirah_array_join_separator_multiple
|
75
|
+
cls, = compile(<<-EOF)
|
76
|
+
x = ["a",1,"c"].join(",")
|
77
|
+
puts x
|
78
|
+
EOF
|
79
|
+
assert_run_output("a,1,c\n", cls)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_java_array_join_separator_empty
|
83
|
+
cls, = compile(<<-EOF)
|
84
|
+
x = int[0].join(",")
|
85
|
+
puts x
|
86
|
+
EOF
|
87
|
+
assert_run_output("\n", cls)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_java_array_join_separator_single
|
91
|
+
cls, = compile(<<-EOF)
|
92
|
+
x = ["a"].to_array(String).join(",")
|
93
|
+
puts x
|
94
|
+
EOF
|
95
|
+
assert_run_output("a\n", cls)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_java_array_join_separator_multiple
|
99
|
+
cls, = compile(<<-EOF)
|
100
|
+
x = ["a",1,"c"].to_array(Object).join(",")
|
101
|
+
puts x
|
102
|
+
EOF
|
103
|
+
assert_run_output("a,1,c\n", cls)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_primitve_java_array_join_separator_multiple
|
107
|
+
cls, = compile(<<-EOF)
|
108
|
+
x = int[4].join(",")
|
109
|
+
puts x
|
110
|
+
EOF
|
111
|
+
assert_run_output("0,0,0,0\n", cls)
|
112
|
+
end
|
113
|
+
|
114
|
+
# implicitly tests each_with_index
|
115
|
+
def test_mapa_on_list
|
116
|
+
cls, = compile(%q[
|
117
|
+
x = ["a","b","c","d"].mapa do |s|
|
118
|
+
"#{s}x"
|
119
|
+
end
|
120
|
+
puts x[2]
|
121
|
+
puts x.getClass.getName
|
122
|
+
])
|
123
|
+
assert_run_output("cx\n[Ljava.lang.String;\n", cls)
|
124
|
+
end
|
125
|
+
|
126
|
+
# implicitly tests each_with_index
|
127
|
+
def test_mapa_on_java_array_with_complex_basetype
|
128
|
+
cls, = compile(%q[
|
129
|
+
x = ["a","b","c","d"].to_array(String).mapa do |s|
|
130
|
+
"#{s}x"
|
131
|
+
end
|
132
|
+
puts x[2]
|
133
|
+
puts x.getClass.getName
|
134
|
+
])
|
135
|
+
assert_run_output("cx\n[Ljava.lang.String;\n", cls)
|
136
|
+
end
|
137
|
+
|
138
|
+
# implicitly tests each_with_index
|
139
|
+
def test_mapa_on_java_array_with_primitive_basetype
|
140
|
+
cls, = compile(%q[
|
141
|
+
x = [1,2,3,4].to_array(int).mapa do |s|
|
142
|
+
"#{s}x"
|
143
|
+
end
|
144
|
+
puts x[2]
|
145
|
+
puts x.getClass.getName
|
146
|
+
])
|
147
|
+
assert_run_output("3x\n[Ljava.lang.String;\n", cls)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_map
|
151
|
+
cls, = compile(%q[
|
152
|
+
x = ["a","b","c","d"].map do |s|
|
153
|
+
"#{s}x"
|
154
|
+
end
|
155
|
+
puts x[2]
|
156
|
+
puts x.getClass.getName
|
157
|
+
])
|
158
|
+
assert_run_output("cx\njava.util.ArrayList\n", cls)
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_operator_append
|
162
|
+
cls, = compile(%q{
|
163
|
+
x = ["a"]
|
164
|
+
x << "b"
|
165
|
+
x << "c" << "d"
|
166
|
+
x << "e"
|
167
|
+
puts x
|
168
|
+
})
|
169
|
+
assert_run_output("[a, b, c, d, e]\n", cls)
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_mapa_on_java_array_with_complex_basetype_returning_type_defined_later
|
173
|
+
cls, = compile(%q[
|
174
|
+
x = ["a","b","c","d"].mapa do |s|
|
175
|
+
TypeDefinedLater.new(s)
|
176
|
+
end
|
177
|
+
puts x[2]
|
178
|
+
puts x.getClass.getName
|
179
|
+
|
180
|
+
class TypeDefinedLater
|
181
|
+
attr_accessor foo:Object
|
182
|
+
|
183
|
+
def initialize(foo:Object)
|
184
|
+
self.foo = foo
|
185
|
+
end
|
186
|
+
|
187
|
+
def toString
|
188
|
+
"TypeDefinedLater(#{foo})"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
])
|
192
|
+
assert_run_output("TypeDefinedLater(c)\n[LTypeDefinedLater;\n", cls)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
@@ -309,36 +309,104 @@ class EnumerableTest < Test::Unit::TestCase
|
|
309
309
|
cls, = compile(<<-EOF)
|
310
310
|
puts [].map { 'b' }
|
311
311
|
EOF
|
312
|
-
|
313
|
-
cls.main(nil)
|
314
|
-
end
|
312
|
+
assert_run_output("[]\n", cls)
|
315
313
|
end
|
316
314
|
|
317
315
|
def test_map_to_different_type
|
318
316
|
cls, = compile(<<-EOF)
|
319
317
|
puts [1].map { 'a' }
|
320
318
|
EOF
|
321
|
-
|
322
|
-
cls.main(nil)
|
323
|
-
end
|
319
|
+
assert_run_output("[a]\n", cls)
|
324
320
|
end
|
325
321
|
|
326
|
-
def test_map_identity
|
322
|
+
def test_map_identity
|
327
323
|
cls, = compile(<<-EOF)
|
328
324
|
puts [1,2,3].map {|x| x}
|
329
325
|
EOF
|
330
|
-
|
331
|
-
cls.main(nil)
|
332
|
-
end
|
326
|
+
assert_run_output("[1, 2, 3]\n", cls)
|
333
327
|
end
|
334
328
|
|
335
329
|
def test_map_with_type_declaration
|
336
330
|
cls, = compile(<<-EOF)
|
337
331
|
puts [1,2,3].map {|x:Integer| x.intValue + 1}
|
338
332
|
EOF
|
339
|
-
|
340
|
-
|
341
|
-
|
333
|
+
assert_run_output("[2, 3, 4]\n", cls)
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_native_array_map_empty_literal
|
337
|
+
cls, = compile(<<-EOF)
|
338
|
+
puts int[0].map { 'b' }
|
339
|
+
EOF
|
340
|
+
assert_run_output("[]\n", cls)
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_native_array_map_to_different_type
|
344
|
+
cls, = compile(<<-EOF)
|
345
|
+
a = int[1]
|
346
|
+
a[0] = 1
|
347
|
+
puts a.map { 'a' }
|
348
|
+
EOF
|
349
|
+
assert_run_output("[a]\n", cls)
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_native_array_map_identity
|
353
|
+
cls, = compile(<<-EOF)
|
354
|
+
a = int[3]
|
355
|
+
a[0] = 1
|
356
|
+
a[1] = 2
|
357
|
+
a[2] = 3
|
358
|
+
puts a.map {|x| x}
|
359
|
+
EOF
|
360
|
+
assert_run_output("[1, 2, 3]\n", cls)
|
361
|
+
end
|
362
|
+
|
363
|
+
def test_native_array_map_with_type_declaration
|
364
|
+
cls, = compile(<<-EOF)
|
365
|
+
a = int[3]
|
366
|
+
a[0] = 1
|
367
|
+
a[1] = 2
|
368
|
+
a[2] = 3
|
369
|
+
puts a.map {|x:int| x + 1}
|
370
|
+
EOF
|
371
|
+
assert_run_output("[2, 3, 4]\n", cls)
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_select_identity
|
375
|
+
cls, = compile(<<-EOF)
|
376
|
+
puts [1,2,3].select {|x| true}
|
377
|
+
EOF
|
378
|
+
assert_run_output("[1, 2, 3]\n", cls)
|
379
|
+
end
|
380
|
+
|
381
|
+
def test_select_odd
|
382
|
+
cls, = compile(<<-EOF)
|
383
|
+
puts [1,2,3].select {|x| (x.intValue&1)==1}
|
384
|
+
EOF
|
385
|
+
assert_run_output("[1, 3]\n", cls)
|
386
|
+
end
|
387
|
+
|
388
|
+
def test_select_multistatement_block
|
389
|
+
cls, = compile(<<-EOF)
|
390
|
+
puts ([1,2,3].select do |x|
|
391
|
+
v = x.intValue
|
392
|
+
v&1==1
|
393
|
+
end)
|
394
|
+
EOF
|
395
|
+
assert_run_output("[1, 3]\n", cls)
|
396
|
+
end
|
397
|
+
|
398
|
+
def test_join
|
399
|
+
cls, = compile(<<-EOF)
|
400
|
+
puts [1,23,4].join
|
401
|
+
EOF
|
402
|
+
assert_run_output("1234\n", cls)
|
403
|
+
end
|
404
|
+
|
405
|
+
def test_join_with_separator
|
406
|
+
cls, = compile(<<-EOF)
|
407
|
+
puts [1,23,4].join ', '
|
408
|
+
EOF
|
409
|
+
assert_run_output("1, 23, 4\n", cls)
|
342
410
|
end
|
343
411
|
|
344
412
|
def test_zip
|