summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-05-04 10:31:45 +0100
committerMichael Williamson <mike@zwobble.org>2013-05-04 10:31:45 +0100
commitcdf71ffdfa56ed698513b8a1d424c73967816c38 (patch)
tree13aa643b91ade9ade7e3176c6c73daf60066e11a
parent9787dd5549f3a3d50580755b80292c1d965d018d (diff)
Add tests for document-matchers
-rw-r--r--lib/document-matchers.js3
-rw-r--r--tests/document-matchers.tests.js25
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/document-matchers.js b/lib/document-matchers.js
index 3232a23..a40bde7 100644
--- a/lib/document-matchers.js
+++ b/lib/document-matchers.js
@@ -16,5 +16,6 @@ function Matcher(elementType, styleName) {
}
Matcher.prototype.matches = function(element) {
- return element.type === this.elementType && element.styleName === this.styleName;
+ return element.type === this.elementType &&
+ (!this.styleName || element.styleName === this.styleName);
}
diff --git a/tests/document-matchers.tests.js b/tests/document-matchers.tests.js
new file mode 100644
index 0000000..55fd447
--- /dev/null
+++ b/tests/document-matchers.tests.js
@@ -0,0 +1,25 @@
+var assert = require("assert");
+
+var test = require("./testing").test;
+var documentMatchers = require("../lib/document-matchers");
+var documents = require("../lib/documents");
+
+
+describe("document-matchers", function() {
+ test("paragraph with no style name matches any paragraph", function() {
+ var matcher = documentMatchers.paragraph();
+ assert.ok(matcher.matches(new documents.Paragraph()));
+ assert.ok(matcher.matches(new paragraphWithStyle("Heading1")));
+ });
+
+ test("paragraph style name only matches paragraphs with that style", function() {
+ var matcher = documentMatchers.paragraph("Heading1");
+ assert.ok(!matcher.matches(new documents.Paragraph()));
+ assert.ok(matcher.matches(paragraphWithStyle("Heading1")));
+ assert.ok(!matcher.matches(paragraphWithStyle("Heading2")));
+ });
+});
+
+function paragraphWithStyle(styleName) {
+ return new documents.Paragraph([], {styleName: styleName});
+}