Skip to content

Commit 07352d8

Browse files
authored
Merge pull request #83 from pelias/tag-generation-tests
Improve tag generation
2 parents d0da681 + 2a1be89 commit 07352d8

File tree

5 files changed

+70
-12
lines changed

5 files changed

+70
-12
lines changed

.jshintrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"node": true,
33
"curly": true,
44
"eqeqeq": true,
5+
"esversion": 6,
56
"freeze": true,
67
"immed": true,
78
"indent": 2,
@@ -14,8 +15,8 @@
1415
"plusplus": false,
1516
"quotmark": "single",
1617
"undef": true,
17-
"unused": true,
18+
"unused": false,
1819
"maxparams": 4,
1920
"maxdepth": 4,
20-
"maxlen": 120
21+
"maxlen": 140
2122
}

index.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ var util = require('util'),
55
split = require('split'),
66
through = require('through2'),
77
child = require('child_process'),
8-
exec = path.join(__dirname, 'build', util.format( 'pbf2json.%s-%s', os.platform(), os.arch() ) );
8+
exec = path.join(__dirname, 'build', util.format( 'pbf2json.%s-%s', os.platform(), os.arch() ) ),
9+
generateParams = require('./lib/generateParams');
910

1011
// custom log levels can be detected for lines with the format:
1112
// [level] message
@@ -29,14 +30,9 @@ function errorHandler( name, level ){
2930

3031
function createReadStream( config ){
3132

32-
var flags = [];
33-
flags.push( util.format( '-tags=%s', config.tags ) );
34-
if( config.hasOwnProperty( 'leveldb' ) ){
35-
flags.push( util.format( '-leveldb=%s', config.leveldb ) );
36-
}
37-
flags.push( config.file );
33+
const params = generateParams(config);
3834

39-
var proc = child.spawn( exec, flags );
35+
var proc = child.spawn( exec, params );
4036

4137
// propagate signals from parent to child
4238
process.on('SIGINT', function(){ proc.kill(); });

lib/generateParams.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function generateParams(config) {
2+
const flags = [];
3+
4+
if (config.tags) {
5+
const tags = config.tags.join(',');
6+
flags.push( `-tags=${tags}` );
7+
}
8+
if( config.hasOwnProperty( 'leveldb' ) ){
9+
flags.push( `-leveldb=${config.leveldb}` );
10+
}
11+
12+
flags.push( config.file );
13+
14+
return flags;
15+
}
16+
17+
module.exports = generateParams;

test/lib/generateParams.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const generateParams = require('../../lib/generateParams');
2+
3+
module.exports.tests = {};
4+
5+
module.exports.tests.params = function(test) {
6+
test('PBF file', function(t) {
7+
const config = {
8+
file: '/some/path/to/osm.pbf'
9+
};
10+
11+
const params = generateParams(config);
12+
13+
t.equal(params[params.length - 1], '/some/path/to/osm.pbf', 'final parameter is path to PBF file');
14+
t.end();
15+
});
16+
test('PBF file', function(t) {
17+
const config = {
18+
tags: [
19+
'tag:one',
20+
'tag:two',
21+
'combination~tags'
22+
]
23+
};
24+
25+
const params = generateParams(config);
26+
27+
const expected = '-tags=tag:one,tag:two,combination~tags';
28+
29+
t.equal(params[0], expected, 'tag array is serialized into parameter');
30+
t.end();
31+
});
32+
};
33+
34+
module.exports.all = function (tape, common) {
35+
36+
function test(name, testFunction) {
37+
return tape('generateParams: ' + name, testFunction);
38+
}
39+
40+
for( var testCase in module.exports.tests ){
41+
module.exports.tests[testCase](test, common);
42+
}
43+
};

test/run.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ var tape = require('tape');
33
var common = {};
44

55
var tests = [
6-
require('./index.js')
6+
require('./index.js'),
7+
require('./lib/generateParams.js')
78
];
89

910
tests.map(function(t) {
1011
t.all(tape, common);
11-
});
12+
});

0 commit comments

Comments
 (0)