test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var assert = require('assert');
  2. var hslaRegex = require('..');
  3. var hslaStrings = [
  4. 'hsla(111, 12.343%, 0.9%, .1)',
  5. 'hsla(123, 45%, 67%, 1)',
  6. 'hsla(1, 1.111%, 1.1111%, .4)',
  7. 'hsla(1, .111%, .1111%, .123456)'
  8. ];
  9. var inexactHslaStrings = [
  10. 'hsla(,,,)',
  11. 'hsla(12,,,)',
  12. 'hsla(1, 1.111%, 1.1111%, .123) ',
  13. ' hSla(1, 1.111%, 1.1111%, 1)',
  14. 'hsl(1, .111%, .1111%)'
  15. ];
  16. describe('hsla-regex', function() {
  17. describe('exact: true', function() {
  18. it('should return a regex that matches exact hsla strings', function() {
  19. hslaStrings.forEach(function(hsla) {
  20. assert.ok(hslaRegex({ exact: true }).test(hsla));
  21. });
  22. });
  23. it('should return a regex that does not match invalid hsla strings', function() {
  24. inexactHslaStrings.forEach(function(invalidHsl) {
  25. assert.ok(!hslaRegex({ exact: true }).test(invalidHsl));
  26. });
  27. });
  28. });
  29. describe('g', function() {
  30. it('should match hsla strings', function() {
  31. assert.deepEqual(
  32. hslaStrings.join('foobar').match(hslaRegex()),
  33. hslaStrings
  34. )
  35. });
  36. it('should not match non hsla strings', function() {
  37. assert.deepEqual(
  38. inexactHslaStrings.join('foobar').match(hslaRegex()),
  39. ['hsla(1, 1.111%, 1.1111%, .123)', 'hSla(1, 1.111%, 1.1111%, 1)']
  40. );
  41. });
  42. });
  43. });