searchPhoneNumbersInText.test.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. var _searchPhoneNumbersInText = _interopRequireDefault(require("./searchPhoneNumbersInText.js"));
  3. var _metadataMin = _interopRequireDefault(require("../metadata.min.json"));
  4. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  5. function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  6. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  7. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  8. describe('searchPhoneNumbersInText', function () {
  9. it('should find phone numbers (with default country)', function () {
  10. var NUMBERS = ['+78005553535', '+12133734253'];
  11. for (var _iterator = _createForOfIteratorHelperLoose((0, _searchPhoneNumbersInText["default"])('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', _metadataMin["default"])), _step; !(_step = _iterator()).done;) {
  12. var number = _step.value;
  13. number.number.number.should.equal(NUMBERS[0]);
  14. NUMBERS.shift();
  15. }
  16. });
  17. it('should find phone numbers', function () {
  18. var NUMBERS = ['+78005553535', '+12133734253'];
  19. for (var _iterator2 = _createForOfIteratorHelperLoose((0, _searchPhoneNumbersInText["default"])('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', _metadataMin["default"])), _step2; !(_step2 = _iterator2()).done;) {
  20. var number = _step2.value;
  21. number.number.number.should.equal(NUMBERS[0]);
  22. NUMBERS.shift();
  23. }
  24. });
  25. it('should find phone numbers in text', function () {
  26. var expectedNumbers = [{
  27. country: 'RU',
  28. nationalNumber: '8005553535',
  29. startsAt: 14,
  30. endsAt: 32
  31. }, {
  32. country: 'US',
  33. nationalNumber: '2133734253',
  34. startsAt: 41,
  35. endsAt: 55
  36. }];
  37. for (var _iterator3 = _createForOfIteratorHelperLoose((0, _searchPhoneNumbersInText["default"])('The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.', 'US', _metadataMin["default"])), _step3; !(_step3 = _iterator3()).done;) {
  38. var number = _step3.value;
  39. var expected = expectedNumbers.shift();
  40. number.startsAt.should.equal(expected.startsAt);
  41. number.endsAt.should.equal(expected.endsAt);
  42. number.number.nationalNumber.should.equal(expected.nationalNumber);
  43. number.number.country.should.equal(expected.country);
  44. }
  45. expectedNumbers.length.should.equal(0);
  46. });
  47. });
  48. //# sourceMappingURL=searchPhoneNumbersInText.test.js.map