From 52100cdb45e72e9e85b2caae19feca506fc21b46 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Sat, 21 Dec 2013 02:32:52 +0100 Subject: [PATCH] unicode tests and ok test coverage. closes #1 --- test/extract.js | 75 +++++++++++++++++++++++++++++++++- test/fixtures/index.js | 2 + test/fixtures/long-name.tar | Bin 2048 -> 2048 bytes test/fixtures/unicode-bsd.tar | Bin 0 -> 10240 bytes test/fixtures/unicode.tar | Bin 0 -> 2048 bytes test/pack.js | 25 +++++++++++- 6 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/unicode-bsd.tar create mode 100644 test/fixtures/unicode.tar diff --git a/test/extract.js b/test/extract.js index 91fe98b..5f9f6db 100644 --- a/test/extract.js +++ b/test/extract.js @@ -279,7 +279,7 @@ test('long-name', function(t) { mode: 0644, uid: 501, gid: 20, - size: 15, + size: 16, mtime: new Date(1387580181000), type: 'file', linkname: null, @@ -291,7 +291,7 @@ test('long-name', function(t) { stream.pipe(concat(function(data) { noEntries = true; - t.same(data.toString(), 'hello long name'); + t.same(data.toString(), 'hello long name\n'); callback(); })); }); @@ -301,5 +301,76 @@ test('long-name', function(t) { }); extract.end(fs.readFileSync(fixtures.LONG_NAME_TAR)); +}); +test('unicode-bsd', function(t) { // can unpack a bsdtar unicoded tarball + t.plan(3); + + var extract = tar.extract(); + var noEntries = false; + + extract.on('entry', function(header, stream, callback) { + t.deepEqual(header, { + name: 'høllø.txt', + mode: 0644, + uid: 501, + gid: 20, + size: 4, + mtime: new Date(1387588646000), + type: 'file', + linkname: null, + uname: 'maf', + gname: 'staff', + devmajor: 0, + devminor: 0 + }); + + stream.pipe(concat(function(data) { + noEntries = true; + t.same(data.toString(), 'hej\n'); + callback(); + })); + }); + + extract.on('finish', function() { + t.ok(noEntries); + }); + + extract.end(fs.readFileSync(fixtures.UNICODE_BSD_TAR)); +}); + +test('unicode', function(t) { // can unpack a bsdtar unicoded tarball + t.plan(3); + + var extract = tar.extract(); + var noEntries = false; + + extract.on('entry', function(header, stream, callback) { + t.deepEqual(header, { + name: 'høstål.txt', + mode: 0644, + uid: 501, + gid: 20, + size: 8, + mtime: new Date(1387580181000), + type: 'file', + linkname: null, + uname: 'maf', + gname: 'staff', + devmajor: 0, + devminor: 0 + }); + + stream.pipe(concat(function(data) { + noEntries = true; + t.same(data.toString(), 'høllø\n'); + callback(); + })); + }); + + extract.on('finish', function() { + t.ok(noEntries); + }); + + extract.end(fs.readFileSync(fixtures.UNICODE_TAR)); }); \ No newline at end of file diff --git a/test/fixtures/index.js b/test/fixtures/index.js index 7e29b74..4eeeb32 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -4,3 +4,5 @@ exports.ONE_FILE_TAR = path.join(__dirname, 'one-file.tar'); exports.MULTI_FILE_TAR = path.join(__dirname, 'multi-file.tar'); exports.TYPES_TAR = path.join(__dirname, 'types.tar'); exports.LONG_NAME_TAR = path.join(__dirname, 'long-name.tar'); +exports.UNICODE_BSD_TAR = path.join(__dirname, 'unicode-bsd.tar'); +exports.UNICODE_TAR = path.join(__dirname, 'unicode.tar'); diff --git a/test/fixtures/long-name.tar b/test/fixtures/long-name.tar index ae8c658d2b44d688f6d27cbff53e73b31079842a..3ba3b6f582d844d170f5d5fb00a54644872d808a 100644 GIT binary patch delta 49 zcmZn=Xb_mtDq&=xU}$7yYHDa=YGP!nU|?cwZepOoU@&?^zic E03PECxc~qF delta 48 zcmZn=Xb_mtDq(1@U}$7yYHDa=YGP!nU|?cwZepguU@& diff --git a/test/fixtures/unicode-bsd.tar b/test/fixtures/unicode-bsd.tar new file mode 100644 index 0000000000000000000000000000000000000000..2f74b5f4524915b0cd7c888409ba0a0e32fcdded GIT binary patch literal 10240 zcmeIxy-ve06b0bSc?v&4x!1qR;EAP33`k6j7Il@-G@xQo9<6&{4AW96LRF`B2plht zk1Xr@bM8YJ<}obd=BC+gyKc9gr6CoU9Ykcc7Db+&HT#+5VVxr)c1p06#;~=dtspkm zs6q^vE#vfQAMYt_a%t