rubyx/test/util/test_compiler_list.rb

52 lines
1.2 KiB
Ruby
Raw Normal View History

require_relative "../helper"
module Util
class MethodCompiler
include Util::CompilerList
attr_reader :name
def initialize(name)
@name = name
end
end
class TestCompilerListOne < Minitest::Test
def setup
@compiler = MethodCompiler.new(:one)
end
def add_two
@compiler.add_method_compiler MethodCompiler.new(:two)
end
def test_basic_length
assert_equal 1 , @compiler.num_compilers
end
def test_last_empty
assert_equal :one , @compiler.last_compiler.name
end
def test_find_one
assert_equal :one , @compiler.find_compiler{|c| c.name == :one}.name
end
end
class TestCompilerListTwo < Minitest::Test
def setup
@compiler = MethodCompiler.new(:one)
@compiler.add_method_compiler MethodCompiler.new(:two)
end
def test_can_add
assert_equal 2 , @compiler.num_compilers
end
def test_last_two
assert_equal :two , @compiler.last_compiler.name
end
def test_find_two
assert_equal :two , @compiler.find_compiler{|c| c.name == :two}.name
end
def test_each
all = []
@compiler.each_compiler{|c| all << c.name}
assert_equal [:one, :two] , all
end
end
end