mirah 0.0.10-java → 0.0.11-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/History.txt +44 -0
  2. data/README.txt +12 -7
  3. data/Rakefile +13 -12
  4. data/examples/SortClosure$__xform_tmp_1.class +0 -0
  5. data/examples/SortClosure$__xform_tmp_2.class +0 -0
  6. data/examples/SortClosure.class +0 -0
  7. data/examples/macros/StringEachChar$Extension1.class +0 -0
  8. data/javalib/mirah-bootstrap.jar +0 -0
  9. data/lib/mirah/appengine_tasks.rb +8 -6
  10. data/lib/mirah/ast/flow.rb +3 -3
  11. data/lib/mirah/ast/structure.rb +23 -2
  12. data/lib/mirah/commands/base.rb +5 -2
  13. data/lib/mirah/commands/base.rb~ +57 -0
  14. data/lib/mirah/commands/run.rb +15 -8
  15. data/lib/mirah/jvm/compiler/java_source.rb +15 -11
  16. data/lib/mirah/jvm/method_lookup.rb~ +247 -0
  17. data/lib/mirah/jvm/types/bitescript_ext.rb +41 -0
  18. data/lib/mirah/jvm/types/boolean.rb +33 -0
  19. data/lib/mirah/jvm/types/factory.rb +43 -3
  20. data/lib/mirah/jvm/types/integers.rb +1 -14
  21. data/lib/mirah/jvm/types/intrinsics.rb +1 -14
  22. data/lib/mirah/jvm/types/source_mirror.rb +6 -3
  23. data/lib/mirah/parser.rb +2 -6
  24. data/lib/mirah/transform/transformer.rb +2 -0
  25. data/lib/mirah/util/argument_processor.rb +33 -12
  26. data/lib/mirah/util/class_loader.rb +7 -2
  27. data/lib/mirah/util/compilation_state.rb +8 -0
  28. data/lib/mirah/version.rb +1 -1
  29. data/lib/mirah/version.rb~ +18 -0
  30. data/test/core/{test_ast.rb → ast_test.rb} +5 -1
  31. data/test/core/{test_commands.rb → commands_test.rb} +29 -2
  32. data/test/core/{test_compilation.rb → compilation_test.rb} +2 -2
  33. data/test/core/{test_env.rb → env_test.rb} +2 -2
  34. data/test/core/{test_macros.rb → macros_test.rb} +2 -2
  35. data/test/core/{test_typer.rb → typer_test.rb} +1 -1
  36. data/test/core/util/argument_processor_test.rb +64 -0
  37. data/test/core/util/class_loader_test.rb +31 -0
  38. data/test/fixtures/my.properties +0 -0
  39. data/test/fixtures/org/foo/A.class +0 -0
  40. data/test/jvm/{test_annotations.rb → annotations_test.rb} +2 -2
  41. data/test/jvm/blocks_test.rb +262 -0
  42. data/test/jvm/bytecode_test_helper.rb +1 -33
  43. data/test/jvm/constructors_test.rb +110 -0
  44. data/test/jvm/{test_enumerable.rb → enumerable_test.rb} +2 -2
  45. data/test/jvm/factory_test.rb +22 -0
  46. data/test/jvm/{test_java_typer.rb → java_typer_test.rb} +1 -1
  47. data/test/jvm/jvm_compiler_test.rb +2162 -0
  48. data/test/jvm/{test_jvm_compiler.rb → jvm_compiler_test.rb~} +43 -220
  49. data/test/jvm/{test_macros.rb → macros_test.rb} +2 -2
  50. data/test/jvm/{test_main_method.rb → main_method_test.rb} +2 -2
  51. data/test/jvm/{test_rescue.rb → rescue_test.rb} +33 -2
  52. data/test/plugins/{test_gwt.rb → gwt_test.rb} +2 -2
  53. data/test/test_helper.rb +40 -0
  54. metadata +33 -33
  55. data/test/jvm/test_blocks.rb +0 -62
@@ -13,7 +13,7 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- class TestJVMCompiler < Test::Unit::TestCase
16
+ class JVMCompilerTest < Test::Unit::TestCase
17
17
  def assert_raise_java(type, message="")
18
18
  ex = assert_raise(NativeException) do
19
19
  yield
@@ -345,14 +345,6 @@ class TestJVMCompiler < Test::Unit::TestCase
345
345
  assert_equal("Hello World!", output)
346
346
  end
347
347
 
348
- def test_constructor
349
- cls, = compile(
350
- "class InitializeTest;def initialize;puts 'Constructed';end;end")
351
- assert_output("Constructed\n") do
352
- cls.new
353
- end
354
- end
355
-
356
348
  def test_method
357
349
  # TODO auto generate a constructor
