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.
Deze repo is gearchiveerd. U kunt bestanden bekijken en het klonen, maar niet pushen of problemen/pull-requests openen.

59 regels
1.5 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, { scale, })
  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)).toBe(name)
  20. })
  21. })
  22. describe('on streams', () => {
  23. const ENCODING = 'utf-8'
  24. test.each([
  25. 'million',
  26. 'example1',
  27. 'example2',
  28. 'example3',
  29. 'example4',
  30. 'example5',
  31. 'example6',
  32. ])('should correctly parse a stream', async (filename) => {
  33. const inputStream = fs.createReadStream(
  34. `./tests/input/${filename}.txt`,
  35. {
  36. encoding: ENCODING,
  37. }
  38. )
  39. const readStream = converter.readStream({
  40. encoding: ENCODING
  41. })
  42. inputStream
  43. .pipe(readStream)
  44. .pipe(fs.createWriteStream(`./tests/output/${filename}.${scale}.txt`))
  45. return new Promise((resolve) => {
  46. readStream.on('end', () => {
  47. resolve('Hello')
  48. })
  49. })
  50. })
  51. })
  52. })