From 68d8c8140fb6ef1118fa2815243817f8e4f55b59 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 19 Nov 2016 11:54:43 +0000 Subject: Move html-paths and document-matchers to styles module --- test/document-matchers.tests.js | 50 ---------------------------------- test/document-to-html.tests.js | 4 +-- test/html-paths.tests.js | 20 -------------- test/html/simplify.tests.js | 2 +- test/style-reader.tests.js | 4 +-- test/styles/document-matchers.tests.js | 50 ++++++++++++++++++++++++++++++++++ test/styles/html-paths.tests.js | 20 ++++++++++++++ 7 files changed, 75 insertions(+), 75 deletions(-) delete mode 100644 test/document-matchers.tests.js delete mode 100644 test/html-paths.tests.js create mode 100644 test/styles/document-matchers.tests.js create mode 100644 test/styles/html-paths.tests.js (limited to 'test') diff --git a/test/document-matchers.tests.js b/test/document-matchers.tests.js deleted file mode 100644 index b989b2d..0000000 --- a/test/document-matchers.tests.js +++ /dev/null @@ -1,50 +0,0 @@ -var assert = require("assert"); - -var test = require("./test")(module); -var documentMatchers = require("../lib/document-matchers"); -var documents = require("../lib/documents"); -var Paragraph = documents.Paragraph; - -test("paragraph with no options matches any paragraph", function() { - var matcher = documentMatchers.paragraph(); - assert.ok(matcher.matches(new Paragraph())); - 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(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() { - var matcher = documentMatchers.paragraph({list: {isOrdered: true, levelIndex: 1}}); - assert.ok(!matcher.matches(new Paragraph())); - assert.ok(matcher.matches(new Paragraph([], {numbering: {level: 1, isOrdered: true}}))); - assert.ok(!matcher.matches(new Paragraph([], {numbering: {level: 0, isOrdered: true}}))); - assert.ok(!matcher.matches(new Paragraph([], {numbering: {level: 1, isOrdered: false}}))); -}); - -test("unordered-list(index) matches an unordered list with specified level index", function() { - var matcher = documentMatchers.paragraph({list: {isOrdered: false, levelIndex: 1}}); - assert.ok(!matcher.matches(new Paragraph())); - 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({list: {isOrdered: true, levelIndex: 0}}); - assert.ok(!matcher.matches(new Paragraph())); -}); - -function paragraphWithStyle(styleId, styleName) { - return new Paragraph([], {styleId: styleId, styleName: styleName}); -} diff --git a/test/document-to-html.tests.js b/test/document-to-html.tests.js index 6283b1a..b7a0251 100644 --- a/test/document-to-html.tests.js +++ b/test/document-to-html.tests.js @@ -6,10 +6,10 @@ var documentToHtml = require("../lib/document-to-html"); var DocumentConverter = documentToHtml.DocumentConverter; var commentAuthorLabel = documentToHtml.commentAuthorLabel; var test = require("./test")(module); -var htmlPaths = require("../lib/html-paths"); +var htmlPaths = require("../lib/styles/html-paths"); var xml = require("../lib/xml"); var results = require("../lib/results"); -var documentMatchers = require("../lib/document-matchers"); +var documentMatchers = require("../lib/styles/document-matchers"); var Html = require("../lib/html"); diff --git a/test/html-paths.tests.js b/test/html-paths.tests.js deleted file mode 100644 index 8d75b7c..0000000 --- a/test/html-paths.tests.js +++ /dev/null @@ -1,20 +0,0 @@ -var assert = require("assert"); - -var test = require("./test")(module); -var htmlPaths = require("../lib/html-paths"); - - -test("element can match multiple tag names", function() { - var pathPart = htmlPaths.element(["ul", "ol"]); - assert.ok(pathPart.matchesElement({tagName: "ul"})); - assert.ok(pathPart.matchesElement({tagName: "ol"})); - assert.ok(!pathPart.matchesElement({tagName: "p"})); -}); - -test("element matches if attributes are the same", function() { - var pathPart = htmlPaths.element(["p"], {"class": "tip"}); - assert.ok(!pathPart.matchesElement({tagName: "p"})); - assert.ok(!pathPart.matchesElement({tagName: "p", attributes: {"class": "tip help"}})); - assert.ok(pathPart.matchesElement({tagName: "p", attributes: {"class": "tip"}})); -}); - diff --git a/test/html/simplify.tests.js b/test/html/simplify.tests.js index cec4dc5..85d2eb9 100644 --- a/test/html/simplify.tests.js +++ b/test/html/simplify.tests.js @@ -4,7 +4,7 @@ var _ = require("underscore"); var test = require("../test")(module); var html = require("../../lib/html"); -var htmlPaths = require("../../lib/html-paths"); +var htmlPaths = require("../../lib/styles/html-paths"); var nonFreshElement = html.nonFreshElement; var text = html.text; diff --git a/test/style-reader.tests.js b/test/style-reader.tests.js index 3fb5f1f..372e649 100644 --- a/test/style-reader.tests.js +++ b/test/style-reader.tests.js @@ -1,6 +1,6 @@ var assert = require("assert"); -var htmlPaths = require("../lib/html-paths"); -var documentMatchers = require("../lib/document-matchers"); +var htmlPaths = require("../lib/styles/html-paths"); +var documentMatchers = require("../lib/styles/document-matchers"); var styleReader = require("../lib/style-reader"); var results = require("../lib/results"); var test = require("./test")(module); diff --git a/test/styles/document-matchers.tests.js b/test/styles/document-matchers.tests.js new file mode 100644 index 0000000..e36298c --- /dev/null +++ b/test/styles/document-matchers.tests.js @@ -0,0 +1,50 @@ +var assert = require("assert"); + +var test = require("../test")(module); +var documentMatchers = require("../../lib/styles/document-matchers"); +var documents = require("../../lib/documents"); +var Paragraph = documents.Paragraph; + +test("paragraph with no options matches any paragraph", function() { + var matcher = documentMatchers.paragraph(); + assert.ok(matcher.matches(new Paragraph())); + 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(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() { + var matcher = documentMatchers.paragraph({list: {isOrdered: true, levelIndex: 1}}); + assert.ok(!matcher.matches(new Paragraph())); + assert.ok(matcher.matches(new Paragraph([], {numbering: {level: 1, isOrdered: true}}))); + assert.ok(!matcher.matches(new Paragraph([], {numbering: {level: 0, isOrdered: true}}))); + assert.ok(!matcher.matches(new Paragraph([], {numbering: {level: 1, isOrdered: false}}))); +}); + +test("unordered-list(index) matches an unordered list with specified level index", function() { + var matcher = documentMatchers.paragraph({list: {isOrdered: false, levelIndex: 1}}); + assert.ok(!matcher.matches(new Paragraph())); + 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({list: {isOrdered: true, levelIndex: 0}}); + assert.ok(!matcher.matches(new Paragraph())); +}); + +function paragraphWithStyle(styleId, styleName) { + return new Paragraph([], {styleId: styleId, styleName: styleName}); +} diff --git a/test/styles/html-paths.tests.js b/test/styles/html-paths.tests.js new file mode 100644 index 0000000..ab24cec --- /dev/null +++ b/test/styles/html-paths.tests.js @@ -0,0 +1,20 @@ +var assert = require("assert"); + +var test = require("../test")(module); +var htmlPaths = require("../../lib/styles/html-paths"); + + +test("element can match multiple tag names", function() { + var pathPart = htmlPaths.element(["ul", "ol"]); + assert.ok(pathPart.matchesElement({tagName: "ul"})); + assert.ok(pathPart.matchesElement({tagName: "ol"})); + assert.ok(!pathPart.matchesElement({tagName: "p"})); +}); + +test("element matches if attributes are the same", function() { + var pathPart = htmlPaths.element(["p"], {"class": "tip"}); + assert.ok(!pathPart.matchesElement({tagName: "p"})); + assert.ok(!pathPart.matchesElement({tagName: "p", attributes: {"class": "tip help"}})); + assert.ok(pathPart.matchesElement({tagName: "p", attributes: {"class": "tip"}})); +}); + -- cgit v1.2.3