2
0

util_spec.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 _util = require('../../shared/util');
  17. describe('util', function () {
  18. describe('stringToPDFString', function () {
  19. it('handles ISO Latin 1 strings', function () {
  20. var str = '\x8Dstring\x8E';
  21. expect((0, _util.stringToPDFString)(str)).toEqual('\u201Cstring\u201D');
  22. });
  23. it('handles UTF-16BE strings', function () {
  24. var str = '\xFE\xFF\x00\x73\x00\x74\x00\x72\x00\x69\x00\x6E\x00\x67';
  25. expect((0, _util.stringToPDFString)(str)).toEqual('string');
  26. });
  27. it('handles empty strings', function () {
  28. var str1 = '';
  29. expect((0, _util.stringToPDFString)(str1)).toEqual('');
  30. var str2 = '\xFE\xFF';
  31. expect((0, _util.stringToPDFString)(str2)).toEqual('');
  32. });
  33. });
  34. describe('removeNullCharacters', function () {
  35. it('should not modify string without null characters', function () {
  36. var str = 'string without null chars';
  37. expect((0, _util.removeNullCharacters)(str)).toEqual('string without null chars');
  38. });
  39. it('should modify string with null characters', function () {
  40. var str = 'string\x00With\x00Null\x00Chars';
  41. expect((0, _util.removeNullCharacters)(str)).toEqual('stringWithNullChars');
  42. });
  43. });
  44. });