1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- /* Copyright 2017 Mozilla Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- 'use strict';
- 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; };
- var _util = require('../../shared/util');
- describe('util', function () {
- describe('bytesToString', function () {
- it('handles non-array arguments', function () {
- expect(function () {
- (0, _util.bytesToString)(null);
- }).toThrow(new Error('Invalid argument for bytesToString'));
- });
- it('handles array arguments with a length not exceeding the maximum', function () {
- expect((0, _util.bytesToString)(new Uint8Array([]))).toEqual('');
- expect((0, _util.bytesToString)(new Uint8Array([102, 111, 111]))).toEqual('foo');
- });
- it('handles array arguments with a length exceeding the maximum', function () {
- var length = 10000;
- var bytes = new Uint8Array(length);
- for (var i = 0; i < length; i++) {
- bytes[i] = 'a'.charCodeAt(0);
- }
- var string = Array(length + 1).join('a');
- expect((0, _util.bytesToString)(bytes)).toEqual(string);
- });
- });
- describe('stringToBytes', function () {
- it('handles non-string arguments', function () {
- expect(function () {
- (0, _util.stringToBytes)(null);
- }).toThrow(new Error('Invalid argument for stringToBytes'));
- });
- it('handles string arguments', function () {
- expect((0, _util.stringToBytes)('')).toEqual(new Uint8Array([]));
- expect((0, _util.stringToBytes)('foo')).toEqual(new Uint8Array([102, 111, 111]));
- });
- });
- describe('stringToPDFString', function () {
- it('handles ISO Latin 1 strings', function () {
- var str = '\x8Dstring\x8E';
- expect((0, _util.stringToPDFString)(str)).toEqual('\u201Cstring\u201D');
- });
- it('handles UTF-16BE strings', function () {
- var str = '\xFE\xFF\x00\x73\x00\x74\x00\x72\x00\x69\x00\x6E\x00\x67';
- expect((0, _util.stringToPDFString)(str)).toEqual('string');
- });
- it('handles empty strings', function () {
- var str1 = '';
- expect((0, _util.stringToPDFString)(str1)).toEqual('');
- var str2 = '\xFE\xFF';
- expect((0, _util.stringToPDFString)(str2)).toEqual('');
- });
- });
- describe('removeNullCharacters', function () {
- it('should not modify string without null characters', function () {
- var str = 'string without null chars';
- expect((0, _util.removeNullCharacters)(str)).toEqual('string without null chars');
- });
- it('should modify string with null characters', function () {
- var str = 'string\x00With\x00Null\x00Chars';
- expect((0, _util.removeNullCharacters)(str)).toEqual('stringWithNullChars');
- });
- });
- describe('ReadableStream', function () {
- it('should return an Object', function () {
- var readable = new _util.ReadableStream();
- expect(typeof readable === 'undefined' ? 'undefined' : _typeof(readable)).toEqual('object');
- });
- it('should have property getReader', function () {
- var readable = new _util.ReadableStream();
- expect(_typeof(readable.getReader)).toEqual('function');
- });
- });
- });
|