forked from persian-tools/persian-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(wordsToNumber): make it functional
- Loading branch information
Showing
4 changed files
with
92 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,76 @@ | ||
import { WordsToNumber } from "../src"; | ||
import { wordsToNumber } from "../src"; | ||
|
||
describe("WordsToNumber", () => { | ||
describe("wordsToNumber", () => { | ||
it("Should convert truly", () => { | ||
expect(WordsToNumber.convert<number>("منفی سه هزار")).toEqual(-3000); | ||
expect(WordsToNumber.convert<number>("سه هزار دویست و دوازده")).toEqual(3212); | ||
expect(WordsToNumber.convert<number>("دوازده هزار بیست دو")).toEqual(12022); | ||
expect(wordsToNumber<number>("منفی سه هزار")).toEqual(-3000); | ||
expect(wordsToNumber<number>("سه هزار دویست و دوازده")).toEqual(3212); | ||
expect(wordsToNumber<number>("دوازده هزار بیست دو")).toEqual(12022); | ||
expect( | ||
WordsToNumber.convert<string>("دوازده هزار بیست دو", { addCommas: true }), | ||
wordsToNumber<string>("دوازده هزار بیست دو", { addCommas: true }), | ||
).toEqual("12,022"); | ||
expect( | ||
WordsToNumber.convert<string>("دوازده هزار و بیست و دو", { addCommas: true }), | ||
wordsToNumber<string>("دوازده هزار و بیست و دو", { addCommas: true }), | ||
).toEqual("12,022"); | ||
}); | ||
|
||
it("Should convert truly and convert to Arabic digits", () => { | ||
expect( | ||
WordsToNumber.convert<string>("منفی سه هزار", { digits: "ar" }), | ||
wordsToNumber<string>("منفی سه هزار", { digits: "ar" }), | ||
).toEqual("-۳۰۰۰"); | ||
expect( | ||
WordsToNumber.convert<string>("سه هزار دویست و دوازده", { digits: "ar" }), | ||
wordsToNumber<string>("سه هزار دویست و دوازده", { digits: "ar" }), | ||
).toEqual("۳۲۱۲"); | ||
expect( | ||
WordsToNumber.convert<string>("دوازده هزار بیست دو", { digits: "ar" }), | ||
wordsToNumber<string>("دوازده هزار بیست دو", { digits: "ar" }), | ||
).toEqual("۱۲۰۲۲"); | ||
expect( | ||
WordsToNumber.convert<string>("دوازده هزار بیست دو", { digits: "ar", addCommas: true }), | ||
wordsToNumber<string>("دوازده هزار بیست دو", { digits: "ar", addCommas: true }), | ||
).toEqual("۱۲,۰۲۲"); | ||
expect( | ||
WordsToNumber.convert<string>("دوازده هزار و بیست و دو", { digits: "ar", addCommas: true }), | ||
wordsToNumber<string>("دوازده هزار و بیست و دو", { digits: "ar", addCommas: true }), | ||
).toEqual("۱۲,۰۲۲"); | ||
expect( | ||
WordsToNumber.convert<string>("چهارصد پنجاه هزار", { digits: "ar", addCommas: true }), | ||
wordsToNumber<string>("چهارصد پنجاه هزار", { digits: "ar", addCommas: true }), | ||
).toEqual("٤٥۰,۰۰۰"); | ||
expect( | ||
WordsToNumber.convert<string>("چهارصد پنجاه هزار", { digits: "ar" }), | ||
wordsToNumber<string>("چهارصد پنجاه هزار", { digits: "ar" }), | ||
).toEqual("٤٥۰۰۰۰"); | ||
}); | ||
|
||
it("Should convert with ordinal words", () => { | ||
expect( | ||
WordsToNumber.convert<string>("منفی ۳ هزار", { digits: "fa", addCommas: true }), | ||
wordsToNumber<string>("منفی ۳ هزار", { digits: "fa", addCommas: true }), | ||
).toEqual("-۳,۰۰۰"); | ||
expect( | ||
WordsToNumber.convert<string>("منفی 3 هزار و 200", { digits: "fa", addCommas: true }), | ||
wordsToNumber<string>("منفی 3 هزار و 200", { digits: "fa", addCommas: true }), | ||
).toEqual("-۳,۲۰۰"); | ||
expect( | ||
WordsToNumber.convert<string>("منفی سه هزارمین", { digits: "fa", addCommas: true }), | ||
wordsToNumber<string>("منفی سه هزارمین", { digits: "fa", addCommas: true }), | ||
).toEqual("-۳,۰۰۰"); | ||
expect( | ||
WordsToNumber.convert<string>("منفی سه هزارمین", { digits: "fa" }), | ||
wordsToNumber<string>("منفی سه هزارمین", { digits: "fa" }), | ||
).toEqual("-۳۰۰۰"); | ||
expect(WordsToNumber.convert<number>("منفی سه هزارمین")).toEqual(-3000); | ||
expect(WordsToNumber.convert<number>("منفی سه هزارم")).toEqual(-3000); | ||
expect(WordsToNumber.convert<string>("منفی سه هزارمین")).not.toEqual("-3000"); | ||
expect(String(WordsToNumber.convert<number>("منفی سه هزارمین"))).toHaveLength(5); | ||
expect(WordsToNumber.convert<number>("منفی سی اُم")).toEqual(-30); | ||
expect(wordsToNumber<number>("منفی سه هزارمین")).toEqual(-3000); | ||
expect(wordsToNumber<number>("منفی سه هزارم")).toEqual(-3000); | ||
expect(wordsToNumber<string>("منفی سه هزارمین")).not.toEqual("-3000"); | ||
expect(String(wordsToNumber<number>("منفی سه هزارمین"))).toHaveLength(5); | ||
expect(wordsToNumber<number>("منفی سی اُم")).toEqual(-30); | ||
expect( | ||
WordsToNumber.convert<number>("سی و سوم", { fuzzy: true }), | ||
wordsToNumber<number>("سی و سوم", { fuzzy: true }), | ||
).toEqual(33); | ||
}); | ||
|
||
it("Should return undefined", () => { | ||
expect( | ||
WordsToNumber.convert<string>("", { digits: "fa", addCommas: true }), | ||
wordsToNumber<string>("", { digits: "fa", addCommas: true }), | ||
).toEqual(""); | ||
// @ts-ignore | ||
expect(WordsToNumber.convert()).toEqual(""); | ||
expect(wordsToNumber()).toEqual(""); | ||
}); | ||
|
||
it("Should works with fuzzy model", () => { | ||
expect( | ||
WordsToNumber.convert<number>("ضد و بنچاه و دو", { fuzzy: true }), | ||
wordsToNumber<number>("ضد و بنچاه و دو", { fuzzy: true }), | ||
).toEqual(152); | ||
}); | ||
}); |