JAVASCRIPT   56

test.js

Guest on 8th October 2021 06:26:00 PM

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

Raw Paste


Login or Register to edit or fork this paste. It's free.