Skip to content

Commit

Permalink
fix: handleText
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Jan 25, 2022
1 parent 1888eb0 commit 3b858be
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/handleText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export function handleText(content_old: string, info?: {
{
content_new = updateMeta(content_new);
}
else if (/GitBundle.properties$/i.test(file))
else if (/Git(hub)?Bundle\.properties$/i.test(file))
{
content_new
content_new = content_new
.replace(//g, '獲取')
;
}
Expand Down
89 changes: 89 additions & 0 deletions test/handle-text.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { readFile } from 'fs-extra';
import { join } from 'upath2';
import { __plugin_dev_raw_dir, __plugin_downloaded_dir_unzip } from '../lib/const';
import { cn2tw_min } from '@lazy-cjk/zh-convert/min';
import { cn2tw } from '@lazy-cjk/zh-convert';
import { array_unique_overwrite } from 'array-hyper-unique';
import { handleText } from '../lib/handleText';

jest.setTimeout(60 * 1000);

/**
* 繁體
*/
const words = array_unique_overwrite([
`提取`,
].reduce((ls, s) =>
{

ls.push(s);
ls.push(cn2tw_min(s));
ls.push(cn2tw(s));

return ls
}, [] as string[]));

const files = [
'messages/GitBundle.properties',
'messages/GithubBundle.properties',
] as const;

/**
* 檢查原始來源的檔案(簡體)
*/
describe(`src`, () =>
{
files.forEach(file =>
{

test(file, async () =>
{

let text = await readFile(join(__plugin_downloaded_dir_unzip, 'zh', file)).then(m => m.toString());

let actual = await handleText(text, {
file,
});

words.forEach(s =>
{
expect(actual).not.toContain(s)
})

expect(actual).toMatchSnapshot();

});

})

})

/**
* 檢查原始來源的檔案(繁體)
*/
describe(`dev`, () =>
{
files.forEach(file =>
{

test(file, async () =>
{

let text = await readFile(join(__plugin_dev_raw_dir, 'zh', file)).then(m => m.toString());

let actual = await handleText(text, {
file,
});

words.forEach(s =>
{
expect(actual).not.toContain(s)
})

expect(actual).toMatchSnapshot();

});

})

})

0 comments on commit 3b858be

Please sign in to comment.