Skip to content

Commit

Permalink
Merge pull request #5 from textlint/add-test
Browse files Browse the repository at this point in the history
Add test case
  • Loading branch information
azu authored Feb 22, 2017
2 parents 521db13 + 99fb921 commit 6ff8008
Show file tree
Hide file tree
Showing 156 changed files with 9,032 additions and 5 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@
"devDependencies": {
"babel-cli": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-jsdoc-to-assert": "^1.0.1",
"babel-preset-jsdoc-to-assert": "^4.0.0",
"babel-preset-power-assert": "^1.0.0",
"babel-register": "^6.8.0",
"mocha": "^2.3.3",
"glob": "^7.1.1",
"mocha": "^3.2.0",
"power-assert": "^1.4.0",
"textlint": "^6.7.0",
"textlint": "^7.2.2",
"textlint-ast-test": "^1.1.3",
"textlint-rule-no-todo": "^2.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions src/HTMLProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class HTMLProcessor {

static availableExtensions() {
return [
".htm",
".html"
];
}
Expand Down
4 changes: 2 additions & 2 deletions src/html-to-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function mapNodeType(node, parent) {
export function parse(html) {
const ast = hast.parse(html);
const src = new StructuredSource(html);
var tr = traverse(ast);
const tr = traverse(ast);
tr.forEach(function (node) {
if (this.notLeaf) {
// avoid conflict <input type="text" />
Expand All @@ -53,7 +53,7 @@ export function parse(html) {
} else if (node.type === "root") {
// FIXME: workaround, should fix hast
node.type = nodeTypes[node.type];
let position = src.rangeToLocation([0, html.length]);
const position = src.rangeToLocation([0, html.length]);
// reverse adjust
node.position = {
start: {line: position.start.line, column: position.start.column + 1},
Expand Down
24 changes: 24 additions & 0 deletions test/HTMLProcessor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,29 @@ describe("HTMLProcessor-test", function () {
});
});
});
context("support file extensions", function () {
beforeEach(function () {
textlint = new TextLintCore();
textlint.setupProcessors({
HTMLProcessor: HTMLProcessor
});
textlint.setupRules({
"no-todo": require("textlint-rule-no-todo")
});
});
it("support {.html, .htm}", function () {
const fixturePathList = [
path.join(__dirname, "/fixtures/test.html"),
path.join(__dirname, "/fixtures/test.htm")
];
const promises = fixturePathList.map((filePath) => {
return textlint.lintFile(filePath).then(results => {
assert(results.messages.length > 0);
assert(results.filePath === filePath);
});
});
return Promise.all(promises);
});
});
});
});
3 changes: 3 additions & 0 deletions test/ast-test-case/adoption/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"fragment": true
}
1 change: 1 addition & 0 deletions test/ast-test-case/adoption/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a><b><b><p></a>
126 changes: 126 additions & 0 deletions test/ast-test-case/adoption/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"type": "Document",
"children": [
{
"type": "Link",
"tagName": "a",
"properties": {},
"children": [
{
"type": "Html",
"tagName": "b",
"properties": {},
"children": [
{
"type": "Html",
"tagName": "b",
"properties": {},
"children": [
{
"type": "Paragraph",
"tagName": "p",
"properties": {},
"children": [],
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 16
}
},
"range": [
9,
16
],
"raw": "<p></a>"
}
],
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 16
}
},
"range": [
6,
16
],
"raw": "<b><p></a>"
}
],
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 16
}
},
"range": [
3,
16
],
"raw": "<b><b><p></a>"
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 16
}
},
"range": [
0,
16
],
"raw": "<a><b><b><p></a>"
},
{
"type": "Str",
"value": "\n",
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 2,
"column": 0
}
},
"range": [
16,
17
],
"raw": "\n"
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 0
}
},
"range": [
0,
17
],
"raw": "<a><b><b><p></a>\n"
}
2 changes: 2 additions & 0 deletions test/ast-test-case/adoption/result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<a><b><b></b></b></a><b><b><p><a></a>
</p></b></b>
1 change: 1 addition & 0 deletions test/ast-test-case/body-body-attributes/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions test/ast-test-case/body-body-attributes/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html>
<body id="a" title="b" class="c">
<body class="d" onclick="e">
156 changes: 156 additions & 0 deletions test/ast-test-case/body-body-attributes/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"type": "Document",
"children": [
{
"type": "Html",
"tagName": "html",
"properties": {},
"children": [
{
"type": "Str",
"value": "\n",
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 2,
"column": 0
}
},
"range": [
6,
7
],
"raw": "\n"
},
{
"type": "Html",
"tagName": "body",
"properties": {
"id": "a",
"title": "b",
"className": [
"c"
],
"type": "UNKNOWN"
},
"children": [
{
"type": "Str",
"value": "\n",
"loc": {
"start": {
"line": 2,
"column": 33
},
"end": {
"line": 3,
"column": 0
}
},
"range": [
40,
41
],
"raw": "\n"
},
{
"type": "Html",
"tagName": "body",
"properties": {
"className": [
"d"
],
"onclick": "e",
"type": "UNKNOWN"
},
"children": [
{
"type": "Str",
"value": "\n",
"loc": {
"start": {
"line": 3,
"column": 28
},
"end": {
"line": 4,
"column": 0
}
},
"range": [
69,
70
],
"raw": "\n"
}
],
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"range": [
41,
71
],
"raw": "<body class=\"d\" onclick=\"e\">\n"
}
],
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"range": [
7,
71
],
"raw": "<body id=\"a\" title=\"b\" class=\"c\">\n<body class=\"d\" onclick=\"e\">\n"
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"range": [
0,
71
],
"raw": "<html>\n<body id=\"a\" title=\"b\" class=\"c\">\n<body class=\"d\" onclick=\"e\">\n"
}
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 0
}
},
"range": [
0,
70
],
"raw": "<html>\n<body id=\"a\" title=\"b\" class=\"c\">\n<body class=\"d\" onclick=\"e\">\n"
}
3 changes: 3 additions & 0 deletions test/ast-test-case/body-body-attributes/result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html><head></head><body id="a" title="b" class="c" onclick="e">

</body></html>
1 change: 1 addition & 0 deletions test/ast-test-case/body-html-attributes/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions test/ast-test-case/body-html-attributes/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html>
<body id="a" title="b" class="c">
<html class="d" onclick="e">
Loading

0 comments on commit 6ff8008

Please sign in to comment.