encodings_spec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2017 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. 'use strict';
  23. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  24. var _encodings = require('../../core/encodings');
  25. describe('encodings', function () {
  26. describe('getEncoding', function () {
  27. it('fetches a valid array for known encoding names', function () {
  28. var knownEncodingNames = ['ExpertEncoding', 'MacExpertEncoding', 'MacRomanEncoding', 'StandardEncoding', 'SymbolSetEncoding', 'WinAnsiEncoding', 'ZapfDingbatsEncoding'];
  29. var _iteratorNormalCompletion = true;
  30. var _didIteratorError = false;
  31. var _iteratorError = undefined;
  32. try {
  33. for (var _iterator = knownEncodingNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  34. var knownEncodingName = _step.value;
  35. var encoding = (0, _encodings.getEncoding)(knownEncodingName);
  36. expect(Array.isArray(encoding)).toEqual(true);
  37. expect(encoding.length).toEqual(256);
  38. var _iteratorNormalCompletion2 = true;
  39. var _didIteratorError2 = false;
  40. var _iteratorError2 = undefined;
  41. try {
  42. for (var _iterator2 = encoding[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  43. var item = _step2.value;
  44. expect(typeof item === 'undefined' ? 'undefined' : _typeof(item)).toEqual('string');
  45. }
  46. } catch (err) {
  47. _didIteratorError2 = true;
  48. _iteratorError2 = err;
  49. } finally {
  50. try {
  51. if (!_iteratorNormalCompletion2 && _iterator2.return) {
  52. _iterator2.return();
  53. }
  54. } finally {
  55. if (_didIteratorError2) {
  56. throw _iteratorError2;
  57. }
  58. }
  59. }
  60. }
  61. } catch (err) {
  62. _didIteratorError = true;
  63. _iteratorError = err;
  64. } finally {
  65. try {
  66. if (!_iteratorNormalCompletion && _iterator.return) {
  67. _iterator.return();
  68. }
  69. } finally {
  70. if (_didIteratorError) {
  71. throw _iteratorError;
  72. }
  73. }
  74. }
  75. });
  76. it('fetches `null` for unknown encoding names', function () {
  77. expect((0, _encodings.getEncoding)('FooBarEncoding')).toEqual(null);
  78. });
  79. });
  80. });