unicode tests and ok test coverage. closes #1

This commit is contained in:
Mathias Buus 2013-12-21 02:32:52 +01:00
parent 7377142d9d
commit 52100cdb45
6 changed files with 99 additions and 3 deletions

View file

@ -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));
});

View file

@ -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');

Binary file not shown.

BIN
test/fixtures/unicode-bsd.tar vendored Normal file

Binary file not shown.

BIN
test/fixtures/unicode.tar vendored Normal file

Binary file not shown.

View file

@ -110,7 +110,7 @@ test('long-name', function(t) {
gname:'staff',
uid:501,
gid:20
}, 'hello long name');
}, 'hello long name\n');
pack.finalize();
@ -119,3 +119,26 @@ test('long-name', function(t) {
t.deepEqual(data, fs.readFileSync(fixtures.LONG_NAME_TAR));
}));
});
test('unicode', function(t) {
t.plan(2);
var pack = tar.pack();
pack.entry({
name:'høstål.txt',
mtime:new Date(1387580181000),
type:'file',
mode:0644,
uname:'maf',
gname:'staff',
uid:501,
gid:20
}, 'høllø\n');
pack.finalize();
pack.pipe(concat(function(data) {
t.equal(data.length & 511, 0);
t.deepEqual(data, fs.readFileSync(fixtures.UNICODE_TAR));
}));
});