Permalink
Browse files

Test fixes

  • Loading branch information...
1 parent bc6b158 commit 9541d762b2da86b45d29b44b1c93c7ee14a4eab5 @ribrdb ribrdb committed Apr 20, 2012
View
Binary file not shown.
@@ -45,7 +45,7 @@ class JavaSource < Base
ImplicitReturn = Struct.new(:value)
- def initialize(scoper)
+ def initialize(scoper, typer)
super
end
@@ -178,7 +178,7 @@ def annotation_value(value)
class ClassBuilder
include Helper
- include Mirah::JVM::Compiler::JVMBytecode::JVMLogger
+ include Mirah::Logging::Logged
attr_reader :package, :name, :superclass, :filename, :class_name, :out
attr_reader :interfaces, :abstract
def initialize(builder, name, superclass, interfaces, abstract)
@@ -232,7 +232,7 @@ def add_intrinsics
add_method('kind_of?', [object_type.meta], boolean) do |compiler, call, expression|
compiler.visit(call.target, expression)
if expression
- klass = call.parameters(0).inferred_type!
+ klass = compiler.inferred_type(call.parameters(0))
compiler.method.instanceof(klass.unmeta)
end
end
@@ -16,10 +16,6 @@
class TestCommands < Test::Unit::TestCase
- def teardown
- Mirah::AST.type_factory = nil
- end
-
class RaisesMirahErrorCommand < Mirah::Commands::Base
def execute
execute_base { raise Mirah::MirahError, "just an error" }
View
@@ -1,61 +0,0 @@
-# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
-# All contributing project authors may be found in the NOTICE file.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# TODO refactor this and test_jvm_compiler to use mirah.rb
-require 'test_helper'
-
-class TestMacros < Test::Unit::TestCase
- java_import 'java.lang.System'
-
- def parse(code)
- Mirah::AST.type_factory = Mirah::JVM::Types::TypeFactory.new
- name = "script" + System.nano_time.to_s
- state = Mirah::Util::CompilationState.new
- state.save_extensions = false
- transformer = Mirah::Transform::Transformer.new(state)
- Java::MirahImpl::Builtin.initialize_builtins(transformer)
- ast = Mirah::AST.parse(code, name, true, transformer)
- typer = Mirah::JVM::Typer.new(transformer)
- ast.infer(typer, true)
- typer.resolve(true)
- ast
- end
-
- def test_macro_helper
- script = parse(<<-EOF)
- import duby.lang.compiler.Compiler
-
- def helper(mirah:Compiler)
- name = "foobar"
- mirah.quote { `name` }
- end
- EOF
- end
-
- def test_self_call_in_unquote
- script = parse(<<-EOF)
- import duby.lang.compiler.Compiler
-
- def foobar(name:String)
- name
- end
-
- def helper(mirah:Compiler)
- name = "foobar"
- mirah.quote { `foobar(name)` }
- end
- EOF
- end
-
-end
View
@@ -42,7 +42,7 @@ def parse(text)
def new_typer(n)
@types = SimpleTypes.new(n.to_s)
- @typer = Mirah::Typer::Typer.new(@types, @scopes)
+ @typer = Mirah::Typer::Typer.new(@types, @scopes, nil)
@mirah = Transform::Transformer.new(Mirah::Util::CompilationState.new, @typer)
@typer
end
View
@@ -191,4 +191,41 @@ def foo c:Callable
end
end
+ def test_parameter_used_in_block
+ cls, = compile(<<-EOF)
+ def foo(x:String):void
+ thread = Thread.new do
+ System.out.println "Hello \#{x}"
+ end
+ begin
+ thread.run
+ thread.join
+ rescue
+ System.out.println "Uh Oh!"
+ end
+ end
+
+ foo('there')
+ EOF
+ assert_output("Hello there\n") do
+ cls.main(nil)
+ end
+ end
+
+ def test_block_with_mirah_interface
+ cls, interface = compile(<<-EOF)
+ interface MyProc do
+ def call; returns :void; end
+ end
+ def foo(b:MyProc)
+ b.call
+ end
+ def bar
+ foo {System.out.println "Hi"}
+ end
+ EOF
+ assert_output("Hi\n") do
+ cls.bar
+ end
+ end
end
View
@@ -103,142 +103,4 @@ def foo
map = cls.new.foo
assert_equal("value", map["key"])
end
-
- def test_wide_nonexpressions
- script, cls1, cls2 = compile(<<-EOF)
- class WideA
- def a
- 2.5
- end
- end
-
- class WideB < WideA
- def a
- super
- 3.5
- end
- end
-
- def self.b
- 1.5
- end
-
- 1.5
- WideA.new.a
- WideB.new.a
- b
- EOF
-
- script.main(nil)
- end
-
- def test_parameter_used_in_block
- cls, = compile(<<-EOF)
- def foo(x:String):void
- thread = Thread.new do
- System.out.println "Hello \#{x}"
- end
- begin
- thread.run
- thread.join
- rescue
- System.out.println "Uh Oh!"
- end
- end
-
- foo('there')
- EOF
- assert_output("Hello there\n") do
- cls.main(nil)
- end
- end
-
- def test_colon2
- cls, = compile(<<-EOF)
- def foo
- java.util::HashSet.new
- end
- EOF
-
- assert_kind_of(java.util.HashSet, cls.foo)
- end
-
- def test_colon2_cast
- cls, = compile(<<-EOF)
- def foo(x:Object)
- java.util::Map.Entry(x)
- end
- EOF
-
- entry = java.util.HashMap.new(:a => 1).entrySet.iterator.next
- assert_equal(entry, cls.foo(entry))
- end
-
- def test_covariant_arrays
- cls, = compile(<<-EOF)
- System.out.println java::util::Arrays.toString(String[5])
- EOF
-
- assert_output("[null, null, null, null, null]\n") do
- cls.main(nil)
- end
- end
-
- def test_getClass_on_object_array
- cls, = compile(<<-EOF)
- System.out.println Object[0].getClass.getName
- EOF
-
- assert_output("[Ljava.lang.Object;\n") do
- cls.main(nil)
- end
- end
-
- def test_nil_assign
- cls, = compile(<<-EOF)
- def foo
- a = nil
- a = 'hello'
- a.length
- end
- EOF
-
- assert_equal(5, cls.foo)
-
- cls, = compile(<<-EOF)
- a = nil
- System.out.println a
- EOF
-
- assert_output("null\n") do
- cls.main(nil)
- end
- end
-
- def test_long_generation
- cls, = compile(<<-EOF)
- c = 2_000_000_000_000
- System.out.println c
- EOF
- end
-
- def test_missing_class_with_block_raises_inference_error
- assert_raises Typer::InferenceError do
- compile("Interface Implements_Go do; end")
- end
- end
-
- def test_bool_equality
- cls, = compile("System.out.println true == false")
- assert_output("false\n") do
- cls.main(nil)
- end
- end
-
- def test_bool_inequality
- cls, = compile("System.out.println true != false")
- assert_output("true\n") do
- cls.main(nil)
- end
- end
end
Oops, something went wrong.

0 comments on commit 9541d76

Please sign in to comment.