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
Binary file
|
@@ -0,0 +1,31 @@
|
|
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
|
+
require 'test_helper'
|
16
|
+
|
17
|
+
class AccessLevelsTest < Test::Unit::TestCase
|
18
|
+
def test_private_method_inaccessible_externally
|
19
|
+
cls, = compile("private def foo; a = 1; a; end; def bar; foo; end")
|
20
|
+
|
21
|
+
assert_raise NoMethodError do
|
22
|
+
cls.foo
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_private_method_accessible_internally
|
27
|
+
cls, = compile("private def foo; a = 1; a; end; def bar; foo; end")
|
28
|
+
|
29
|
+
assert_equal 1, cls.bar
|
30
|
+
end
|
31
|
+
end
|
@@ -50,10 +50,9 @@ class AnnotationsTest < Test::Unit::TestCase
|
|
50
50
|
puts anno.value
|
51
51
|
EOF
|
52
52
|
|
53
|
-
|
54
|
-
cls.main nil
|
55
|
-
end
|
53
|
+
assert_run_output("1\n", cls)
|
56
54
|
end
|
55
|
+
|
57
56
|
def test_annotation_from_constant
|
58
57
|
return
|
59
58
|
cls, = compile(<<-EOF)
|
@@ -69,9 +68,7 @@ class AnnotationsTest < Test::Unit::TestCase
|
|
69
68
|
puts anno.value
|
70
69
|
EOF
|
71
70
|
|
72
|
-
|
73
|
-
cls.main nil
|
74
|
-
end
|
71
|
+
assert_run_output("1\n", cls)
|
75
72
|
end
|
76
73
|
|
77
74
|
end
|
data/test/jvm/blocks_test.rb
CHANGED
@@ -70,9 +70,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
70
70
|
puts "Uh Oh!"
|
71
71
|
end
|
72
72
|
EOF
|
73
|
-
|
74
|
-
cls.main([].to_java :string)
|
75
|
-
end
|
73
|
+
assert_run_output("Hello\n", cls)
|
76
74
|
end
|
77
75
|
|
78
76
|
def test_arg_types_inferred_from_interface
|
@@ -88,9 +86,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
88
86
|
o.addObserver {|x, a| puts a}
|
89
87
|
o.notifyObservers("Hello Observer")
|
90
88
|
EOF
|
91
|
-
|
92
|
-
script.main([].to_java :string)
|
93
|
-
end
|
89
|
+
assert_run_output("Hello Observer\n", script)
|
94
90
|
end
|
95
91
|
|
96
92
|
def test_closure
|
@@ -159,9 +155,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
159
155
|
list.each {|x| puts x }
|
160
156
|
EOF
|
161
157
|
|
162
|
-
|
163
|
-
cls.main(nil)
|
164
|
-
end
|
158
|
+
assert_run_output("a\nABC\nb\nCats\n", cls)
|
165
159
|
end
|
166
160
|
|
167
161
|
def test_block_with_abstract_from_object
|
@@ -196,8 +190,82 @@ class BlocksTest < Test::Unit::TestCase
|
|
196
190
|
puts "never get here"
|
197
191
|
end
|
198
192
|
EOF
|
199
|
-
|
200
|
-
|
193
|
+
assert_run_output("an object\n", cls)
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_nesting_with_abstract_class
|
197
|
+
pend 'test_nesting_with_abstract_class' do
|
198
|
+
cls, main = compile(%q{
|
199
|
+
abstract class Nestable
|
200
|
+
abstract def foo(n: Nestable):void;end
|
201
|
+
def create(n: Nestable):void
|
202
|
+
puts "create #{n}"
|
203
|
+
n.foo(n)
|
204
|
+
end
|
205
|
+
|
206
|
+
def toString:String
|
207
|
+
"nestable"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
class Main
|
212
|
+
def self.create(b: Nestable):void
|
213
|
+
b.foo(b)
|
214
|
+
end
|
215
|
+
|
216
|
+
def self.main(args: String[]):void
|
217
|
+
create do |x:Nestable|
|
218
|
+
puts "outer foo"
|
219
|
+
create do |m: Nestable|
|
220
|
+
puts "in foo #{m}"
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
})
|
226
|
+
assert_output "outer foo\ncreate nestable\nin foo nestable\n" do
|
227
|
+
main.main([])
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_use_abstract_inplace
|
233
|
+
pend "test_use_abstract_inplace" do
|
234
|
+
#with_finest_logging {
|
235
|
+
cls, main, parent = compile(%q{
|
236
|
+
abstract class A < P
|
237
|
+
|
238
|
+
def self.empty:A
|
239
|
+
create do
|
240
|
+
puts "empty"
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def self.create(n: A):void
|
245
|
+
puts "create #{n}"
|
246
|
+
n.execute
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
class Main
|
252
|
+
def self.create(b: Nestable = A.empty):void
|
253
|
+
b.execute
|
254
|
+
end
|
255
|
+
|
256
|
+
def self.main(args: String[]):void
|
257
|
+
create
|
258
|
+
create { puts "not empty"}
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
abstract class P
|
263
|
+
abstract def execute:void;end
|
264
|
+
end
|
265
|
+
})
|
266
|
+
assert_output "outer foo\ncreate nestable\nin foo nestable\n" do
|
267
|
+
main.main([])
|
268
|
+
end
|
201
269
|
end
|
202
270
|
end
|
203
271
|
|
@@ -212,9 +280,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
212
280
|
|
213
281
|
foo('there')
|
214
282
|
EOF
|
215
|
-
|
216
|
-
cls.main(nil)
|
217
|
-
end
|
283
|
+
assert_run_output("Hello there\n", cls)
|
218
284
|
end
|
219
285
|
|
220
286
|
def test_block_with_mirah_interface
|
@@ -273,9 +339,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
273
339
|
puts "hi"
|
274
340
|
end
|
275
341
|
CODE
|
276
|
-
|
277
|
-
cls.main(nil)
|
278
|
-
end
|
342
|
+
assert_run_output("hi\n", cls)
|
279
343
|
end
|
280
344
|
|
281
345
|
def test_block_with_too_many_params
|
@@ -300,7 +364,6 @@ class BlocksTest < Test::Unit::TestCase
|
|
300
364
|
end
|
301
365
|
|
302
366
|
def test_call_with_block_assigned_to_macro
|
303
|
-
#cls, = with_finest_logging{compile(<<-CODE)}
|
304
367
|
cls, = compile(<<-CODE)
|
305
368
|
class S
|
306
369
|
def initialize(run: Runnable)
|
@@ -317,9 +380,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
317
380
|
puts b
|
318
381
|
end
|
319
382
|
CODE
|
320
|
-
|
321
|
-
cls.main(nil)
|
322
|
-
end
|
383
|
+
assert_run_output("hey\n{wut=1}\n1\n", cls)
|
323
384
|
end
|
324
385
|
|
325
386
|
def test_nested_closure_in_closure_doesnt_raise_error
|
@@ -338,36 +399,121 @@ class BlocksTest < Test::Unit::TestCase
|
|
338
399
|
end
|
339
400
|
end
|
340
401
|
CODE
|
341
|
-
|
342
|
-
cls.main(nil)
|
343
|
-
end
|
402
|
+
assert_run_output("first closure\nsecond closure\n", cls)
|
344
403
|
end
|
345
404
|
|
346
405
|
def test_nested_closure_with_var_from_outer_closure
|
347
|
-
|
348
|
-
|
349
|
-
cls, = compile(<<-'CODE')
|
350
|
-
interface BarRunner do;def run:void;end;end
|
406
|
+
cls, = compile(<<-'CODE')
|
407
|
+
interface BarRunner do;def run:void;end;end
|
351
408
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
end
|
409
|
+
class Nestable
|
410
|
+
def foo(a:BarRunner)
|
411
|
+
a.run
|
356
412
|
end
|
413
|
+
end
|
414
|
+
Nestable.new.foo do
|
415
|
+
c = "closure"
|
416
|
+
puts "first #{c}"
|
357
417
|
Nestable.new.foo do
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
418
|
+
puts "second #{c}"
|
419
|
+
end
|
420
|
+
end
|
421
|
+
CODE
|
422
|
+
assert_run_output("first closure\nsecond closure\n", cls)
|
423
|
+
end
|
424
|
+
|
425
|
+
def test_nested_closure_with_nested_closed_over_args
|
426
|
+
cls, = compile(<<-'CODE')
|
427
|
+
interface Jogger do;def jog(pace:int):void;end;end
|
428
|
+
|
429
|
+
class Nestable
|
430
|
+
def foo(pace: int, a: Jogger)
|
431
|
+
a.jog(pace)
|
432
|
+
end
|
433
|
+
end
|
434
|
+
Nestable.new.foo 10 do |pace|
|
435
|
+
puts "first #{pace}"
|
436
|
+
Nestable.new.foo 20 do |inner_pace|
|
437
|
+
puts "second #{pace} #{inner_pace}"
|
438
|
+
end
|
439
|
+
end
|
440
|
+
CODE
|
441
|
+
assert_run_output("first 10\nsecond 10 20\n", cls)
|
442
|
+
end
|
443
|
+
|
444
|
+
def test_nested_closure_with_nested_closed_over_args2
|
445
|
+
cls, = compile(%q[
|
446
|
+
interface Jogger do;def jog(param:int):void;end;end
|
447
|
+
|
448
|
+
class Nestable
|
449
|
+
def operate(blub: int, a: Jogger):void
|
450
|
+
a.jog(blub)
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
class Bar
|
455
|
+
def baz(foo:int):void
|
456
|
+
puts "bazstart"
|
457
|
+
Nestable.new.operate(10) do |arg1|
|
458
|
+
puts "first #{arg1} #{foo}"
|
459
|
+
Nestable.new.operate 20 do |inner_pace|
|
460
|
+
puts "second #{arg1} #{inner_pace} #{foo}"
|
461
|
+
end
|
462
|
+
Nestable.new.operate 30 do |inner_pace2|
|
463
|
+
puts "third #{arg1} #{inner_pace2} #{foo}"
|
464
|
+
end
|
362
465
|
end
|
363
466
|
end
|
364
|
-
CODE
|
365
|
-
assert_output "first closure\nsecond closure\n" do
|
366
|
-
cls.main(nil)
|
367
467
|
end
|
368
|
-
|
468
|
+
|
469
|
+
Bar.new.baz(4)
|
470
|
+
])
|
471
|
+
assert_run_output("bazstart\nfirst 10 4\nsecond 10 20 4\nthird 10 30 4\n", cls)
|
369
472
|
end
|
370
473
|
|
474
|
+
def test_two_closures_capture_different_variables
|
475
|
+
cls, = compile(%q[
|
476
|
+
interface Jogger do;def jog(param:int):void;end;end
|
477
|
+
|
478
|
+
class Nestable
|
479
|
+
def operate(blub: int, a: Jogger):void
|
480
|
+
a.jog(blub)
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
class Bar
|
485
|
+
def baz(foo:int):void
|
486
|
+
puts "bazstart"
|
487
|
+
bar = 7
|
488
|
+
Nestable.new.operate(40) do |arg1|
|
489
|
+
puts bar
|
490
|
+
end
|
491
|
+
Nestable.new.operate(10) do |arg1|
|
492
|
+
puts "first #{arg1} #{foo}"
|
493
|
+
end
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
Bar.new.baz(4)
|
498
|
+
])
|
499
|
+
assert_run_output("bazstart\n7\nfirst 10 4\n", cls)
|
500
|
+
end
|
501
|
+
|
502
|
+
def test_uncastable_block_arg_type_fails
|
503
|
+
error = assert_raises Mirah::MirahError do
|
504
|
+
compile(<<-EOF)
|
505
|
+
import java.io.OutputStream
|
506
|
+
def foo x:OutputStream
|
507
|
+
x.write byte(1)
|
508
|
+
rescue
|
509
|
+
end
|
510
|
+
foo do |b:String|
|
511
|
+
puts "writing"
|
512
|
+
end
|
513
|
+
EOF
|
514
|
+
end
|
515
|
+
assert_equal "Cannot cast java.lang.String to int.", error.message
|
516
|
+
end
|
371
517
|
|
372
518
|
def test_method_requiring_subclass_of_abstract_class_finds_abstract_method
|
373
519
|
cls, = compile(<<-EOF)
|
@@ -380,9 +526,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
380
526
|
puts "writing"
|
381
527
|
end
|
382
528
|
EOF
|
383
|
-
|
384
|
-
cls.main(nil)
|
385
|
-
end
|
529
|
+
assert_run_output("writing\n", cls)
|
386
530
|
end
|
387
531
|
|
388
532
|
def test_block_with_interface_method_with_2_arguments_with_types
|
@@ -401,9 +545,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
401
545
|
puts b
|
402
546
|
end
|
403
547
|
EOF
|
404
|
-
|
405
|
-
cls.main(nil)
|
406
|
-
end
|
548
|
+
assert_run_output("hello\n1243\n", cls)
|
407
549
|
end
|
408
550
|
|
409
551
|
def test_block_with_interface_method_with_2_arguments_without_types
|
@@ -422,11 +564,23 @@ class BlocksTest < Test::Unit::TestCase
|
|
422
564
|
puts b
|
423
565
|
end
|
424
566
|
EOF
|
425
|
-
|
426
|
-
cls.main(nil)
|
427
|
-
end
|
567
|
+
assert_run_output("hello\n1243\n", cls)
|
428
568
|
end
|
429
569
|
|
570
|
+
def test_closures_with_static_imports
|
571
|
+
cls, = compile(<<-EOF)
|
572
|
+
def foo a:Runnable
|
573
|
+
a.run
|
574
|
+
end
|
575
|
+
foo do
|
576
|
+
x = [2,1]
|
577
|
+
import static java.util.Collections.*
|
578
|
+
sort x
|
579
|
+
puts x
|
580
|
+
end
|
581
|
+
EOF
|
582
|
+
assert_run_output("[1, 2]\n", cls)
|
583
|
+
end
|
430
584
|
|
431
585
|
def test_closures_support_non_local_return
|
432
586
|
pend "nlr doesnt work right now" do
|
@@ -443,9 +597,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
443
597
|
end
|
444
598
|
puts nlr
|
445
599
|
EOF
|
446
|
-
|
447
|
-
cls.main(nil)
|
448
|
-
end
|
600
|
+
assert_run_output("NLR!\n", cls)
|
449
601
|
end
|
450
602
|
end
|
451
603
|
|
@@ -464,9 +616,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
464
616
|
end
|
465
617
|
puts nlr
|
466
618
|
EOF
|
467
|
-
|
468
|
-
cls.main(nil)
|
469
|
-
end
|
619
|
+
assert_run_output("1234\n", cls)
|
470
620
|
end
|
471
621
|
end
|
472
622
|
|
@@ -503,9 +653,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
503
653
|
foo { return }
|
504
654
|
puts "or here"
|
505
655
|
EOF
|
506
|
-
|
507
|
-
cls.main(nil)
|
508
|
-
end
|
656
|
+
assert_run_output("before\n", cls)
|
509
657
|
end
|
510
658
|
end
|
511
659
|
|
@@ -526,9 +674,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
526
674
|
end
|
527
675
|
puts ClosureInMethodInClass.new.nlr
|
528
676
|
EOF
|
529
|
-
|
530
|
-
cls.main(nil)
|
531
|
-
end
|
677
|
+
assert_run_output("before\n1234\n", cls)
|
532
678
|
end
|
533
679
|
end
|
534
680
|
|
@@ -548,9 +694,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
548
694
|
end
|
549
695
|
ClosureInVoidMethodInClass.new.nlr
|
550
696
|
EOF
|
551
|
-
|
552
|
-
cls.main(nil)
|
553
|
-
end
|
697
|
+
assert_run_output("before\n", cls)
|
554
698
|
end
|
555
699
|
end
|
556
700
|
|
@@ -570,9 +714,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
570
714
|
puts nlr true
|
571
715
|
puts nlr false
|
572
716
|
EOF
|
573
|
-
|
574
|
-
cls.main(nil)
|
575
|
-
end
|
717
|
+
assert_run_output("NLR!\nNLArrrr\n", cls)
|
576
718
|
end
|
577
719
|
end
|
578
720
|
|
@@ -596,9 +738,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
596
738
|
puts nlr true
|
597
739
|
puts nlr false
|
598
740
|
EOF
|
599
|
-
|
600
|
-
cls.main(nil)
|
601
|
-
end
|
741
|
+
assert_run_output("NLR!\nNLArrrr\n", cls)
|
602
742
|
end
|
603
743
|
end
|
604
744
|
|
@@ -620,9 +760,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
620
760
|
puts nlr true
|
621
761
|
puts nlr false
|
622
762
|
EOF
|
623
|
-
|
624
|
-
cls.main(nil)
|
625
|
-
end
|
763
|
+
assert_run_output("NLR!\nmay get here\nNLArrrr\n", cls)
|
626
764
|
end
|
627
765
|
end
|
628
766
|
|
@@ -648,33 +786,27 @@ class BlocksTest < Test::Unit::TestCase
|
|
648
786
|
Huh.new.wut(Huh.new.regular)
|
649
787
|
EOF
|
650
788
|
|
651
|
-
|
652
|
-
cls.main(nil)
|
653
|
-
end
|
789
|
+
assert_run_output("Closure!\nfinish\n", cls)
|
654
790
|
end
|
655
791
|
|
656
792
|
|
657
793
|
def test_closure_with_or
|
658
|
-
cls, =
|
659
|
-
def r(run: Runnable) run.run; end
|
794
|
+
cls, = compile(<<-EOF)
|
795
|
+
def r(run: java.lang.Runnable) run.run; end
|
660
796
|
r { puts "a" || "b"}
|
661
797
|
EOF
|
662
798
|
|
663
|
-
|
664
|
-
cls.main(nil)
|
665
|
-
end
|
799
|
+
assert_run_output("a\n", cls)
|
666
800
|
end
|
667
801
|
|
668
802
|
def test_closure_with_or_ii
|
669
|
-
cls, =
|
803
|
+
cls, = compile(<<-EOF)
|
670
804
|
interface C; def c(): String;end;end
|
671
805
|
def r(cee: C) puts cee.c; end
|
672
806
|
r { "a" || "b"}
|
673
807
|
EOF
|
674
808
|
|
675
|
-
|
676
|
-
cls.main(nil)
|
677
|
-
end
|
809
|
+
assert_run_output("a\n", cls)
|
678
810
|
end
|
679
811
|
|
680
812
|
def test_two_closures_in_the_same_method
|
@@ -689,9 +821,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
689
821
|
end
|
690
822
|
regular
|
691
823
|
EOF
|
692
|
-
|
693
|
-
cls.main(nil)
|
694
|
-
end
|
824
|
+
assert_run_output("Closure!\nWe Want it\n", cls)
|
695
825
|
end
|
696
826
|
|
697
827
|
def test_closures_in_a_rescue
|
@@ -710,9 +840,7 @@ class BlocksTest < Test::Unit::TestCase
|
|
710
840
|
end
|
711
841
|
regular
|
712
842
|
EOF
|
713
|
-
|
714
|
-
cls.main(nil)
|
715
|
-
end
|
843
|
+
assert_run_output("Closure!\nWe Want it\n", cls)
|
716
844
|
end
|
717
845
|
|
718
846
|
def test_lambda_with_type_defined_before
|
@@ -723,24 +851,18 @@ class BlocksTest < Test::Unit::TestCase
|
|
723
851
|
x = lambda(Fooable) { puts "hey you" }
|
724
852
|
x.foo
|
725
853
|
EOF
|
726
|
-
|
727
|
-
cls.main(nil)
|
728
|
-
end
|
854
|
+
assert_run_output("hey you\n", cls)
|
729
855
|
end
|
730
856
|
|
731
857
|
def test_lambda_with_type_defined_later
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
def foo: void; end
|
737
|
-
end
|
738
|
-
x.foo
|
739
|
-
EOF
|
740
|
-
assert_output "hey you\n" do
|
741
|
-
cls.main(nil)
|
858
|
+
cls, = compile(<<-EOF)
|
859
|
+
x = lambda(Fooable) { puts "hey you" }
|
860
|
+
interface Fooable
|
861
|
+
def foo: void; end
|
742
862
|
end
|
743
|
-
|
863
|
+
x.foo
|
864
|
+
EOF
|
865
|
+
assert_run_output("hey you\n", cls)
|
744
866
|
end
|
745
867
|
|
746
868
|
def test_closure_with_primitive_array_param
|
@@ -753,28 +875,89 @@ class BlocksTest < Test::Unit::TestCase
|
|
753
875
|
end
|
754
876
|
r {|b| puts String.new(b) }
|
755
877
|
EOF
|
756
|
-
|
757
|
-
cls.main(nil)
|
758
|
-
end
|
878
|
+
assert_run_output("yay\n", cls)
|
759
879
|
end
|
760
880
|
|
761
881
|
|
882
|
+
def test_block_syntax_for_anonymous_class_implementing_inner_interface
|
883
|
+
cls, = compile('
|
884
|
+
import org.foo.InnerInterfaceClass
|
885
|
+
|
886
|
+
InnerInterfaceClass.forward("foo") do |param|
|
887
|
+
puts param
|
888
|
+
end
|
889
|
+
')
|
890
|
+
assert_run_output("foo\n", cls)
|
891
|
+
end
|
892
|
+
|
893
|
+
def test_block_syntax_for_abstract_class_invoke_self
|
894
|
+
omit_if JVMCompiler::JVM_VERSION.to_f < 1.8
|
895
|
+
cls, = compile('
|
896
|
+
import org.foo.AbstractExecutorJava8
|
897
|
+
|
898
|
+
AbstractExecutorJava8.execute do
|
899
|
+
puts "foo"
|
900
|
+
end
|
901
|
+
')
|
902
|
+
assert_run_output("foo\n", cls)
|
903
|
+
end
|
904
|
+
|
762
905
|
def test_lambda_closure
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
b.run
|
767
|
-
end
|
768
|
-
msg = "yay"
|
769
|
-
l = lambda(Runnable) { puts msg }
|
770
|
-
r l
|
771
|
-
EOF
|
772
|
-
assert_output "yay\n" do
|
773
|
-
cls.main(nil)
|
906
|
+
cls, = compile(<<-EOF)
|
907
|
+
def r b: Runnable
|
908
|
+
b.run
|
774
909
|
end
|
775
|
-
|
910
|
+
msg = "yay"
|
911
|
+
l = lambda(Runnable) { puts msg }
|
912
|
+
r l
|
913
|
+
EOF
|
914
|
+
assert_run_output("yay\n", cls)
|
776
915
|
end
|
777
916
|
|
917
|
+
|
918
|
+
def test_binding_in_class_definition_has_right_namespace
|
919
|
+
classes = compile(<<-'EOF')
|
920
|
+
package test
|
921
|
+
class Something
|
922
|
+
def create(a: Runnable):void
|
923
|
+
a.run
|
924
|
+
end
|
925
|
+
def with_binding
|
926
|
+
loc = 1
|
927
|
+
create do
|
928
|
+
puts "test #{loc}"
|
929
|
+
end
|
930
|
+
end
|
931
|
+
end
|
932
|
+
EOF
|
933
|
+
class_names = classes.map(&:java_class).map(&:name)
|
934
|
+
pattern = /test\.Something\$.*?Binding\d*/
|
935
|
+
assert class_names.find{|c| c.match pattern },
|
936
|
+
"generated classes: #{class_names} didn't contain #{pattern}."
|
937
|
+
end
|
938
|
+
|
939
|
+
|
940
|
+
def test_binding_in_script_has_right_namespace
|
941
|
+
classes = compile(<<-'EOF', name: 'MyScript')
|
942
|
+
def create(a: Runnable):void
|
943
|
+
a.run
|
944
|
+
end
|
945
|
+
def with_binding
|
946
|
+
loc = 1
|
947
|
+
create do
|
948
|
+
puts "test #{loc}"
|
949
|
+
end
|
950
|
+
end
|
951
|
+
EOF
|
952
|
+
class_names = classes.map(&:java_class).map(&:name)
|
953
|
+
pattern = /MyScriptTopLevel\$.*?Binding\d*/
|
954
|
+
|
955
|
+
assert class_names.find{|c| c.match pattern },
|
956
|
+
"generated classes: #{class_names} didn't contain #{pattern}."
|
957
|
+
end
|
958
|
+
|
959
|
+
|
960
|
+
|
778
961
|
# nested nlr scopes
|
779
962
|
|
780
963
|
# works with script as end
|