|
| 1 | +import { createMs } from 'enhanced-ms'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | + |
| 4 | +const ms = createMs({ language: 'pt' }); |
| 5 | + |
| 6 | +describe('Portuguese', () => { |
| 7 | + describe('format milliseconds', () => { |
| 8 | + it('formats milliseconds with default options', () => { |
| 9 | + expect(ms(90061)).toBe('1 minuto 30 segundos'); |
| 10 | + expect(ms(90061000)).toBe('1 dia 1 hora 1 minuto 1 segundo'); |
| 11 | + }); |
| 12 | + |
| 13 | + it('returns null for sub one second with default options', () => { |
| 14 | + expect(ms(0)).toBeNull(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('format using short preset', () => { |
| 18 | + expect(ms(90061, 'short')).toBe('1m 30s'); |
| 19 | + expect(ms(90061000, 'short')).toBe('1d 1h'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('format using colon notation preset', () => { |
| 23 | + expect(ms(90061, 'colonNotation')).toBe('01:30'); |
| 24 | + expect(ms(90061000, 'colonNotation')).toBe('25:01:01'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('formats with use abbreviations', () => { |
| 28 | + const options = { useAbbreviations: true }; |
| 29 | + expect(ms(90061, options)).toBe('1m 30s'); |
| 30 | + expect(ms(90061000, options)).toBe('1d 1h 1m 1s'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('formats with unit limit', () => { |
| 34 | + const options = { unitLimit: 1 }; |
| 35 | + expect(ms(90061, options)).toBe('1 minuto'); |
| 36 | + expect(ms(90061000, options)).toBe('1 dia'); |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + describe('parse duration', () => { |
| 41 | + it('parses durations', () => { |
| 42 | + expect(ms('1 minuto 30 segundos')).toBe(90000); |
| 43 | + expect(ms('1m 30s')).toBe(90000); |
| 44 | + expect(ms('1 minuto 30 segundos 61 milissegundos')).toBe(90061); |
| 45 | + expect(ms('1m 30s 61ms')).toBe(90061); |
| 46 | + }); |
| 47 | + |
| 48 | + it('parses portuguese-specific unit names and abbreviations', () => { |
| 49 | + expect(ms('2 meses')).toBe(2 * 2_628_000_000); |
| 50 | + expect(ms('2 semanas')).toBe(2 * 604_800_000); |
| 51 | + expect(ms('2sem')).toBe(2 * 604_800_000); |
| 52 | + }); |
| 53 | + |
| 54 | + it('parses accented portuguese unit names correctly', () => { |
| 55 | + expect(ms('2 séculos')).toBe(2 * 3_153_600_000_000); |
| 56 | + expect(ms('2 milênios')).toBe(2 * 31_536_000_000_000); |
| 57 | + }); |
| 58 | + |
| 59 | + it('returns zero for invalid durations', () => { |
| 60 | + expect(ms('nyr9341')).toBe(0); |
| 61 | + expect(ms('o4utrc89nyt')).toBe(0); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
0 commit comments