test-buffer-ascii.js 876 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var Buffer = require('../../').Buffer;
  3. var assert = require('assert');
  4. // ASCII conversion in node.js simply masks off the high bits,
  5. // it doesn't do transliteration.
  6. assert.equal(Buffer.from('hérité').toString('ascii'), 'hC)ritC)');
  7. // 71 characters, 78 bytes. The ’ character is a triple-byte sequence.
  8. var input = 'C’est, graphiquement, la réunion d’un accent aigu ' +
  9. 'et d’un accent grave.';
  10. var expected = 'Cb\u0000\u0019est, graphiquement, la rC)union ' +
  11. 'db\u0000\u0019un accent aigu et db\u0000\u0019un ' +
  12. 'accent grave.';
  13. var buf = Buffer.from(input);
  14. for (var i = 0; i < expected.length; ++i) {
  15. assert.equal(buf.slice(i).toString('ascii'), expected.slice(i));
  16. // Skip remainder of multi-byte sequence.
  17. if (input.charCodeAt(i) > 65535) ++i;
  18. if (input.charCodeAt(i) > 127) ++i;
  19. }