Skip to content

Commit

Permalink
メモ機能・ルビ機能の記法を全角記号にも対応させた (#1709)
Browse files Browse the repository at this point in the history
* テストを追加

* ルビとメモを全角記号対応

* コメントを修正

* .eachを使ってテストの行数を削減

---------

Co-authored-by: Hiroshiba <[email protected]>
  • Loading branch information
weweweok and Hiroshiba authored Jan 13, 2024
1 parent 80a3eb0 commit 06e8721
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 57 deletions.
10 changes: 7 additions & 3 deletions src/store/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,19 @@ export function extractYomiText(

function skipRubyReadingPart(text: string): string {
// テキスト内の全ての{漢字|かんじ}パターンを探し、漢字部分だけを残す
return text.replace(/\{([^|]*)\|([^}]*)\}/g, "$1");
return text
.replace(/\{([^|]*)\|([^}]*)\}/g, "$1")
.replace(/{([^|]*)|([^}]*)}/g, "$1");
}
function skipRubyWritingPart(text: string): string {
// テキスト内の全ての{漢字|かんじ}パターンを探し、かんじ部分だけを残す
return text.replace(/\{([^|]*)\|([^}]*)\}/g, "$2");
return text
.replace(/\{([^|]*)\|([^}]*)\}/g, "$2")
.replace(/{([^|]*)|([^}]*)}/g, "$2");
}
function skipMemoText(targettext: string): string {
// []をスキップ
return targettext.replace(/\[.*?\]/g, "");
return targettext.replace(/\[.*?\]/g, "").replace(/[.*?]/g, "");
}

/**
Expand Down
129 changes: 75 additions & 54 deletions tests/unit/store/utility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,64 +72,85 @@ test("currentDateString", () => {
expect(currentDateString()).toMatch(/\d{4}\d{2}\d{2}/);
});

describe("extractExportTextとextractYomiText", () => {
const memoText = "ダミー]ダミー[メモ]ダミー[ダミー";
const rubyText = "ダミー|}ダミー{漢字|読み}ダミー{|ダミー";
describe.each([
// 半角記号
{
testName: "半角記号",
memoText: "ダミー]ダミー[メモ]ダミー[ダミー",
rubyText: "ダミー|}ダミー{漢字|読み}ダミー{|ダミー",
expectedSkippedMemoText: "ダミー]ダミーダミー[ダミー",
expectedSkippedRubyExportText: "ダミー|}ダミー読みダミー{|ダミー",
expectedSkippedRubyYomiText: "ダミー|}ダミー漢字ダミー{|ダミー",
},
// 全角記号
{
testName: "全角記号",
memoText: "ダミー]ダミー[メモ]ダミー[ダミー",
rubyText: "ダミー|}ダミー{漢字|読み}ダミー{|ダミー",
expectedSkippedMemoText: "ダミー]ダミーダミー[ダミー",
expectedSkippedRubyExportText: "ダミー|}ダミー読みダミー{|ダミー",
expectedSkippedRubyYomiText: "ダミー|}ダミー漢字ダミー{|ダミー",
},
])(
"extractExportTextとextractYomiText $testName",
({
memoText,
rubyText,
expectedSkippedMemoText,
expectedSkippedRubyExportText,
expectedSkippedRubyYomiText,
}) => {
const text = memoText + rubyText;

const text = memoText + rubyText;

const expectedSkippedMemoText = "ダミー]ダミーダミー[ダミー";
const expectedSkippedRubyExportText = "ダミー|}ダミー読みダミー{|ダミー";
const expectedSkippedRubyYomiText = "ダミー|}ダミー漢字ダミー{|ダミー";

it("無指定の場合はそのまま", () => {
const param = {
enableMemoNotation: false,
enableRubyNotation: false,
};
expect(extractExportText(text, param)).toBe(text);
expect(extractYomiText(text, param)).toBe(text);
});
it("無指定の場合はそのまま", () => {
const param = {
enableMemoNotation: false,
enableRubyNotation: false,
};
expect(extractExportText(text, param)).toBe(text);
expect(extractYomiText(text, param)).toBe(text);
});

it("メモをスキップ", () => {
const param = {
enableMemoNotation: true,
enableRubyNotation: false,
};
expect(extractExportText(text, param)).toBe(
expectedSkippedMemoText + rubyText
);
expect(extractYomiText(text, param)).toBe(
expectedSkippedMemoText + rubyText
);
});
it("メモをスキップ", () => {
const param = {
enableMemoNotation: true,
enableRubyNotation: false,
};
expect(extractExportText(text, param)).toBe(
expectedSkippedMemoText + rubyText
);
expect(extractYomiText(text, param)).toBe(
expectedSkippedMemoText + rubyText
);
});

it("ルビをスキップ", () => {
const param = {
enableMemoNotation: false,
enableRubyNotation: true,
};
expect(extractExportText(text, param)).toBe(
memoText + expectedSkippedRubyYomiText
);
expect(extractYomiText(text, param)).toBe(
memoText + expectedSkippedRubyExportText
);
});
it("ルビをスキップ", () => {
const param = {
enableMemoNotation: false,
enableRubyNotation: true,
};
expect(extractExportText(text, param)).toBe(
memoText + expectedSkippedRubyYomiText
);
expect(extractYomiText(text, param)).toBe(
memoText + expectedSkippedRubyExportText
);
});

it("メモとルビをスキップ", () => {
const param = {
enableMemoNotation: true,
enableRubyNotation: true,
};
expect(extractExportText(text, param)).toBe(
expectedSkippedMemoText + expectedSkippedRubyYomiText
);
expect(extractYomiText(text, param)).toBe(
expectedSkippedMemoText + expectedSkippedRubyExportText
);
});
});
it("メモとルビをスキップ", () => {
const param = {
enableMemoNotation: true,
enableRubyNotation: true,
};
expect(extractExportText(text, param)).toBe(
expectedSkippedMemoText + expectedSkippedRubyYomiText
);
expect(extractYomiText(text, param)).toBe(
expectedSkippedMemoText + expectedSkippedRubyExportText
);
});
}
);

describe("TuningTranscription", () => {
it("2つ以上のアクセント句でも正しくデータを転写できる", async () => {
Expand Down

0 comments on commit 06e8721

Please sign in to comment.