Skip to content

Commit

Permalink
refactor: 定数名をアッパーキャメルケースに変更
Browse files Browse the repository at this point in the history
test: テストケースをitからtestに変更
  • Loading branch information
Hiroshiba committed Dec 28, 2024
1 parent 9e03466 commit 5a3f596
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
28 changes: 14 additions & 14 deletions src/mock/engineMock/aquestalkLikeMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ enum ParseKanaErrorCode {
const _LOOP_LIMIT = 300;

// AquesTalk 風記法特殊文字
const _UNVOICE_SYMBOL = "_"; // 無声化
const _ACCENT_SYMBOL = "'"; // アクセント位置
const _NOPAUSE_DELIMITER = "/"; // ポーズ無しアクセント句境界
const _PAUSE_DELIMITER = "、"; // ポーズ有りアクセント句境界
const _WIDE_INTERROGATION_MARK = "?"; // 疑問形
const UNVOICE_SYMBOL = "_"; // 無声化
const ACCENT_SYMBOL = "'"; // アクセント位置
const NOPAUSE_DELIMITER = "/"; // ポーズ無しアクセント句境界
const PAUSE_DELIMITER = "、"; // ポーズ有りアクセント句境界
const WIDE_INTERROGATION_MARK = "?"; // 疑問形

// AquesTalk 風記法とモーラの対応。無声母音も含む。(音素長・音高 0 初期化)
const _kana2mora: Record<string, Mora> = {};
Expand All @@ -43,7 +43,7 @@ Object.entries(moraToPhonemes).forEach(([kana, [consonant, vowel]]) => {
// FIXME: バリデーションする
const upperVowel = vowel.toUpperCase();

_kana2mora[_UNVOICE_SYMBOL + kana] = {
_kana2mora[UNVOICE_SYMBOL + kana] = {
text: kana,
consonant: consonant,
consonantLength: consonant ? 0 : undefined,
Expand Down Expand Up @@ -73,7 +73,7 @@ function _textToAccentPhrase(phrase: string): AccentPhrase {
outerLoop += 1;

// 「`'` でアクセント位置」の実装
if (phrase[baseIndex] === _ACCENT_SYMBOL) {
if (phrase[baseIndex] === ACCENT_SYMBOL) {
// 「アクセント位置はちょうど1つ」の実装
if (moras.length === 0) {
throw new Error(
Expand All @@ -96,7 +96,7 @@ function _textToAccentPhrase(phrase: string): AccentPhrase {
// 例: phrase "キャ" -> "キ" 検出 -> "キャ" 検出/上書き -> Mora("キャ")
for (let watchIndex = baseIndex; watchIndex < phrase.length; watchIndex++) {
// アクセント位置特殊文字が来たら探索打ち切り
if (phrase[watchIndex] === _ACCENT_SYMBOL) {
if (phrase[watchIndex] === ACCENT_SYMBOL) {
break;
}
stack += phrase[watchIndex];
Expand Down Expand Up @@ -146,8 +146,8 @@ export function parseKana(text: string): AccentPhrase[] {
// アクセント句境界(`/`か`、`)の出現までインデックス進展
if (
i === text.length ||
text[i] === _PAUSE_DELIMITER ||
text[i] === _NOPAUSE_DELIMITER
text[i] === PAUSE_DELIMITER ||
text[i] === NOPAUSE_DELIMITER
) {
let phrase = text.substring(phraseBase, i);
if (phrase.length === 0) {
Expand All @@ -161,9 +161,9 @@ export function parseKana(text: string): AccentPhrase[] {
phraseBase = i + 1;

// 「`?` で疑問文」の実装
const isInterrogative = phrase.includes(_WIDE_INTERROGATION_MARK);
const isInterrogative = phrase.includes(WIDE_INTERROGATION_MARK);
if (isInterrogative) {
if (phrase.indexOf(_WIDE_INTERROGATION_MARK) !== phrase.length - 1) {
if (phrase.indexOf(WIDE_INTERROGATION_MARK) !== phrase.length - 1) {
throw new Error(
ParseKanaErrorCode.INTERROGATION_MARK_NOT_AT_END.replace(
"{text}",
Expand All @@ -172,13 +172,13 @@ export function parseKana(text: string): AccentPhrase[] {
);
}
// 疑問形はモーラでなくアクセント句属性で表現
phrase = phrase.replace(_WIDE_INTERROGATION_MARK, "");
phrase = phrase.replace(WIDE_INTERROGATION_MARK, "");
}

const accentPhrase = _textToAccentPhrase(phrase);

// 「`、` で無音付き区切り」の実装
if (i < text.length && text[i] === _PAUSE_DELIMITER) {
if (i < text.length && text[i] === PAUSE_DELIMITER) {
accentPhrase.pauseMora = {
text: "、",
consonant: undefined,
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/mock/engineMock/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ beforeEach(() => {
describe("createOpenAPIEngineMock", () => {
const mock = createOpenAPIEngineMock();

it("versionVersionGet", async () => {
test("versionVersionGet", async () => {
const response = await mock.versionVersionGet();
expect(response).toMatchSnapshot();
});

it("audioQueryAudioQueryPost", async () => {
test("audioQueryAudioQueryPost", async () => {
const response = await mock.audioQueryAudioQueryPost({
text: "こんにちは",
speaker: 0,
});
expect(response).toMatchSnapshot();
});

it("synthesisSynthesisPost", async () => {
test("synthesisSynthesisPost", async () => {
const audioQuery = await mock.audioQueryAudioQueryPost({
text: "こんにちは",
speaker: 0,
Expand All @@ -34,7 +34,7 @@ describe("createOpenAPIEngineMock", () => {
expect(await hash(await response.arrayBuffer())).toMatchSnapshot();
});

it("singFrameAudioQuerySingFrameAudioQueryPost", async () => {
test("singFrameAudioQuerySingFrameAudioQueryPost", async () => {
const response = await mock.singFrameAudioQuerySingFrameAudioQueryPost({
speaker: 0,
score: {
Expand All @@ -50,7 +50,7 @@ describe("createOpenAPIEngineMock", () => {
expect(response).toMatchSnapshot();
});

it("frameSynthesisFrameSynthesisPost", async () => {
test("frameSynthesisFrameSynthesisPost", async () => {
const frameAudioQuery =
await mock.singFrameAudioQuerySingFrameAudioQueryPost({
speaker: 0,
Expand All @@ -71,7 +71,7 @@ describe("createOpenAPIEngineMock", () => {
expect(await hash(await response.arrayBuffer())).toMatchSnapshot();
});

it("辞書系", async () => {
test("辞書系", async () => {
let response;

// 単語の追加
Expand Down

0 comments on commit 5a3f596

Please sign in to comment.