Skip to content

Commit 9446373

Browse files
committed
test: add test case
1 parent 581460a commit 9446373

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/no-doubled-joshi.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ const defaultOptions = {
3939
min_interval: 1,
4040
strict: false
4141
};
42+
43+
4244
export default function (context, options = {}) {
4345
const helper = new RuleHelper(context);
4446
// 最低間隔値
45-
let minInterval = options.min_interval || defaultOptions.min_interval;
46-
let isStrict = options.strict || defaultOptions.strict;
47-
let {Syntax, report, getSource, RuleError} = context;
47+
const minInterval = options.min_interval || defaultOptions.min_interval;
48+
const isStrict = options.strict || defaultOptions.strict;
49+
const {Syntax, report, getSource, RuleError} = context;
4850
return {
4951
[Syntax.Paragraph](node){
5052
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
@@ -89,21 +91,18 @@ export default function (context, options = {}) {
8991
// if difference
9092
let differenceIndex = otherPosition - startPosition;
9193
if (differenceIndex <= minInterval) {
92-
console.log(node);
93-
console.log(text);
94-
console.log(sentences);
95-
console.log(sentence.loc);
96-
console.log(current.word_position);
9794
let originalPosition = source.originalPositionFor({
9895
line: sentence.loc.start.line,
9996
column: sentence.loc.start.column + (current.word_position - 1)
10097
});
101-
report(node, new RuleError(`一文に二回以上利用されている助詞 "${key}" がみつかりました。`, {
98+
// padding position
99+
var padding = {
102100
line: originalPosition.line - 1,
103101
// matchLastToken.word_position start with 1
104102
// this is padding column start with 0 (== -1)
105103
column: originalPosition.column
106-
}));
104+
};
105+
report(node, new RuleError(`一文に二回以上利用されている助詞 "${key}" がみつかりました。`, padding));
107106
}
108107
return current;
109108
});

test/fixtures/test.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# TESTTTTT
1+
# テスト文
22

33
`app.use(middleware)` という形で、_middleware_と呼ばれる関数には`request``response`といったオブジェクトが渡されます。
44
この`request``response`を_middleware_で処理することでログを取ったり、任意のレスポンスを返しことができるようになっています。

test/test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@
22
"use strict";
33
import {TextLintCore} from "textlint";
44
import rule from "../src/no-doubled-joshi";
5-
describe("text", function () {
5+
import assert from "power-assert";
6+
describe("example-test", function () {
67
it("should handle", function () {
78
let textlint = new TextLintCore();
89
textlint.setupRules({
910
"no-doubled-joshi": rule
1011
});
1112
return textlint.lintFile(__dirname + "/fixtures/test.md").then(result => {
12-
console.log(result);
13+
assert.equal(result.messages.length, 1);
14+
let message = result.messages[0];
15+
assert.deepEqual(message, {
16+
ruleId: 'no-doubled-joshi',
17+
message: '一文に二回以上利用されている助詞 "で" がみつかりました。',
18+
line: 4,
19+
column: 43,
20+
severity: 2
21+
});
1322
});
1423
});
1524
});

0 commit comments

Comments
 (0)