summaryrefslogtreecommitdiff
path: root/test/coverage/test_coverage.rb
diff options
context:
space:
mode:
authorktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-17 06:48:03 +0000
committerktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-17 06:48:03 +0000
commit9738f96fcfe50b2a605e350bdd40bd7a85665f54 (patch)
treea8495fa0a315ef4015f01db4d158b74987d18277 /test/coverage/test_coverage.rb
parentb077654a2c89485c086e77c337d30a11ff3781c3 (diff)
Introduce pattern matching [EXPERIMENTAL]
[ruby-core:87945] [Feature #14912] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/coverage/test_coverage.rb')
-rw-r--r--test/coverage/test_coverage.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/coverage/test_coverage.rb b/test/coverage/test_coverage.rb
index 30523c3..f88e97e 100644
--- a/test/coverage/test_coverage.rb
+++ b/test/coverage/test_coverage.rb
@@ -359,6 +359,38 @@ class TestCoverage < Test::Unit::TestCase
end;
end
+ def test_branch_coverage_for_pattern_matching
+ result = {
+ :branches=> {
+ [:case, 0, 3, 4, 8, 7] => {[:in, 1, 5, 6, 5, 7]=>2, [:in, 2, 7, 6, 7, 7]=>0, [:else, 3, 3, 4, 8, 7]=>1},
+ [:case, 4, 12, 2, 17, 5] => {[:in, 5, 14, 4, 14, 5]=>2, [:else, 6, 16, 4, 16, 5]=>1}},
+ }
+ assert_coverage(<<~"end;", { branches: true }, result)
+ def foo(x)
+ begin
+ case x
+ in 0
+ 0
+ in 1
+ 1
+ end
+ rescue NoMatchingPatternError
+ end
+
+ case x
+ in 0
+ 0
+ else
+ 1
+ end
+ end
+
+ foo(0)
+ foo(0)
+ foo(2)
+ end;
+ end
+
def test_branch_coverage_for_safe_method_invocation
result = {
:branches=>{