encodings_spec.js 3.1 KB

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