test.js 1.2 KB

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