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.

51 lines
1.2 KiB

4 years ago
  1. var assert = require('assert');
  2. var rgbaRegex = require('..');
  3. var rgbaStrings = [
  4. 'rgba(12,34,56, 1)',
  5. 'rgba(255, 255, 255, .9)',
  6. 'rgba(1, 1,1, 0.2)'
  7. ];
  8. var inexactRgbaStrings = [
  9. 'rgba(,,,)',
  10. 'rGba(12,34,56,1)',
  11. 'rgba(12, 34, 200,1) ',
  12. ' rgba(12,34,56,1)',
  13. 'rgba(1,2,,)'
  14. ];
  15. describe('rgba-regex', function() {
  16. describe('exact: true', function() {
  17. it('should return a regex that matches exact rgba strings', function() {
  18. rgbaStrings.forEach(function(rgba) {
  19. assert.ok(rgbaRegex({ exact: true }).test(rgba));
  20. });
  21. });
  22. it('should return a regex that does not match invalid rgba strings', function() {
  23. inexactRgbaStrings.forEach(function(invalidRgba) {
  24. assert.ok(!rgbaRegex({ exact: true }).test(invalidRgba));
  25. });
  26. });
  27. });
  28. describe('g', function() {
  29. it('should match rgba strings', function() {
  30. assert.deepEqual(
  31. rgbaStrings.join('foobar').match(rgbaRegex()),
  32. rgbaStrings
  33. )
  34. });
  35. it('should not match non rgba strings', function() {
  36. assert.deepEqual(
  37. inexactRgbaStrings.join('foobar').match(rgbaRegex()),
  38. ['rGba(12,34,56,1)', 'rgba(12, 34, 200,1)', 'rgba(12,34,56,1)']
  39. );
  40. });
  41. });
  42. });