Skip to content

Commit

Permalink
Unit tests for strip op
Browse files Browse the repository at this point in the history
  • Loading branch information
andylolz committed Nov 28, 2013
1 parent 7f386bf commit af7d8cd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/unit.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ require('./unit/cut.js');
// require('./unit/html.js');
// require('./unit/none.js');
// require('./unit/replace.js');
// require('./unit/strip.js');
require('./unit/strip.js');
// require('./unit/tail.js');
64 changes: 64 additions & 0 deletions test/unit/strip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
var assert = require('assert');
var csv = require('csv');
var stream = require('stream');
var _ = require('underscore');

var ops = require('../../lib/operators.js');

var headerStr = 'this,is,the,header,row,,,,,,,,,,,,,,,,';
var headerRow = headerStr.split(',');
var headerData = JSON.stringify({row: headerRow, index: 0});

var out = new stream();

describe('strip', function(){
describe('an empty row', function(){
var dataStr = ',,,,,,,,,,,,,,,,,,,,';
var row = dataStr.split(',');
var data = JSON.stringify({row: row, index: 1});

it('should strip the row', function(done){
rowCount = 0;
out.write = function(d) {
var stripDataStr = JSON.parse(d).row.join(',');
assert.equal(stripDataStr, headerStr);
rowCount++;
};

out.end = function(d) {
assert.equal(rowCount, 1);
done();
};

var strip = new ops['strip']();
strip.write(headerData);
strip.write(data);
strip.end();
strip.pipe(out);
});
});

describe('a partially-filled row', function(){
var dataStr = '2006/2007 - 12,81.2,163.0,244.2,77.4,143.4,220.5,5.4%,7.6%,6.8%,4.6%,4.4%,4.5%,,,,,,,,';
var row = dataStr.split(',');
var data = JSON.stringify({row: row, index: 1});

it('should *not* strip the row', function(done){
rowCount = 0;
out.write = function(d) {
rowCount++;
};

out.end = function(d) {
assert.equal(rowCount, 2);
done();
};

var strip = new ops['strip']();
strip.write(headerData);
strip.write(data);
strip.end();
strip.pipe(out);
});
});
});

1 comment on commit af7d8cd

@andylolz
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refs #95.

Please sign in to comment.