encodings_spec.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2019 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 _encodings = require("../../core/encodings");
  24. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  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. for (var _i = 0, _knownEncodingNames = knownEncodingNames; _i < _knownEncodingNames.length; _i++) {
  30. var knownEncodingName = _knownEncodingNames[_i];
  31. var encoding = (0, _encodings.getEncoding)(knownEncodingName);
  32. expect(Array.isArray(encoding)).toEqual(true);
  33. expect(encoding.length).toEqual(256);
  34. var _iteratorNormalCompletion = true;
  35. var _didIteratorError = false;
  36. var _iteratorError = undefined;
  37. try {
  38. for (var _iterator = encoding[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  39. var item = _step.value;
  40. expect(_typeof(item)).toEqual('string');
  41. }
  42. } catch (err) {
  43. _didIteratorError = true;
  44. _iteratorError = err;
  45. } finally {
  46. try {
  47. if (!_iteratorNormalCompletion && _iterator["return"] != null) {
  48. _iterator["return"]();
  49. }
  50. } finally {
  51. if (_didIteratorError) {
  52. throw _iteratorError;
  53. }
  54. }
  55. }
  56. }
  57. });
  58. it('fetches `null` for unknown encoding names', function () {
  59. expect((0, _encodings.getEncoding)('FooBarEncoding')).toEqual(null);
  60. });
  61. });
  62. });