Skip to content
Permalink
Browse files
ensure that a block body is created even when the block is empty
  • Loading branch information
baroquebobcat committed Oct 16, 2011
1 parent d8b0641 commit 0a826dd
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
@@ -406,7 +406,7 @@ def transform_iter(node, parent)
Mirah::AST::Block.new(parent, position(node)) do |block|
[
args ? transformer.transform(args, block) : Mirah::AST::Arguments.new(block, position(node)),
body ? transformer.transform(body, block) : nil,
body ? transformer.transform(body, block) : Mirah::AST::Body.new(block, position(node)),
]
end
end
@@ -120,7 +120,7 @@ def compile_ast ast
compiler
end

def compile(code, name = "script" + System.nano_time.to_s)
def compile(code, name = tmp_script_name)
clear_tmp_files
reset_type_factory

@@ -130,6 +130,10 @@ def compile(code, name = "script" + System.nano_time.to_s)

generate_classes compiler
end

def tmp_script_name
"script" + System.nano_time.to_s
end
end


@@ -0,0 +1,62 @@
# 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.

class TestBlocks < Test::Unit::TestCase

def setup
super
clear_tmp_files
reset_type_factory
end

def parse_and_type code, name=tmp_script_name
parse_and_resolve_types name, code
end

#this should probably be a core test
def test_empty_block_parses_and_types_without_error
assert_nothing_raised do
parse_and_type(<<-CODE)
interface Bar do;def run:void;end;end
class Foo
def foo(a:Bar)
1
end
end
Foo.new.foo do
end
CODE
end
end

def test_non_empty_block_parses_and_types_without_error
assert_nothing_raised do
parse_and_type(<<-CODE)
interface Bar do;def run:void;end;end
class Foo
def foo(a:Bar)
1
end
end
Foo.new.foo do
1
end
CODE
end
end

end

0 comments on commit 0a826dd

Please sign in to comment.