|
1 | 1 | import { describe, it, expect } from 'vitest'; |
2 | | -import numberstring, { comma, group, ordinal, decimal, currency, roman, parse, negative, fraction, year, telephone, percent, spanish, french, german, danish, chinese, hindi, russian, toWords } from '../index.js'; |
| 2 | +import numberstring, { comma, group, ordinal, decimal, currency, roman, parse, negative, fraction, year, telephone, percent, spanish, french, german, danish, chinese, hindi, russian, portuguese, toWords } from '../index.js'; |
3 | 3 |
|
4 | 4 | describe('numberstring', () => { |
5 | 5 | describe('basic conversions', () => { |
@@ -973,6 +973,64 @@ describe('toWords', () => { |
973 | 973 | expect(toWords(42, { lang: 'russian' })).toBe('сорок два'); |
974 | 974 | expect(toWords(42, { lang: 'русский' })).toBe('сорок два'); |
975 | 975 | }); |
| 976 | + |
| 977 | + it('converts to Portuguese', () => { |
| 978 | + expect(toWords(42, { lang: 'pt' })).toBe('quarenta e dois'); |
| 979 | + expect(toWords(42, { lang: 'portuguese' })).toBe('quarenta e dois'); |
| 980 | + expect(toWords(42, { lang: 'português' })).toBe('quarenta e dois'); |
| 981 | + }); |
| 982 | +}); |
| 983 | + |
| 984 | +describe('portuguese', () => { |
| 985 | + it('converts basic numbers', () => { |
| 986 | + expect(portuguese(0)).toBe('zero'); |
| 987 | + expect(portuguese(1)).toBe('um'); |
| 988 | + expect(portuguese(10)).toBe('dez'); |
| 989 | + expect(portuguese(15)).toBe('quinze'); |
| 990 | + expect(portuguese(21)).toBe('vinte e um'); |
| 991 | + expect(portuguese(42)).toBe('quarenta e dois'); |
| 992 | + }); |
| 993 | + |
| 994 | + it('converts hundreds', () => { |
| 995 | + expect(portuguese(100)).toBe('cem'); |
| 996 | + expect(portuguese(101)).toBe('cento e um'); |
| 997 | + expect(portuguese(200)).toBe('duzentos'); |
| 998 | + expect(portuguese(500)).toBe('quinhentos'); |
| 999 | + expect(portuguese(123)).toBe('cento e vinte e três'); |
| 1000 | + }); |
| 1001 | + |
| 1002 | + it('converts thousands', () => { |
| 1003 | + expect(portuguese(1000)).toBe('mil'); |
| 1004 | + expect(portuguese(2000)).toBe('dois mil'); |
| 1005 | + expect(portuguese(1001)).toBe('mil e um'); |
| 1006 | + expect(portuguese(2500)).toBe('dois mil e quinhentos'); |
| 1007 | + expect(portuguese(10000)).toBe('dez mil'); |
| 1008 | + expect(portuguese(100000)).toBe('cem mil'); |
| 1009 | + }); |
| 1010 | + |
| 1011 | + it('converts millions', () => { |
| 1012 | + expect(portuguese(1000000)).toBe('um milhão'); |
| 1013 | + expect(portuguese(2000000)).toBe('dois milhões'); |
| 1014 | + expect(portuguese(1500000)).toBe('um milhão e quinhentos mil'); |
| 1015 | + }); |
| 1016 | + |
| 1017 | + it('uses "e" connector between higher scales and thousands', () => { |
| 1018 | + // This is the specific bug fix - "um milhão e mil" not "um milhão mil" |
| 1019 | + expect(portuguese(1001000)).toBe('um milhão e mil'); |
| 1020 | + expect(portuguese(2001000)).toBe('dois milhões e mil'); |
| 1021 | + expect(portuguese(1002000)).toBe('um milhão e dois mil'); |
| 1022 | + }); |
| 1023 | + |
| 1024 | + it('applies capitalization', () => { |
| 1025 | + expect(portuguese(42, { cap: 'title' })).toBe('Quarenta E Dois'); |
| 1026 | + expect(portuguese(42, { cap: 'upper' })).toBe('QUARENTA E DOIS'); |
| 1027 | + }); |
| 1028 | + |
| 1029 | + it('returns false for invalid input', () => { |
| 1030 | + expect(portuguese(-1)).toBe(false); |
| 1031 | + expect(portuguese(NaN)).toBe(false); |
| 1032 | + expect(portuguese('abc')).toBe(false); |
| 1033 | + }); |
976 | 1034 | }); |
977 | 1035 |
|
978 | 1036 | describe('comma', () => { |
|
0 commit comments