diff options
| author | Jack Nagel | 2013-03-13 02:07:01 -0500 |
|---|---|---|
| committer | Jack Nagel | 2013-03-16 13:05:02 -0500 |
| commit | f8b4959742393499dda5bb48fd55ba107433b381 (patch) | |
| tree | b97ebf2719aea3211b4cedd800a39331a713ce59 /Library/Homebrew/test | |
| parent | 7104e20bde71a72a99497c8148ebeb10cf97dfde (diff) | |
| download | brew-f8b4959742393499dda5bb48fd55ba107433b381.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 |
