summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-05-04 11:02:56 +0100
committerMichael Williamson <mike@zwobble.org>2013-05-04 11:02:56 +0100
commit8cf5cf90366a4f5f8e0efaf3bb39c0c4f8f512e0 (patch)
tree7e8e2e9825ea0758315b6628e37c36b147a0cdb2
parent2fb0cb2820dee31b4e48937586f7f98c7ec8aa61 (diff)
Fix list index 0 matching any paragraph
-rw-r--r--lib/document-matchers.js4
-rw-r--r--tests/document-matchers.tests.js5
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/document-matchers.js b/lib/document-matchers.js
index 58b3204..e681349 100644
--- a/lib/document-matchers.js
+++ b/lib/document-matchers.js
@@ -17,8 +17,8 @@ function Matcher(elementType, styleName) {
Matcher.prototype.matches = function(element) {
return element.type === this._elementType &&
- (!this._styleName || element.styleName === this._styleName) &&
- (!this._listIndex || isList(element, this._listIndex, this._listIsOrdered));
+ (this._styleName === undefined || element.styleName === this._styleName) &&
+ (this._listIndex === undefined || isList(element, this._listIndex, this._listIsOrdered));
}
Matcher.prototype.orderedList = function(levelIndex) {
diff --git a/tests/document-matchers.tests.js b/tests/document-matchers.tests.js
index eef463d..6d77926 100644
--- a/tests/document-matchers.tests.js
+++ b/tests/document-matchers.tests.js
@@ -33,6 +33,11 @@ describe("document-matchers", function() {
assert.ok(matcher.matches(new Paragraph([], {numbering: {level: 1, isOrdered: false}})));
assert.ok(!matcher.matches(new Paragraph([], {numbering: {level: 1, isOrdered: true}})));
});
+
+ test("matchers for lists with index 0 do not match elements that are not lists", function() {
+ var matcher = documentMatchers.paragraph().orderedList(0);
+ assert.ok(!matcher.matches(new Paragraph()));
+ });
});
function paragraphWithStyle(styleName) {