Skip to content

Commit 7c5abb0

Browse files
committed
Implement Context#match_exclustion?
1 parent 372635f commit 7c5abb0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/matrixeval/ruby/context.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ def variants
5151
[main_variant] + rest_variants
5252
end
5353

54+
def match_exclusion?(exclusion)
55+
return false if exclusion.empty?
56+
57+
variants.all? do |variant|
58+
vector_key = variant.vector.key
59+
if exclusion.key?(vector_key)
60+
exclusion[vector_key] == variant.key
61+
else
62+
true
63+
end
64+
end
65+
end
66+
5467
end
5568
end
5669
end

test/matrixeval/ruby/context_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ def test_variants
7474
assert_equal "5.0", @context.variants[2].key
7575
end
7676

77+
def test_match_exclusion
78+
assert @context.match_exclusion?({ "ruby" => "3.0", "rails" => "6.1" })
79+
assert @context.match_exclusion?({ "ruby" => "3.0", "rails" => "6.1", "sidekiq" => "5.0" })
80+
assert @context.match_exclusion?({ "rails" => "6.1", "sidekiq" => "5.0" })
81+
refute @context.match_exclusion?({ "ruby" => "2.7", "rails" => "6.1" })
82+
refute @context.match_exclusion?({ "sidekiq" => "6.0"})
83+
refute @context.match_exclusion?({})
84+
end
85+
7786
def test_all
7887
Matrixeval::Ruby::Config.stubs(:variant_combinations).returns([
7988
[

0 commit comments

Comments
 (0)