index.js 878 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. var test = require('tape');
  3. var v = require('es-value-fixtures');
  4. var forEach = require('for-each');
  5. var inspect = require('object-inspect');
  6. var regexTester = require('../');
  7. test('regex tester', function (t) {
  8. t.equal(typeof regexTester, 'function', 'is a function');
  9. t.test('non-regexes', function (st) {
  10. forEach(v.primitives.concat(v.objects), function (val) {
  11. st['throws'](
  12. function () { regexTester(val); },
  13. TypeError,
  14. inspect(val) + ' is not a regex'
  15. );
  16. });
  17. st.end();
  18. });
  19. t.test('regexes', function (st) {
  20. var tester = regexTester(/a/);
  21. st.equal(typeof tester, 'function', 'returns a function');
  22. st.equal(tester('a'), true, 'returns true for a match');
  23. st.equal(tester('b'), false, 'returns false for a non-match');
  24. st.equal(tester('a'), true, 'returns true for a match again');
  25. st.end();
  26. });
  27. t.end();
  28. });