diff options
| author | Jack Nagel | 2013-03-13 02:07:01 -0500 |
|---|---|---|
| committer | Jack Nagel | 2013-03-16 13:05:02 -0500 |
| commit | aa69b671b347a7b22daa5bbad7d166fdab45e3e1 (patch) | |
| tree | 664f307cd6f06a5e8e65a928ddf3e6c56c112313 /Library/Homebrew/test | |
| parent | f91df69127967889a5e7ee7ac6decc6842b7b1cc (diff) | |
| download | homebrew-aa69b671b347a7b22daa5bbad7d166fdab45e3e1.tar.bz2 | |
Use a priority queue to select compilers
The existing case-statement with nested if-statements is gross and hard
to extend. Replacing it with a priority queue simplifies the logic and
makes it very easy to add new compilers to the fails_with system, which
we will likely want to do in the future.
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/test_compiler_queue.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Library/Homebrew/test/test_compiler_queue.rb b/Library/Homebrew/test/test_compiler_queue.rb new file mode 100644 index 000000000..6dee1ab37 --- /dev/null +++ b/Library/Homebrew/test/test_compiler_queue.rb @@ -0,0 +1,38 @@ +require 'testing_env' +require 'compilers' + +class CompilerQueueTests < Test::Unit::TestCase + FakeCompiler = Struct.new(:name, :priority) + + def setup + @q = CompilerQueue.new + end + + def test_shovel_returns_self + assert_same @q, (@q << Object.new) + end + + def test_empty + assert @q.empty? + end + + def test_queues_items + a = FakeCompiler.new(:foo, 0) + b = FakeCompiler.new(:bar, 0) + @q << a << b + assert_equal a, @q.pop + assert_equal b, @q.pop + assert_nil @q.pop + end + + def test_pops_items_by_priority + a = FakeCompiler.new(:foo, 0) + b = FakeCompiler.new(:bar, 0.5) + c = FakeCompiler.new(:baz, 1) + @q << a << b << c + assert_equal c, @q.pop + assert_equal b, @q.pop + assert_equal a, @q.pop + assert_nil @q.pop + end +end |
