test.js 1.2 KB

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