[SCM] ci-tooling packaging branch, master, updated. b7c8e411ae6be6c305dec187825cf6b88e3a0934
Harald Sitter
apachelogger-guest at moszumanska.debian.org
Mon Oct 12 09:09:05 UTC 2015
Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=da01e12
The following commit has been merged in the master branch:
commit da01e124069d877134cb76e963c0759c34385c83
Author: Harald Sitter <sitter at kde.org>
Date: Mon Oct 12 10:51:39 2015 +0200
refactor pattering we now have two patterns
FNMatchPattern is the previous pattern
IncludePattern is the new pattern which essentially is *foo* globbing
---
lib/ci/pattern.rb | 50 +++++++++++++++++++++++++++++++++++++------------
test/test_ci_pattern.rb | 9 +++++++++
2 files changed, 47 insertions(+), 12 deletions(-)
diff --git a/lib/ci/pattern.rb b/lib/ci/pattern.rb
index e7b67cd..a0e0df8 100644
--- a/lib/ci/pattern.rb
+++ b/lib/ci/pattern.rb
@@ -9,24 +9,14 @@ module CI
# include PatternFilter
# end
- # A POSIX regex match pattern.
- # Pattern matching is implemented by File.fnmatch and reperesents a POSIX
- # regex match. Namely a simplified regex as often used for file or path
- # patterns.
- class Pattern
+ # Base class for all patterns
+ class PatternBase
attr_reader :pattern
def initialize(pattern)
@pattern = pattern
end
- # @param reference [String] reference the pattern might match
- # @return true if the pattern matches the refernece
- def match?(reference)
- reference = reference.pattern if reference.respond_to?(:pattern)
- File.fnmatch(@pattern, reference)
- end
-
# Compare self to other.
# Patterns are
# - equal when self matches other and other matches self
@@ -65,7 +55,14 @@ module CI
"#{@pattern}"
end
+ # FIXME returns difference on what you put in
def self.filter(reference, enumerable)
+ if reference.respond_to?(:reject!)
+ enumerable.each do |e, *|
+ reference.reject! { |k, *| e.match?(k) }
+ end
+ return reference
+ end
enumerable.reject { |k, *| !k.match?(reference) }
end
@@ -88,4 +85,33 @@ module CI
new_hash
end
end
+
+ # A POSIX regex match pattern.
+ # Pattern matching is implemented by File.fnmatch and reperesents a POSIX
+ # regex match. Namely a simplified regex as often used for file or path
+ # patterns.
+ class FNMatchPattern < PatternBase
+ # @param reference [String] reference the pattern might match
+ # @return true if the pattern matches the refernece
+ def match?(reference)
+ reference = reference.pattern if reference.respond_to?(:pattern)
+ File.fnmatch(@pattern, reference)
+ end
+ end
+
+ Pattern = FNMatchPattern # Compat
+
+ # Simple .include? pattern. An instance of this pattern matches a reference
+ # if it is included in the reference in any form or fashion at any given
+ # location. It is therefore less accurate than the FNMatchPattern but more
+ # convenient to handle if all patterns are meant to essentially be matches of
+ # the form "*pat*".
+ class IncludePattern < PatternBase
+ # @param reference [String] reference the pattern might match
+ # @return true if the pattern matches the refernece
+ def match?(reference)
+ reference = reference.pattern if reference.respond_to?(:pattern)
+ reference.include?(pattern)
+ end
+ end
end
diff --git a/test/test_ci_pattern.rb b/test/test_ci_pattern.rb
index e6f568a..b1ffdfe 100644
--- a/test/test_ci_pattern.rb
+++ b/test/test_ci_pattern.rb
@@ -68,4 +68,13 @@ class CIPatternTest < TestCase
assert_equal(a[0], 'a/b')
assert_equal(a[1], 'a/*')
end
+
+ def test_include_pattern
+ ref = 'abcDEF'
+ pattern = CI::IncludePattern.new(ref)
+ assert(pattern.match?("yolo#{ref}yolo"))
+ assert(pattern.match?("yolo#{ref}"))
+ assert(pattern.match?("#{ref}yolo"))
+ assert_false(pattern.match?("yolo"))
+ end
end
--
ci-tooling packaging
More information about the pkg-kde-commits
mailing list