normalize-data-types.test.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { normalize } from '../src/util/dataTypes'
  2. let table = [
  3. ['foo', 'foo'],
  4. ['foo-bar', 'foo-bar'],
  5. ['16/9', '16/9'],
  6. ['16_/_9', '16 / 9'],
  7. // '_'s are converted to spaces except when escaped
  8. ['foo_bar', 'foo bar'],
  9. ['foo__bar', 'foo bar'],
  10. ['foo\\_bar', 'foo_bar'],
  11. // Urls are preserved as-is
  12. [
  13. 'url("https://example.com/abc+def/some-path/2022-01-01-abc/some_underscoered_path")',
  14. 'url("https://example.com/abc+def/some-path/2022-01-01-abc/some_underscoered_path")',
  15. ],
  16. // file-path-like-things without quotes are preserved as-is
  17. ['/foo/bar/baz.png', '/foo/bar/baz.png'],
  18. ['/foo/bar-2/baz.png', '/foo/bar-2/baz.png'],
  19. // var(…) is preserved as is
  20. ['var(--foo)', 'var(--foo)'],
  21. ['var(--headings-h1-size)', 'var(--headings-h1-size)'],
  22. // math functions like calc(…) get spaces around operators
  23. ['calc(1+2)', 'calc(1 + 2)'],
  24. ['calc(100%+1rem)', 'calc(100% + 1rem)'],
  25. ['calc(1+calc(100%-20px))', 'calc(1 + calc(100% - 20px))'],
  26. ['calc(var(--headings-h1-size)*100)', 'calc(var(--headings-h1-size) * 100)'],
  27. [
  28. 'calc(var(--headings-h1-size)*calc(100%+50%))',
  29. 'calc(var(--headings-h1-size) * calc(100% + 50%))',
  30. ],
  31. ['min(1+2)', 'min(1 + 2)'],
  32. ['max(1+2)', 'max(1 + 2)'],
  33. ['clamp(1+2,1+3,1+4)', 'clamp(1 + 2,1 + 3,1 + 4)'],
  34. ['var(--heading-h1-font-size)', 'var(--heading-h1-font-size)'],
  35. ['var(--my-var-with-more-than-3-words)', 'var(--my-var-with-more-than-3-words)'],
  36. ['var(--width, calc(100%+1rem))', 'var(--width, calc(100% + 1rem))'],
  37. // Misc
  38. ['color(0_0_0/1.0)', 'color(0 0 0/1.0)'],
  39. ['color(0_0_0_/_1.0)', 'color(0 0 0 / 1.0)'],
  40. ]
  41. it.each(table)('normalize data: %s', (input, output) => {
  42. expect(normalize(input)).toBe(output)
  43. })