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.

52 lines
1.3 KiB

4 years ago
  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. });