Useful methods for file-related functions.
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.

44 lines
1004 B

  1. import * as fc from 'fast-check'
  2. import getUrlScheme, { UrlScheme } from './getUrlScheme'
  3. it('should exist', () => {
  4. expect(getUrlScheme).toBeDefined()
  5. })
  6. it('should be a callable', () => {
  7. expect(typeof getUrlScheme).toBe('function')
  8. })
  9. it('should accept 1 argument', () => {
  10. expect(getUrlScheme).toHaveLength(1)
  11. })
  12. test.each`
  13. scheme | kind
  14. ${'http'} | ${'HTTP'}
  15. ${'https'} | ${'HTTPS'}
  16. `('should detect $kind URLs', ({ scheme, kind }) => {
  17. fc.assert(
  18. fc.property(fc.webUrl({ validSchemes: [scheme] }), url => {
  19. expect(getUrlScheme(url)).toBe(UrlScheme[kind as keyof typeof UrlScheme])
  20. })
  21. )
  22. })
  23. it('should fall back to local URLs', () => {
  24. fc.assert(
  25. fc.property(
  26. fc.array(
  27. fc.oneof(
  28. fc.string().filter(s => /^[a-zA-Z0-9._-]+$/.test(s)),
  29. fc.constant('..'),
  30. fc.constant('.')
  31. )
  32. ),
  33. pathFragments => {
  34. expect(getUrlScheme(pathFragments.join('/'))).toBe(UrlScheme.FILE)
  35. }
  36. )
  37. )
  38. })