Skip to content

Commit af5d41a

Browse files
committed
test: add test
1 parent 70d3f5a commit af5d41a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/textlint-rule-date-weekday-mismatch.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ function reporter(context, config = {}) {
5757
// get weekday from actual date string
5858
const kV = chronoDate.start.knownValues;
5959
const $moment = moment(`${kV.year}-${kV.month}-${kV.day}`, "YYYY-MM-DD", lang);
60+
if (!$moment.isValid()) {
61+
return;
62+
}
6063
const slicedText = text.slice(chronoDate.index);
6164
// (match) or (match)
6265
const match = slicedText.match(/\s*?([(])([^()]+)([)])/);

test/textlint-rule-date-weekday-mismatch-test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ tester.run("rule", rule, {
88
"2016年12月29日(木)",
99
"2016年12月29日(木曜日)",
1010
"2016-12-29(Thursday)",
11-
"2016-12-29(Tsu)"
11+
"2016-12-29(Tsu)",
12+
// invalid date should be ignored
13+
"11月 25日 (火曜日) "
1214
],
1315
invalid: [
1416
// single match
@@ -23,6 +25,17 @@ tester.run("rule", rule, {
2325
}
2426
]
2527
},
28+
{
29+
text: "2017年1月1日(火)",
30+
output: "2017年1月1日(日)",
31+
errors: [
32+
{
33+
message: "2017年1月1日(火) mismatch weekday.\n2017年1月1日(火) => 2017年1月1日(日)",
34+
line: 1,
35+
column: 11
36+
}
37+
]
38+
},
2639
{
2740
text: "Welcome to 2016-12-29(Fri)",
2841
output: "Welcome to 2016-12-29(Thu)",

0 commit comments

Comments
 (0)