Skip to content

Commit

Permalink
Moved tests from 'tests/read' directory to 'src/read' directory
Browse files Browse the repository at this point in the history
This refactoring engages in better code organization by moving all test files from the 'tests/read' directory to the 'src/read' directory. Furthermore, support for BigInt numbers was added in the NumberReader utility.
  • Loading branch information
hckhanh committed Feb 26, 2024
1 parent 069c88e commit e9caeb7
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hckhanh/vn-number",
"version": "1.0.9",
"version": "1.1.0",
"exports": "./src/index.ts",
"exclude": [
".github/",
Expand Down
2 changes: 1 addition & 1 deletion tests/read/Billion.test.ts → src/read/Billion.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import Billion from '~/read/Billion'
import Billion from '~/read/Billion.ts'

describe('Billion', function () {
it('should read first number: 2.000.000.000', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/read/Million.test.ts → src/read/Million.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import Million from '~/read/Million'
import Million from '~/read/Million.ts'

describe('Million', function () {
it('should read first number: 10.100.000', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/read/Number.test.ts → src/read/Number.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import Numbers from '~/read/Numbers'
import Numbers from '~/read/Numbers.ts'

describe('Numbers', function () {
it('should read number: 5', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import NumberReader from '~/read/NumberReader'
import NumberReader from '~/read/NumberReader.ts'

describe('NumberReader', function () {
it('should throw error when read number: a.000', function () {
Expand Down Expand Up @@ -128,4 +128,9 @@ describe('NumberReader', function () {
const number: string = '1000000000000000000'
expect(NumberReader.read(number)).to.equal('một tỷ tỷ')
})

it('should read BigInt number: 1.000.000.000.000.000.000', function () {
const number = BigInt('1000000000000000000')
expect(NumberReader.read(number)).to.equal('một tỷ tỷ')
})
})
4 changes: 2 additions & 2 deletions src/read/NumberReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export default class NumberReader {
* @param number the number to read
* @return a string of the number is read in Vietnamese
*/
public static read(number: string | number): string {
const s = typeof number === 'number' ? number.toString() : number
public static read(number: string | number | BigInt): string {
const s = typeof number !== 'string' ? number.toString() : number

const numberGroups = this.getGroupNumbers(s)
const numbers = this.mapToNumbers(numberGroups)
Expand Down
2 changes: 1 addition & 1 deletion tests/read/Thousand.test.ts → src/read/Thousand.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import Thousand from '~/read/Thousand'
import Thousand from '~/read/Thousand.ts'

describe('Thousand', function () {
it('should read number: 060.000', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/read/index.test.ts → src/read/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { readVnNumber } from '~/read'
import { readVnNumber } from '~/read/index.ts'

describe('index', function () {
it('should read number 2.000.000.000 in string', function () {
Expand Down

0 comments on commit e9caeb7

Please sign in to comment.