Get the name of a number, even if it's stupidly big.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

55 line
1.4 KiB

  1. import fs from 'fs'
  2. import Converter from '../src'
  3. import English from '../src/systems/en'
  4. describe.each`
  5. name | system | scale
  6. ${'English'} | ${English} | ${'short'}
  7. ${'English'} | ${English} | ${'long'}
  8. `('$name ($scale count)', ({ system, scale, }) => {
  9. let converter: Converter
  10. beforeAll(() => {
  11. converter = new Converter(system)
  12. })
  13. describe('on values', () => {
  14. test.each`
  15. value | name
  16. ${1000000} | ${'one million'}
  17. ${123456789} | ${'one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine'}
  18. `('should parse $value as $name', ({ value, name, }) => {
  19. expect(converter.convert(value, { scale })).toBe(name)
  20. })
  21. })
  22. describe('on streams', () => {
  23. const ENCODING = 'utf-8'
  24. test.each([
  25. 'million.txt'
  26. ])('should correctly parse a stream', async (filename) => {
  27. const inputStream = fs.createReadStream(
  28. `./tests/input/${filename}`,
  29. {
  30. encoding: ENCODING,
  31. highWaterMark: 3, // this is required to parse kilos correctly
  32. }
  33. )
  34. const readStream = converter.readStream({
  35. scale,
  36. encoding: ENCODING
  37. })
  38. inputStream
  39. .pipe(readStream)
  40. .pipe(fs.createWriteStream(`./tests/output/${filename}`))
  41. return new Promise((resolve) => {
  42. readStream.on('end', () => {
  43. resolve('Hello')
  44. })
  45. })
  46. })
  47. })
  48. })