aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mammoth/document_matchers.py10
-rw-r--r--tests/styles/document_matcher_tests.py16
2 files changed, 24 insertions, 2 deletions
diff --git a/mammoth/document_matchers.py b/mammoth/document_matchers.py
index af1fd47..d1f8e74 100644
--- a/mammoth/document_matchers.py
+++ b/mammoth/document_matchers.py
@@ -45,6 +45,14 @@ def equal_to(value):
def _operator_equal_to(first, second):
return first.upper() == second.upper()
+
+
+def starts_with(value):
+ return StringMatcher(_operator_starts_with, value)
+
+
+def _operator_starts_with(first, second):
+ return second.upper().startswith(first.upper())
@cobble.data
@@ -54,5 +62,3 @@ class StringMatcher(object):
def matches(self, other):
return self.operator(self.value, other)
-
-
diff --git a/tests/styles/document_matcher_tests.py b/tests/styles/document_matcher_tests.py
index 46893d1..dccf4f1 100644
--- a/tests/styles/document_matcher_tests.py
+++ b/tests/styles/document_matcher_tests.py
@@ -8,3 +8,19 @@ def equal_to_matcher_is_case_insensitive():
matcher = document_matchers.equal_to("Heading 1")
assert_equal(True, matcher.matches("heaDING 1"))
assert_equal(False, matcher.matches("heaDING 2"))
+
+
+@istest
+def starts_with_matcher_matches_string_with_prefix():
+ matcher = document_matchers.starts_with("Heading")
+ assert_equal(True, matcher.matches("Heading"))
+ assert_equal(True, matcher.matches("Heading 1"))
+ assert_equal(False, matcher.matches("Custom Heading"))
+ assert_equal(False, matcher.matches("Head"))
+ assert_equal(False, matcher.matches("Header 2"))
+
+
+@istest
+def starts_with_matcher_is_case_insensitive():
+ matcher = document_matchers.starts_with("Heading")
+ assert_equal(True, matcher.matches("heaDING"))