Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. var tape = require("tape");
  2. var utf8 = require("..");
  3. var data = require("fs").readFileSync(require.resolve("./data/utf8.txt")),
  4. dataStr = data.toString("utf8");
  5. tape.test("utf8", function(test) {
  6. test.test(test.name + " - length", function(test) {
  7. test.equal(utf8.length(""), 0, "should return a byte length of zero for an empty string");
  8. test.equal(utf8.length(dataStr), Buffer.byteLength(dataStr), "should return the same byte length as node buffers");
  9. test.end();
  10. });
  11. test.test(test.name + " - read", function(test) {
  12. var comp = utf8.read([], 0, 0);
  13. test.equal(comp, "", "should decode an empty buffer to an empty string");
  14. comp = utf8.read(data, 0, data.length);
  15. test.equal(comp, data.toString("utf8"), "should decode to the same byte data as node buffers");
  16. var longData = Buffer.concat([data, data, data, data]);
  17. comp = utf8.read(longData, 0, longData.length);
  18. test.equal(comp, longData.toString("utf8"), "should decode to the same byte data as node buffers (long)");
  19. var chunkData = new Buffer(data.toString("utf8").substring(0, 8192));
  20. comp = utf8.read(chunkData, 0, chunkData.length);
  21. test.equal(comp, chunkData.toString("utf8"), "should decode to the same byte data as node buffers (chunk size)");
  22. test.end();
  23. });
  24. test.test(test.name + " - write", function(test) {
  25. var buf = new Buffer(0);
  26. test.equal(utf8.write("", buf, 0), 0, "should encode an empty string to an empty buffer");
  27. var len = utf8.length(dataStr);
  28. buf = new Buffer(len);
  29. test.equal(utf8.write(dataStr, buf, 0), len, "should encode to exactly " + len + " bytes");
  30. test.equal(buf.length, data.length, "should encode to a buffer length equal to that of node buffers");
  31. for (var i = 0; i < buf.length; ++i) {
  32. if (buf[i] !== data[i]) {
  33. test.fail("should encode to the same buffer data as node buffers (offset " + i + ")");
  34. return;
  35. }
  36. }
  37. test.pass("should encode to the same buffer data as node buffers");
  38. test.end();
  39. });
  40. });