Skip to content

Commit

Permalink
add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
PingHuskar committed Jul 14, 2024
1 parent 4a15ccf commit 48a7bef
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
dist
lib
.DS_Store
playground.js
playground.js
coverage
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () =>{
Expand Down Expand Up @@ -300,11 +306,26 @@ 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`, () => {
expect(true).toBe(true)
expect(true).toBe(!false)
expect(false).toBe(false);
expect(false).toBe(!true)
})
})

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);
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Better BahtText",
"main": "index.js",
"scripts": {
"test": "jest"
"test": "jest",
"cv": "jest --coverage"
},
"author": "Chadin Chaipornpisuth",
"license": "ISC",
Expand Down

0 comments on commit 48a7bef

Please sign in to comment.