Skip to content

Commit

Permalink
test: use @novel-segment/assert
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Jan 24, 2022
1 parent 8f845b9 commit ddd4f62
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 124 deletions.
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@
"dependencies": {
"@bluelovers/fast-glob": "^3.0.4",
"@lazy-cjk/zh-convert": "^1.0.42",
"@novel-segment/loaders": "^1.0.27",
"@novel-segment/sort-dict-table": "^1.0.1",
"@novel-segment/sort-synonym": "^1.0.1",
"@novel-segment/util-compare": "^1.0.1",
"@novel-segment/assert": "^1.0.2",
"@novel-segment/loaders": "^1.0.28",
"@novel-segment/pretty-diff": "^1.0.2",
"@novel-segment/sort-dict-table": "^1.0.2",
"@novel-segment/sort-synonym": "^1.0.2",
"@novel-segment/stringify": "^1.0.1",
"@novel-segment/util-compare": "^1.0.2",
"@yarn-tool/find-root": "^1.0.61",
"ansi-colors": "^4.1.1",
"array-hyper-unique": "^2.0.6",
Expand All @@ -79,16 +82,16 @@
"cjk-conv": "^1.2.137",
"cli-progress": "^3.10.0",
"crlf-normalize": "^1.0.7",
"cross-fetch": "^3.1.4",
"cross-fetch": "^3.1.5",
"debug-color2": "^1.2.7",
"dot-properties-loader": "^1.0.5",
"dot-properties2": "^1.0.4",
"fs-extra": "^10.0.0",
"jszip": "^3.7.1",
"jszip-fixed-date": "^1.0.3",
"micromatch": "^4.0.4",
"novel-segment": "^2.7.85",
"novel-segment-cli": "^1.1.103",
"novel-segment": "^2.7.86",
"novel-segment-cli": "^1.1.104",
"progress-estimator": "^0.3.0",
"tslib": "^2.3.1",
"upath2": "^3.1.12"
Expand Down
30 changes: 22 additions & 8 deletions test/segment.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { lazyMatchSynonym001, lazyMatchSynonym001Not } from '@novel-segment/assert';
import { processIdeaSegmentText } from '../lib/segment';
import { ITSValueOrArrayMaybeReadonly } from 'ts-type/lib/type/base';

jest.setTimeout(60 * 1000);

type ITestList = [ITSValueOrArrayMaybeReadonly<string>, string][];

/**
* 檢查是否確實轉換
* 通過測試不代表轉換符合預期,因為檢查詞必須要正確設定才可以
Expand All @@ -12,7 +16,7 @@ describe(`segment`, () =>
/**
* 繁體/簡體皆可 但簡體比較能反映真實運作
*/
[
(<ITestList>[
//[`繁體`, `繁體/簡體皆可 但簡體比較能反映真實運作`],

[`打印`, `action.Print.text=打印(_P)…\naction.Print.description=打印文件`],
Expand Down Expand Up @@ -55,15 +59,16 @@ describe(`segment`, () =>
[`插件`, `Kotlin 插件有可用的新版本 {0}。<b><a href="#">安裝</a></b>`],
[`兼容`, `從右到左文本兼容性問題`],

].forEach(text =>
]).forEach(text =>
{

test(text.join(' - '), async () =>
test(_handleTitles(text), async () =>
{

let actual = await processIdeaSegmentText(text[1]);

expect(actual).not.toContain(text[0])
lazyMatchSynonym001Not(actual, [text[0]].flat());
//expect(actual).not.toContain(text[0])
expect(actual).toMatchSnapshot();

});
Expand All @@ -78,27 +83,36 @@ describe(`segment`, () =>
describe(`should include`, () =>
{

[
(<ITestList>[

[`顯示`, `顯示屏幕外圖像`],
[`頁面`, `打开文件或项目。您也可以通过拖放到欢迎屏幕来打开项目或编辑文件。`],
[`頁面`, `显示初始屏幕`],
[`原始碼`, `选择根源代码`],
[`全域類別庫`, `导入的项目引用了未知的全局库`],
[`執行巨集`, `查看、更改、录制、播放宏`],

].forEach(text =>
]).forEach(text =>
{

test(text.join(' - '), async () =>
test(_handleTitles(text), async () =>
{

let actual = await processIdeaSegmentText(text[1]);

expect(actual).toContain(text[0])
lazyMatchSynonym001(actual, [text[0]].flat());
//expect(actual).toContain(text[0])
expect(actual).toMatchSnapshot();

});

});

})

function _handleTitles(actual: [ITSValueOrArrayMaybeReadonly<string>, string])
{
let arr = actual.slice();
arr[0] = [arr[0]].flat().join('/');
return arr.join(' - ')
}
Loading

0 comments on commit ddd4f62

Please sign in to comment.