-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JA] Add support for Hiragana #511
Changes from 2 commits
a8db2e4
3ee9da5
835abfa
7da7629
bbb1e2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,27 +2,90 @@ import * as chrono from "../../src/"; | |
import { testSingleCase } from "../test_util"; | ||
|
||
test("Test - Single Expression", function () { | ||
testSingleCase(chrono.ja, "今日感じたことを忘れずに", new Date(2012, 8 - 1, 10, 12), (result) => { | ||
expect(result.index).toBe(0); | ||
expect(result.text).toBe("今日"); | ||
function testToday(pattern: string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you not use a function like this and repeat testSingleCase() for each case? I know it's a lot of duplicated code, but we want to ensure the tests are really straightforward. (e.g. if the expect fails it would be more difficult to see where we break the test). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I absolutely agree with you. |
||
testSingleCase(chrono.ja, `${pattern}感じたことを忘れずに`, new Date(2012, 8 - 1, 10, 12), (result) => { | ||
expect(result.index).toBe(0); | ||
expect(result.text).toBe(pattern); | ||
expect(result.start).not.toBeNull(); | ||
expect(result.start.get("year")).toBe(2012); | ||
expect(result.start.get("month")).toBe(8); | ||
expect(result.start.get("day")).toBe(10); | ||
expect(result.start).toBeDate(new Date(2012, 8 - 1, 10, 12)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, previously, we test too many things. e.g. only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do so accordingly 👍 |
||
}); | ||
} | ||
|
||
expect(result.start).not.toBeNull(); | ||
expect(result.start.get("year")).toBe(2012); | ||
expect(result.start.get("month")).toBe(8); | ||
expect(result.start.get("day")).toBe(10); | ||
testToday("今日"); | ||
testToday("きょう"); | ||
|
||
expect(result.start).toBeDate(new Date(2012, 8 - 1, 10, 12)); | ||
}); | ||
function testYesterday(pattern: string) { | ||
testSingleCase(chrono.ja, `${pattern}の全国観測値ランキング`, new Date(2012, 8 - 1, 10, 12), (result) => { | ||
expect(result.index).toBe(0); | ||
expect(result.text).toBe(pattern); | ||
|
||
testSingleCase(chrono.ja, "昨日の全国観測値ランキング", new Date(2012, 8 - 1, 10, 12), (result) => { | ||
expect(result.index).toBe(0); | ||
expect(result.text).toBe("昨日"); | ||
expect(result.start).not.toBeNull(); | ||
expect(result.start.get("year")).toBe(2012); | ||
expect(result.start.get("month")).toBe(8); | ||
expect(result.start.get("day")).toBe(9); | ||
|
||
expect(result.start).not.toBeNull(); | ||
expect(result.start.get("year")).toBe(2012); | ||
expect(result.start.get("month")).toBe(8); | ||
expect(result.start.get("day")).toBe(9); | ||
expect(result.start).toBeDate(new Date(2012, 8 - 1, 9, 12)); | ||
}); | ||
} | ||
testYesterday("昨日"); | ||
testYesterday("きのう"); | ||
|
||
expect(result.start).toBeDate(new Date(2012, 8 - 1, 9, 12)); | ||
}); | ||
function testTomorrow(pattern: string) { | ||
testSingleCase(chrono.ja, `${pattern}の天気は晴れです`, new Date(2012, 8 - 1, 10, 12), (result) => { | ||
expect(result.index).toBe(0); | ||
expect(result.text).toBe(pattern); | ||
|
||
expect(result.start).not.toBeNull(); | ||
expect(result.start.get("year")).toBe(2012); | ||
expect(result.start.get("month")).toBe(8); | ||
expect(result.start.get("day")).toBe(11); | ||
|
||
expect(result.start).toBeDate(new Date(2012, 8 - 1, 11, 12)); | ||
}); | ||
} | ||
|
||
testTomorrow("明日"); | ||
testTomorrow("あした"); | ||
|
||
function testTonight(pattern: string) { | ||
testSingleCase(chrono.ja, `${pattern}には雨が降るでしょう`, new Date(2012, 8 - 1, 10, 12), (result) => { | ||
expect(result.index).toBe(0); | ||
expect(result.text).toBe(pattern); | ||
|
||
expect(result.start).not.toBeNull(); | ||
expect(result.start.get("year")).toBe(2012); | ||
expect(result.start.get("month")).toBe(8); | ||
expect(result.start.get("day")).toBe(10); | ||
expect(result.start.get("meridiem")).toBe(chrono.Meridiem.PM); | ||
|
||
expect(result.start).toBeDate(new Date(2012, 8 - 1, 10, 22)); | ||
}); | ||
} | ||
|
||
testTonight("今夜"); | ||
testTonight("こんや"); | ||
testTonight("今夕"); | ||
testTonight("こんゆう"); | ||
testTonight("今晩"); | ||
testTonight("こんばん"); | ||
|
||
function testMorning(pattern: string) { | ||
testSingleCase(chrono.ja, `${pattern}食べたパンは美味しかった`, new Date(2012, 8 - 1, 10, 12), (result) => { | ||
expect(result.index).toBe(0); | ||
expect(result.text).toBe(pattern); | ||
|
||
expect(result.start).not.toBeNull(); | ||
expect(result.start.get("year")).toBe(2012); | ||
expect(result.start.get("month")).toBe(8); | ||
expect(result.start.get("day")).toBe(10); | ||
expect(result.start.get("meridiem")).toBe(chrono.Meridiem.AM); | ||
|
||
expect(result.start).toBeDate(new Date(2012, 8 - 1, 10, 6)); | ||
}); | ||
} | ||
testMorning("今朝"); | ||
testMorning("けさ"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
text
notstr
, because your function name is normalizeTextToKanji, not normalizeStrToKanji.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree!