-
Notifications
You must be signed in to change notification settings - Fork 392
feat(pinyin): convert first of two third tones to second tone #356
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
Open
luojiyin1987
wants to merge
6
commits into
zh-lx:main
Choose a base branch
from
luojiyin1987:feat/third-tone-sandhi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+135
−17
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f0cfde6
feat(pinyin): convert first of two third tones to second tone
luojiyin1987 0d2b0f7
Merge branch 'main' into feat/third-tone-sandhi
luojiyin1987 bdf8bfb
perf(pinyin): detect third tones with light regex instead of tone cla…
luojiyin1987 2608409
docs(pinyin): describe third-tone sandhi in option comments and param…
luojiyin1987 9417b7c
docs(pinyin): add third-tone sandhi reference link
luojiyin1987 30b438f
Merge branch 'main' into feat/third-tone-sandhi
luojiyin1987 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,75 @@ | ||
| import { pinyin } from '../lib/index'; | ||
| import { expect, describe, it } from 'vitest'; | ||
| import { clearCustomDict, customPinyin, pinyin } from '../lib/index'; | ||
| import { afterEach, expect, describe, it } from 'vitest'; | ||
|
|
||
| describe("toneSandhi", () => { | ||
| afterEach(() => { | ||
| clearCustomDict('pinyin'); | ||
| }); | ||
|
|
||
| it("[toneSandhi]不", () => { | ||
| const result = pinyin("不是", { toneSandhi: false }); | ||
| expect(result).to.be.equal("bù shì"); | ||
| }); | ||
|
|
||
| it("changes the first of two consecutive third tones", () => { | ||
| expect(pinyin("你好", { toneSandhi: true })).to.be.equal("ní hǎo"); | ||
| expect(pinyin("你高", { toneSandhi: true })).to.be.equal("nǐ gāo"); | ||
| }); | ||
|
|
||
| it("supports each tone output format", () => { | ||
| expect( | ||
| pinyin("你好", { toneSandhi: true, toneType: "symbol" }), | ||
| ).to.be.equal("ní hǎo"); | ||
| expect( | ||
| pinyin("你好", { toneSandhi: true, toneType: "num" }), | ||
| ).to.be.equal("ni2 hao3"); | ||
| expect( | ||
| pinyin("你好", { toneSandhi: true, toneType: "none" }), | ||
| ).to.be.equal("ni hao"); | ||
| }); | ||
|
|
||
| it("reproduces the issue 286 example", () => { | ||
| expect( | ||
| pinyin("你好", { | ||
| toneSandhi: true, | ||
| type: "array", | ||
| toneType: "num", | ||
| }), | ||
| ).toEqual(["ni2", "hao3"]); | ||
| }); | ||
|
|
||
| it("keeps both third tones when tone sandhi is disabled", () => { | ||
| expect(pinyin("你好", { toneSandhi: false })).to.be.equal("nǐ hǎo"); | ||
| }); | ||
|
|
||
| it("does not apply across non-Chinese boundaries", () => { | ||
| expect(pinyin("你,好", { toneSandhi: true })).to.be.equal("nǐ , hǎo"); | ||
| expect(pinyin("你a好", { toneSandhi: true })).to.be.equal("nǐ a hǎo"); | ||
| }); | ||
|
|
||
| it("handles separate pairs between punctuation boundaries", () => { | ||
| expect(pinyin("你好,很好", { toneSandhi: true })).to.be.equal( | ||
| "ní hǎo , hén hǎo", | ||
| ); | ||
| }); | ||
|
|
||
| it("keeps runs longer than two third tones unchanged", () => { | ||
| expect(pinyin("我很好", { toneSandhi: true })).to.be.equal("wǒ hěn hǎo"); | ||
| expect(pinyin("我想很好", { toneSandhi: true })).to.be.equal( | ||
| "wǒ xiǎng hěn hǎo", | ||
| ); | ||
| }); | ||
|
|
||
| it("uses custom pinyin results for third-tone sandhi", () => { | ||
| customPinyin({ | ||
| 你好: "wǒ hǎo", | ||
| }); | ||
|
|
||
| expect(pinyin("你好", { toneSandhi: true })).to.be.equal("wó hǎo"); | ||
| }); | ||
|
|
||
| it("preserves existing tone sandhi for 一 and 不", () => { | ||
| expect(pinyin("一把", { toneSandhi: true })).to.be.equal("yì bǎ"); | ||
| expect(pinyin("不想", { toneSandhi: true })).to.be.equal("bù xiǎng"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.