alle new
This commit is contained in:
erik committed 2026-10-01 06:46:51 +02:00
1 parent da64472251
commit 5b20adee48
1605 files changed
+396517 -1674

No files matched your search

+91
View File
@@ -0,0 +1,91 @@
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: documentMatchers.equalTo("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()));
});
test("highlight matcher does not match non-highlight elements", function() {
var matcher = documentMatchers.highlight();
assert.ok(!matcher.matches(new Paragraph()));
});
test("highlight matcher without color matches all highlight elements", function() {
var matcher = documentMatchers.highlight({});
assert.ok(matcher.matches({type: "highlight", color: "yellow"}));
});
test("highlight matcher with color matches highlight with that color", function() {
var matcher = documentMatchers.highlight({color: "yellow"});
assert.ok(matcher.matches({type: "highlight", color: "yellow"}));
});
test("highlight matcher with color does not match highlights with other colors", function() {
var matcher = documentMatchers.highlight({color: "yellow"});
assert.ok(!matcher.matches({type: "highlight", color: "red"}));
});
function paragraphWithStyle(styleId, styleName) {
return new Paragraph([], {styleId: styleId, styleName: styleName});
}
test("equalTo matcher is case insensitive", function() {
var matcher = documentMatchers.equalTo("Heading 1");
assert.ok(matcher.operator(matcher.operand, "heaDING 1"));
assert.ok(!matcher.operator(matcher.operand, "heaDING 2"));
});
test("startsWith matches strings with prefix", function() {
var matcher = documentMatchers.startsWith("Heading");
assert.ok(matcher.operator(matcher.operand, "Heading"));
assert.ok(matcher.operator(matcher.operand, "Heading 1"));
assert.ok(!matcher.operator(matcher.operand, "Custom Heading"));
assert.ok(!matcher.operator(matcher.operand, "Head"));
assert.ok(!matcher.operator(matcher.operand, "Header 2"));
});
test("startsWith matcher is case insensitive", function() {
var matcher = documentMatchers.startsWith("Heading");
assert.ok(matcher.operator(matcher.operand, "heaDING"));
});
+20
View File
@@ -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"}}));
});
+124
View File
@@ -0,0 +1,124 @@
var hamjest = require("hamjest");
var assertThat = hamjest.assertThat;
var contains = hamjest.contains;
var hasProperties = hamjest.hasProperties;
var tokenise = require("../../../lib/styles/parser/tokeniser").tokenise;
var test = require("../../test")(module);
test("unknown tokens are tokenised", function() {
assertTokens("~", [isToken("unrecognisedCharacter", "~")]);
});
test("empty string is tokenised to end of file token", function() {
assertTokens("", []);
});
test("whitespace is tokenised", function() {
assertTokens(" \t\t ", [isToken("whitespace")]);
});
test("identifiers are tokenised", function() {
assertTokens("Overture", [isToken("identifier", "Overture")]);
});
test("integers are tokenised", function() {
assertTokens("123", [isToken("integer", "123")]);
});
test("strings are tokenised", function() {
assertTokens("'Tristan'", [isToken("string", "Tristan")]);
});
test("escaped string terminators in strings are tokenised", function() {
assertTokens("'Tristan\\''", [isToken("string", "Tristan\\'")]);
});
test("escape sequences in strings are tokenised", function() {
assertTokens("'Tristan\\\\'", [isToken("string", "Tristan\\\\")]);
});
test("unterminated strings are tokenised", function() {
assertTokens("'Tristan", [isToken("unterminated-string", "Tristan")]);
});
test("unterminated strings ending with escaped string terminator are tokenised", function() {
assertTokens("'Tristan\\'", [isToken("unterminated-string", "Tristan\\'")]);
});
test("unterminated strings with unterminated escape are tokenised", function() {
assertTokens("'Tristan\\", [isToken("unterminated-string", "Tristan\\")]);
});
test("unterminated strings with many escape sequences do not cause excessive backtracking", function() {
assertTokens("'" + "\\a".repeat(50), [isToken("unterminated-string", "\\a".repeat(50))]);
});
test("arrows are tokenised", function() {
assertTokens("=>", [isToken("arrow")]);
});
test("classes are tokenised", function() {
assertTokens(".overture", [isToken("dot"), isToken("identifier", "overture")]);
});
test("colons are tokenised", function() {
assertTokens("::", [isToken("colon"), isToken("colon")]);
});
test("greater thans are tokenised", function() {
assertTokens(">>", [isToken("gt"), isToken("gt")]);
});
test("equals are tokenised", function() {
assertTokens("==", [isToken("equals"), isToken("equals")]);
});
test("startsWith symbols are tokenised", function() {
assertTokens("^=^=", [isToken("startsWith"), isToken("startsWith")]);
});
test("open parens are tokenised", function() {
assertTokens("((", [isToken("open-paren"), isToken("open-paren")]);
});
test("close parens are tokenised", function() {
assertTokens("))", [isToken("close-paren"), isToken("close-paren")]);
});
test("open square brackets are tokenised", function() {
assertTokens("[[", [isToken("open-square-bracket"), isToken("open-square-bracket")]);
});
test("close square brackets are tokenised", function() {
assertTokens("]]", [isToken("close-square-bracket"), isToken("close-square-bracket")]);
});
test("choices are tokenised", function() {
assertTokens("||", [isToken("choice"), isToken("choice")]);
});
test("can tokenise multiple tokens", function() {
assertTokens("The Magic Position", [
isToken("identifier", "The"),
isToken("whitespace"),
isToken("identifier", "Magic"),
isToken("whitespace"),
isToken("identifier", "Position")
]);
});
function assertTokens(input, expectedTokens) {
assertThat(
tokenise(input),
contains.apply(null, expectedTokens.concat([isToken("end", null)]))
);
}
function isToken(tokenType, value) {
return hasProperties({
name: tokenType,
value: value
});
}