util_spec.js 1.8 KB

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