aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/document-matchers.js2
-rw-r--r--tests/document-matchers.tests.js17
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/document-matchers.js b/lib/document-matchers.js
index 9f138ea..5075172 100644
--- a/lib/document-matchers.js
+++ b/lib/document-matchers.js
@@ -16,6 +16,7 @@ function Matcher(elementType, options) {
options = options || {};
this._elementType = elementType;
this._styleId = options.styleId;
+ this._styleName = options.styleName;
if (options.list) {
this._listIndex = options.list.levelIndex;
this._listIsOrdered = options.list.isOrdered;
@@ -25,6 +26,7 @@ function Matcher(elementType, options) {
Matcher.prototype.matches = function(element) {
return element.type === this._elementType &&
(this._styleId === undefined || element.styleId === this._styleId) &&
+ (this._styleName === undefined || element.styleName === this._styleName) &&
(this._listIndex === undefined || isList(element, this._listIndex, this._listIsOrdered));
};
diff --git a/tests/document-matchers.tests.js b/tests/document-matchers.tests.js
index bb51c69..58dbf80 100644
--- a/tests/document-matchers.tests.js
+++ b/tests/document-matchers.tests.js
@@ -9,14 +9,21 @@ describe("document-matchers", function() {
test("paragraph with no options matches any paragraph", function() {
var matcher = documentMatchers.paragraph();
assert.ok(matcher.matches(new Paragraph()));
- assert.ok(matcher.matches(paragraphWithStyleId("Heading1")));
+ assert.ok(matcher.matches(paragraphWithStyle("Heading1", "Heading 1")));
});
test("paragraph style ID only matches paragraphs with that style ID", function() {
var matcher = documentMatchers.paragraph({styleId: "Heading1"});
assert.ok(!matcher.matches(new Paragraph()));
- assert.ok(matcher.matches(paragraphWithStyleId("Heading1")));
- assert.ok(!matcher.matches(paragraphWithStyleId("Heading2")));
+ assert.ok(matcher.matches(paragraphWithStyle("Heading1", "Heading 1")));
+ assert.ok(!matcher.matches(paragraphWithStyle("Heading2", "Heading 2")));
+ });
+
+ test("paragraph style name only matches paragraphs with that style name", function() {
+ var matcher = documentMatchers.paragraph({styleName: "Heading 1"});
+ assert.ok(!matcher.matches(new Paragraph()));
+ assert.ok(matcher.matches(paragraphWithStyle("Heading1", "Heading 1")));
+ assert.ok(!matcher.matches(paragraphWithStyle("Heading2", "Heading 2")));
});
test("ordered-list(index) matches an ordered list with specified level index", function() {
@@ -40,6 +47,6 @@ describe("document-matchers", function() {
});
});
-function paragraphWithStyleId(styleId) {
- return new Paragraph([], {styleId: styleId});
+function paragraphWithStyle(styleId, styleName) {
+ return new Paragraph([], {styleId: styleId, styleName: styleName});
}