358
350
  cls, = compile(
@@ -1396,57 +1388,6 @@ class TestJVMCompiler < Test::Unit::TestCase
1396
1388
  assert_equal([nil, "x", nil], f.a.to_a)
1397
1389
  end
1398
1390
 
1399
- def test_constructor_chaining
1400
- foo, = compile(<<-EOF)
1401
- class Foo5
1402
- def initialize(s:String)
1403
- initialize(s, "foo")
1404
- end
1405
-
1406
- def initialize(s:String, f:String)
1407
- @s = s
1408
- @f = f
1409
- end
1410
-
1411
- def f
1412
- @f
1413
- end
1414
-
1415
- def s
1416
- @s
1417
- end
1418
- end
1419
- EOF
1420
-
1421
- instance = foo.new("S")
1422
- assert_equal("S", instance.s)
1423
- assert_equal("foo", instance.f)
1424
-
1425
- instance = foo.new("foo", "bar")
1426
- assert_equal("foo", instance.s)
1427
- assert_equal("bar", instance.f)
1428
- end
1429
-
1430
- def test_super_constructor
1431
- sc_a, sc_b = compile(<<-EOF)
1432
- class SC_A
1433
- def initialize(a:int)
1434
- puts "A"
1435
- end
1436
- end
1437
-
1438
- class SC_B < SC_A
1439
- def initialize
1440
- super(0)
1441
- puts "B"
1442
- end
1443
- end
1444
- EOF
1445
-
1446
- assert_output("A\nB\n") do
1447
- sc_b.new
1448
- end
1449
- end
1450
1391
 
1451
1392
  def test_literal_array
1452
1393
  cls, = compile(<<-EOF)
@@ -1503,15 +1444,6 @@ class TestJVMCompiler < Test::Unit::TestCase
1503
1444
  assert_equal java.lang.String.java_class.array_class, cls.split.class.java_class
1504
1445
  end
1505
1446
 
1506
- def test_empty_constructor
1507
- foo, = compile(<<-EOF)
1508
- class Foo6
1509
- def initialize; end
1510
- end
1511
- EOF
1512
- foo.new
1513
- end
1514
-
1515
1447
  def test_same_field_name
1516
1448
  cls, = compile(<<-EOF)
1517
1449
  class A1
@@ -1546,15 +1478,6 @@ class TestJVMCompiler < Test::Unit::TestCase
1546
1478
  assert !obj.equals(cls.new)
1547
1479
  end
1548
1480
 
1549
- def test_inexact_constructor
1550
- # FIXME: this is a stupid test
1551
- cls, = compile(
1552
- "class EmptyEmpty; def self.empty_empty; t = Thread.new(Thread.new); t.start; begin; t.join; rescue InterruptedException; end; puts 'ok'; end; end")
1553
- assert_output("ok\n") do
1554
- cls.empty_empty
1555
- end
1556
- end
1557
-
1558
1481
  def test_method_lookup_with_overrides
1559
1482
  cls, = compile(<<-EOF)
1560
1483
  class Bar; implements Runnable
@@ -1570,132 +1493,6 @@ class TestJVMCompiler < Test::Unit::TestCase
1570
1493
  # It shouldn't get confused by the Thread(String) constructor.
1571
1494
  end
1572
1495
 
1573
- def test_block
1574
- cls, = compile(<<-EOF)
1575
- thread = Thread.new do
1576
- puts "Hello"
1577
- end
1578
- begin
1579
- thread.run
1580
- thread.join
1581
- rescue
1582
- puts "Uh Oh!"
1583
- end
1584
- EOF
1585
- assert_output("Hello\n") do
1586
- cls.main([].to_java :string)
1587
- end
1588
-
1589
- script, cls = compile(<<-EOF)
1590
- import java.util.Observable
1591
- class MyObservable < Observable
1592
- def initialize
1593
- super
1594
- setChanged
1595
- end
1596
- end
1597
-
1598
- o = MyObservable.new
1599
- o.addObserver {|x, a| puts a}
1600
- o.notifyObservers("Hello Observer")
1601
- EOF
1602
- assert_output("Hello Observer\n") do
1603
- script.main([].to_java :string)
1604
- end
1605
-
1606
- cls, = compile(<<-EOF)
1607
- def foo
1608
- a = "Hello"
1609
- thread = Thread.new do
1610
- puts a
1611
- end
1612
- begin
1613
- a = a + " Closures"
1614
- thread.run
1615
- thread.join
1616
- rescue
1617
- puts "Uh Oh!"
1618
- end
1619
- return
1620
- end
1621
- EOF
1622
- assert_output("Hello Closures\n") do
1623
- cls.foo
1624
- end
1625
-
1626
- cls, = compile(<<-EOF)
1627
- def run(x:Runnable)
1628
- x.run
1629
- end
1630
- def foo
1631
- a = 1
1632
- run {a += 1}
1633
- a
1634
- end
1635
- EOF
1636
- assert_equal(2, cls.foo)
1637
- end
1638
-
1639
- def test_block_with_method_def
1640
- cls, = compile(<<-EOF)
1641
- import java.util.ArrayList
1642
- import java.util.Collections
1643
- list = ArrayList.new(["a", "ABC", "Cats", "b"])
1644
- Collections.sort(list) do
1645
- def equals(a:Object, b:Object)
1646
- String(a).equalsIgnoreCase(String(b))
1647
- end
1648
- def compare(a:Object, b:Object)
1649
- String(a).compareToIgnoreCase(String(b))
1650
- end
1651
- end
1652
- list.each {|x| puts x}
1653
- EOF
1654
-
1655
- assert_output("a\nABC\nb\nCats\n") do
1656
- cls.main(nil)
1657
- end
1658
- end
1659
-
1660
- def test_block_with_abstract_from_object
1661
- # Comparator interface also defines equals(Object) as abstract,
1662
- # but it can be inherited from Object. We test that here.
1663
- cls, = compile(<<-EOF)
1664
- import java.util.ArrayList
1665
- import java.util.Collections
1666
- list = ArrayList.new(["a", "ABC", "Cats", "b"])
1667
- Collections.sort(list) do |a, b|
1668
- String(a).compareToIgnoreCase(String(b))
1669
- end
1670
- list.each {|x| puts x}
1671
- EOF
1672
-
1673
- assert_output("a\nABC\nb\nCats\n") do
1674
- cls.main(nil)
1675
- end
1676
- end
1677
-
1678
- def test_block_with_no_arguments_and_return_value
1679
- cls, = compile(<<-EOF)
1680
- import java.util.concurrent.Callable
1681
- def foo c:Callable
1682
- throws Exception
1683
- puts c.call
1684
- end
1685
- begin
1686
- foo do
1687
- "an object"
1688
- end
1689
- rescue
1690
- puts "never get here"
1691
- end
1692
- EOF
1693
- assert_output("an object\n") do
1694
- cls.main(nil)
1695
- end
1696
- end
1697
-
1698
-
1699
1496
  def test_optional_args
1700
1497
  cls, = compile(<<-EOF)
1701
1498
  def foo(a:int, b:int = 1, c:int = 2)
@@ -1854,6 +1651,15 @@ class TestJVMCompiler < Test::Unit::TestCase
1854
1651
  assert_equal(2, cls.foo(1))
1855
1652
  end
1856
1653
 
1654
+ def test_string_interpolation_method_calls
1655
+ cls, = compile <<-CODE
1656
+ print "apples \#{'oranges'}".replace('apples', 'oranges')
1657
+ CODE
1658
+ assert_output "oranges oranges" do
1659
+ cls.main nil
1660
+ end
1661
+ end
1662
+
1857
1663
  def test_self_dot_static_methods
1858
1664
  cls, = compile(<<-EOF)
1859
1665
  class ClassWithStatics
@@ -1904,22 +1710,6 @@ class TestJVMCompiler < Test::Unit::TestCase
1904
1710
  assert_equal("java.lang.Character$UnicodeBlock", subset.java_class.name)
1905
1711
  end
1906
1712
 
1907
- def test_default_constructor
1908
- script, cls = compile(<<-EOF)
1909
- class DefaultConstructable
1910
- def foo
1911
- "foo"
1912
- end
1913
- end
1914
-
1915
- print DefaultConstructable.new.foo
1916
- EOF
1917
-
1918
- assert_output("foo") do
1919
- script.main(nil)
1920
- end
1921
- end
1922
-
1923
1713
  def test_class_literal
1924
1714
  cls, = compile(<<-EOF)
1925
1715
  def foo
@@ -2349,10 +2139,43 @@ class TestJVMCompiler < Test::Unit::TestCase
2349
2139
  puts c
2350
2140
  EOF
2351
2141
  end
2142
+ <<<<<<< HEAD:test/jvm/jvm_compiler_test.rb
2352
2143
 
2353
2144
  def test_missing_class_with_block_raises_inference_error
2354
2145
  assert_raises Typer::InferenceError do
2355
2146
  compile("Interface Implements_Go do; end")
2356
2147
  end
2357
2148
  end
2149
+
2150
+ def test_bool_equality
2151
+ cls, = compile("puts true == false")
2152
+ assert_output("false\n") do
2153
+ cls.main(nil)
2154
+ end
2155
+ end
2156
+
2157
+ def test_bool_inequality
2158
+ cls, = compile("puts true != false")
2159
+ assert_output("true\n") do
2160
+ =======
2161
+
2162
+ def test_add_args_in_macro
2163
+ cls, = compile(<<-EOF)
2164
+ macro def foo(a)
2165
+ import duby.lang.compiler.Node
2166
+ quote { bar "1", `Node(a.child_nodes.get(0)).child_nodes`, "2"}
2167
+ end
2168
+
2169
+ def bar(a:String, b:String, c:String, d:String)
2170
+ puts "\#{a} \#{b} \#{c} \#{d}"
2171
+ end
2172
+
2173
+ foo(["a", "b"])
2174
+ EOF
2175
+
2176
+ assert_output("1 a b 2\n") do
2177
+ >>>>>>> parser_support:test/test_jvm_compiler.rb
2178
+ cls.main(nil)
2179
+ end
2180
+ end
2358
2181
  end
@@ -13,7 +13,7 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- class TestMacros < Test::Unit::TestCase
16
+ class MacrosTest < Test::Unit::TestCase
17
17
  def test_defmacro
18
18
  cls, = compile(<<-EOF)
19
19
  defmacro bar(x) do
@@ -157,4 +157,4 @@ class TestMacros < Test::Unit::TestCase
157
157
  end
158
158
 
159
159
  end
160
- end
160
+ end
@@ -1,4 +1,4 @@
1
- class TestMainMethod < Test::Unit::TestCase
1
+ class MainMethodTest < Test::Unit::TestCase
2
2
  def test_main_generation_for_file_with_class_of_same_name
3
3
  code = <<-EOC
4
4
  class WithMain
@@ -12,4 +12,4 @@ class TestMainMethod < Test::Unit::TestCase
12
12
  main_class.main(nil)
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -13,7 +13,7 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- class TestRescue < Test::Unit::TestCase
16
+ class RescueTest < Test::Unit::TestCase
17
17
 
18
18
  def test_rescue
19
19
  cls, = compile(<<-EOF)
@@ -130,6 +130,22 @@ class TestRescue < Test::Unit::TestCase
130
130
  cls.foo(false)
131
131
  end
132
132
  assert_equal "java.lang.Exception: !x", ex.message
133
+
134
+ cls, = compile(<<-EOF)
135
+ def foo:long
136
+ begin
137
+ return bar
138
+ rescue Exception => e
139
+ return long(0)
140
+ end
141
+ end
142
+
143
+ def bar
144
+ long(1)
145
+ end
146
+ EOF
147
+
148
+ assert_equal 1, cls.foo
133
149
  end
134
150
 
135
151
  def test_empty_rescues
@@ -148,5 +164,20 @@ class TestRescue < Test::Unit::TestCase
148
164
  end
149
165
  nil
150
166
  EOF
167
+
168
+ cls, = compile(<<-EOF)
169
+ def empty_with_ensure
170
+ begin
171
+ i = 0
172
+ while i < 10
173
+ i += 1
174
+ end
175
+ rescue
176
+ ensure
177
+ puts 'ensuring'
178
+ end
179
+ ""
180
+ end
181
+ EOF
151
182
  end
152
- end
183
+ end
@@ -15,7 +15,7 @@
15
15
 
16
16
  require 'test_helper'
17
17
 
18
- class TestGWT < Test::Unit::TestCase
18
+ class GWTTest < Test::Unit::TestCase
19
19
  include Mirah::AST
20
20
 
21
21
  def test_jsni_static
@@ -66,4 +66,4 @@ class TestGWT < Test::Unit::TestCase
66
66
  arg_size = new_ast.arguments.args.size
67
67
  assert_equal(arg_size, 2)
68
68
  end
69
- end
69
+ end
data/test/test_helper.rb CHANGED
@@ -17,3 +17,43 @@ require 'test/unit'
17
17
  require 'mirah'
18
18
  require 'jruby'
19
19
  require 'turn'
20
+
21
+ module CommonAssertions
22
+ import java.lang.System
23
+ import java.io.PrintStream
24
+
25
+ def assert_include(value, array, message=nil)
26
+ message = build_message message, '<?> does not include <?>', array, value
27
+ assert_block message do
28
+ array.include? value
29
+ end
30
+ end
31
+
32
+ def capture_output
33
+ saved_output = System.out
34
+ saved_stdout = $stdout
35
+ saved_stderr = $stderr
36
+ output = StringIO.new
37
+ System.setOut(PrintStream.new(output.to_outputstream))
38
+ $stdout = output
39
+ $stderr = output
40
+ begin
41
+ yield
42
+ output.rewind
43
+ output.read
44
+ ensure
45
+ System.setOut(saved_output)
46
+ $stdout = saved_stdout
47
+ $stderr = saved_stderr
48
+ end
49
+ end
50
+
51
+ def assert_output(expected, &block)
52
+ assert_equal(expected, capture_output(&block))
53
+ end
54
+
55
+ end
56
+
57
+ class Test::Unit::TestCase
58
+ include CommonAssertions
59
+ end