From 48a7beffabe9e9be4708a43b86d4f3cb171e17e7 Mon Sep 17 00:00:00 2001 From: Chadin Chaipornpisuth Date: Sun, 14 Jul 2024 22:15:14 +0700 Subject: [PATCH] add coverage --- .gitignore | 3 ++- index.js | 18 +++++++++--------- index.test.js | 23 ++++++++++++++++++++++- package.json | 3 ++- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 62c2d4c..d3f3dcb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules dist lib .DS_Store -playground.js \ No newline at end of file +playground.js +coverage \ No newline at end of file diff --git a/index.js b/index.js index 3ca940e..2322f07 100644 --- a/index.js +++ b/index.js @@ -352,15 +352,14 @@ const IsValidText = (text) => { if (eachdigits.at(i) === "") continue; if (ONETONINE.indexOf(eachdigits.at(i)) === -1) { if (eachdigits.at(i) === SPECIALONE) { - if (sixdigitsword.indexOf(`สิบเอ็ด`) === -1) { - console.log(`line 20`); - return false; - } + // if (sixdigitsword.indexOf(`สิบเอ็ด`) === -1) { + // return false; + // } continue; } else if (eachdigits.at(i) === SPECIALTWO) { - if (sixdigitsword.indexOf(`ยี่สิบ`) === -1) { - return false; - } + // if (sixdigitsword.indexOf(`ยี่สิบ`) === -1) { + // return false; + // } continue; } else { return false; @@ -427,7 +426,8 @@ const TB = (BT, error = `Invalid String`) => { }; const IsValidTB = (str) => { - return str === BT(TB(str)).replace(FULLBAHT, ""); + const BTTB = BT(TB(str)).replace(/\s/g, ""); + return str === BTTB.replace(FULLBAHT, ""); }; const ABT = (money, ed = false) => { @@ -531,7 +531,7 @@ const LNBT = (nameorpowerof10, d=`1`) => { case `string`: try { if (nameorpowerof10 == `Googolplex`) { - return `No Don't Try This` + return `Don't Try This` } const v = large_numbers.find(n => n.name === nameorpowerof10).powof10 if (v < 0) return undefined diff --git a/index.test.js b/index.test.js index 362c3d0..5d57675 100644 --- a/index.test.js +++ b/index.test.js @@ -57,6 +57,12 @@ test("ABT", () => { expect(BR.ABT(`768,601,800,000,000`)).toBe( `เจ็ดร้อยหกสิบแปดล้านหกแสนหนึ่งพันแปดร้อยล้านบาทถ้วน` ); + expect(BR.ABT([123])).toBe( + undefined + ) + expect(BR.ABT(9007199254740992)).toBe( + `เก้าพันเจ็ดล้านหนึ่งแสนเก้าหมื่นเก้าพันสองร้อยห้าสิบสี่ล้านเจ็ดแสนสี่หมื่นเก้าร้อยเก้าสิบสองบาทถ้วน` + ); }); test('PrintSatangs', () =>{ @@ -300,6 +306,9 @@ test(`IsValidText`, () => { expect(BR.IsValidText(null)).toBe(false); expect(BR.IsValidText(0)).toBe(false); expect(BR.IsValidText(123)).toBe(false); + expect(BR.IsValidText(`แสนแสน`)).toBe(false); + expect(BR.IsValidText(`ยี่สิบ`)).toBe(true); + expect(BR.IsValidText(`สองสิบ`)).toBe(false); }); test(`Bool Test`, () => { @@ -307,4 +316,16 @@ test(`Bool Test`, () => { expect(true).toBe(!false) expect(false).toBe(false); expect(false).toBe(!true) -}) \ No newline at end of file +}) + +test(`IsValidTB`, () => { + expect(BR.IsValidTB(`แปดสิบแปดบาท`)).toBe(true); +}); + +test(`LNBT`, () => { + expect(BR.LNBT(`Googolplex`)).toBe(`Don't Try This`); + expect(BR.LNBT(`Septillion`)).toBe(`หนึ่งล้านล้านล้านล้านบาทถ้วน`); + expect(BR.LNBT(`JumNumKaoEpu`)).toBe(undefined); + expect(BR.LNBT(1, 0)).toBe(`ศูนย์บาทถ้วน`); + expect(BR.LNBT([`asdf`])).toBe(undefined); +}); \ No newline at end of file diff --git a/package.json b/package.json index 30f86c7..dc65883 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "Better BahtText", "main": "index.js", "scripts": { - "test": "jest" + "test": "jest", + "cv": "jest --coverage" }, "author": "Chadin Chaipornpisuth", "license": "ISC",