Skip to content

Commit ce2b024

Browse files
committed
fix(test): always use valid example
1 parent e4ef656 commit ce2b024

File tree

14 files changed

+260
-24
lines changed

14 files changed

+260
-24
lines changed

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"author": "azu",
1212
"license": "MIT",
1313
"devDependencies": {
14-
"textlint": "^5.1.0",
14+
"textlint": "^5.5.1-0",
1515
"textlint-rule-preset-jtf-style": "file:.."
1616
}
1717
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"build": "babel src --out-dir lib --source-maps",
2727
"watch": "babel src --out-dir lib --watch --source-maps",
2828
"prepublish": "npm run --if-present build",
29+
"pretest": "node tool/create-fixtures.js",
2930
"test": "mocha && npm run test:textlint",
3031
"test:textlint": "(cd example && npm t)"
3132
},
@@ -37,6 +38,7 @@
3738
],
3839
"devDependencies": {
3940
"babel": "^5.8.23",
41+
"glob": "^7.0.0",
4042
"mocha": "^2.3.3",
4143
"textlint": "^5.5.1-0",
4244
"textlint-tester": "^0.5.1-0"

src/2.1.5.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function reporter(context) {
3939
return;
4040
}
4141
const text = getSource(node);
42-
const matches = matchCaptureGroupAll(text, /([\uFF65-\uFF9F]+)/);
42+
const matches = matchCaptureGroupAll(text, /([\uFF65-\uFF9F]+)/g);
4343
matches.forEach(match => {
4444
const {index, text} = match;
4545
report(node, {

src/3.1.2.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"use strict";
33
import {isUserWrittenNode} from "./util/node-util";
44
import {matchAll} from "./util/match-index";
5-
5+
import regx from 'regx';
6+
import {japaneseRegExp} from "./util/regexp";
7+
const rx = regx("g");
68
/*
79
3.1.2. 全角文字どうし
810
@@ -18,7 +20,7 @@ function reporter(context) {
1820
}
1921
const text = getSource(node);
2022
// 全角同士の間は半角スペースを入れない
21-
const matchReg = /(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])( )(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])/g;
23+
const matchReg = rx`${japaneseRegExp}( )${japaneseRegExp}`;
2224
const katakakana = /[-]( )[-]/;
2325
matchAll(text, matchReg).forEach(match => {
2426
const {input, captureGroups} = match;

src/4.2.2.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
*/
1313
import {isUserWrittenNode} from "./util/node-util";
1414
import {matchCaptureGroupAll} from "./util/match-index";
15+
import regx from 'regx';
16+
import {japaneseRegExp} from "./util/regexp";
17+
const rx = regx("g");
1518
function reporter(context) {
1619
let {Syntax, RuleError, report, fixer, getSource} = context;
1720
return {
@@ -21,7 +24,7 @@ function reporter(context) {
2124
}
2225
let text = getSource(node);
2326
// 和文で半角の?は利用しない
24-
const matchRegExp = /(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])(\?)/;
27+
const matchRegExp = rx`${japaneseRegExp}(\?)`;
2528
matchCaptureGroupAll(text, matchRegExp).forEach(match => {
2629
const {index} = match;
2730
return report(node, new RuleError("疑問符(?)を使用する場合は「全角」で表記します。", {

test/2.1.5-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ tester.run("2.1.5.カタカナ", rule, {
1919
}
2020
]
2121
},
22+
{
23+
text: `
24+
25+
アジア
26+
27+
`,
28+
output:`
29+
30+
アジア
31+
32+
`,
33+
errors: [
34+
{
35+
message: "カタカナは「全角」で表記します。"
36+
}
37+
]
38+
},
2239
{
2340
text: "ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚",
2441
output: "ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゛゜",

test/3.1.2-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ tester.run("3.1.2. 全角文字どうし", rule, {
2222
]
2323
},
2424
{
25-
text: "これは どういうこと?",
26-
output: "これはどういうこと?",
25+
text: "これは どういうこと",
26+
output: "これはどういうこと",
2727
errors: [
2828
{
2929
message: "原則として、全角文字どうしの間にスペースを入れません。",

test/4.1.1-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ tester.run("4.1.1.句点(。)", rule, {
1010
],
1111
invalid: [
1212
{
13-
text: "A 氏は「5 月に新製品を発売します。」と述べました。",
14-
output: "A 氏は「5 月に新製品を発売します」と述べました。",
13+
text: "A氏は「5月に新製品を発売します。」と述べました。",
14+
output: "A氏は「5月に新製品を発売します」と述べました。",
1515
errors: [
1616
{
1717
message: "文中にかぎかっこが入る場合は、閉じかっこの前に句点を打ちません。",
18-
column: 19
18+
column: 17
1919
}
2020
]
2121
},
2222
{
23-
text: "従業員は約 30,000 人です(関連企業を含みます。)",
24-
output: "従業員は約 30,000 人です(関連企業を含みます)",
23+
text: "従業員は約30,000人です(関連企業を含みます。",
24+
output: "従業員は約30,000人です(関連企業を含みます",
2525
errors: [
2626
{
2727
message: "文中にかぎかっこが入る場合は、閉じかっこの前に句点を打ちません。",
2828
line: 1,
29-
column: 27
29+
column: 25
3030
}
3131
]
3232
}

test/fixer-test.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ import {TextLintCore} from "textlint"
66
import * as fs from "fs";
77
describe("fixer-test", function () {
88
it("should convert expected", function () {
9-
const expected = fs.readFileSync(__dirname + "/fixtures/expected.md", "utf-8");
9+
const expected = fs.readFileSync(__dirname + "/fixtures/output.md", "utf-8");
1010
const textlint = new TextLintCore();
11-
textlint.setupRules(preset.rules, preset.rulesConfig);
12-
return textlint.fixFile(__dirname + "/fixtures/replace.md").then(result => {
13-
const output = result.output;
14-
assert.equal(output, expected);
11+
// all true
12+
textlint.setupRules(preset.rules);
13+
return textlint.fixFile(__dirname + "/fixtures/input.md").then(result => {
14+
assert.equal(result.remainingMessages.length, 0);
15+
const inputs = result.output.split("\n");
16+
const outputs = expected.split("\n");
17+
for (var i = 0; i < inputs.length; i++) {
18+
const input = inputs[i];
19+
const output = outputs[i];
20+
assert.equal(input, output);
21+
}
1522
});
1623
});
1724
});

test/fixtures/expected.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)