util.test.js 885 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {
  2. limit,
  3. trimAfterFirstMatch,
  4. startsWith,
  5. endsWith
  6. } from './util.js'
  7. describe('findNumbers/util', () =>
  8. {
  9. it('should generate regexp limit', () =>
  10. {
  11. let thrower = () => limit(1, 0)
  12. thrower.should.throw()
  13. thrower = () => limit(-1, 1)
  14. thrower.should.throw()
  15. thrower = () => limit(0, 0)
  16. thrower.should.throw()
  17. })
  18. it('should trimAfterFirstMatch', () =>
  19. {
  20. trimAfterFirstMatch(/\d/, 'abc123').should.equal('abc')
  21. trimAfterFirstMatch(/\d/, 'abc').should.equal('abc')
  22. })
  23. it('should determine if a string starts with a substring', () =>
  24. {
  25. startsWith('𐍈123', '𐍈').should.equal(true)
  26. startsWith('1𐍈', '𐍈').should.equal(false)
  27. })
  28. it('should determine if a string ends with a substring', () =>
  29. {
  30. endsWith('123𐍈', '𐍈').should.equal(true)
  31. endsWith('𐍈1', '𐍈').should.equal(false)
  32. })
  33. })