mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
4.2 KiB
119 lines
4.2 KiB
9 years ago
|
var parser = require('../../../helper/text_parser');
|
||
9 years ago
|
|
||
|
var type_mapping = require('../../../helper/type_mapping');
|
||
9 years ago
|
var layers_map = type_mapping.layer_with_aliases_to_type;
|
||
9 years ago
|
|
||
|
module.exports.tests = {};
|
||
|
|
||
|
module.exports.tests.interface = function(test, common) {
|
||
|
test('interface', function(t) {
|
||
9 years ago
|
t.equal(typeof parser.get_parsed_address, 'function', 'valid function');
|
||
|
t.equal(typeof parser.get_layers, 'function', 'valid function');
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports.tests.split_on_comma = function(test, common) {
|
||
9 years ago
|
var queries = [
|
||
|
{ name: 'soho', admin_parts: 'new york' },
|
||
|
{ name: 'chelsea', admin_parts: 'london' },
|
||
|
{ name: '123 main', admin_parts: 'new york' }
|
||
|
];
|
||
9 years ago
|
|
||
9 years ago
|
queries.forEach(function (query) {
|
||
9 years ago
|
test('naive parsing ' + query, function(t) {
|
||
9 years ago
|
var address = parser.get_parsed_address(query.name + ', ' + query.admin_parts);
|
||
9 years ago
|
|
||
|
t.equal(typeof address, 'object', 'valid object');
|
||
9 years ago
|
t.equal(address.name, query.name, 'name set correctly to ' + address.name);
|
||
|
t.equal(address.admin_parts, query.admin_parts, 'admin_parts set correctly to ' + address.admin_parts);
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
9 years ago
|
});
|
||
9 years ago
|
};
|
||
|
|
||
|
module.exports.tests.parse_three_chars_or_less = function(test, common) {
|
||
|
var chars_queries = ['a', 'bb', 'ccc'];
|
||
|
var num_queries = ['1', '12', '123'];
|
||
|
var alphanum_q = ['a1', '1a2', '12c'];
|
||
|
|
||
9 years ago
|
var queries = chars_queries.concat(num_queries).concat(alphanum_q);
|
||
|
queries.forEach(function(query) {
|
||
9 years ago
|
test('query length < 3 (' + query + ')', function(t) {
|
||
9 years ago
|
var address = parser.get_parsed_address(query);
|
||
9 years ago
|
var target_layer = layers_map.coarse;
|
||
9 years ago
|
var layers = parser.get_layers(query);
|
||
9 years ago
|
|
||
|
t.equal(typeof address, 'object', 'valid object');
|
||
9 years ago
|
t.deepEqual(layers, target_layer, 'admin_parts set correctly to ' + target_layer.join(', '));
|
||
9 years ago
|
t.end();
|
||
|
});
|
||
9 years ago
|
});
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
module.exports.tests.parse_one_token = function(test, common) {
|
||
|
test('query with one token', function (t) {
|
||
|
var address = parser.get_parsed_address('yugolsavia');
|
||
|
t.equal(address, null, 'nothing address specific detected');
|
||
|
t.end();
|
||
|
});
|
||
|
test('query with two tokens, no numbers', function (t) {
|
||
|
var address = parser.get_parsed_address('small town');
|
||
|
t.equal(address, null, 'nothing address specific detected');
|
||
|
t.end();
|
||
|
});
|
||
|
test('query with two tokens, number first', function (t) {
|
||
|
var address = parser.get_parsed_address('123 main');
|
||
|
t.equal(address, null, 'nothing address specific detected');
|
||
|
t.end();
|
||
|
});
|
||
|
test('query with two tokens, number second', function (t) {
|
||
|
var address = parser.get_parsed_address('main 123');
|
||
|
t.equal(address, null, 'nothing address specific detected');
|
||
|
t.end();
|
||
|
});
|
||
|
test('query with many tokens', function(t) {
|
||
|
var address = parser.get_parsed_address('main particle new york');
|
||
|
t.equal(address, null, 'nothing address specific detected');
|
||
|
t.end();
|
||
|
});
|
||
9 years ago
|
};
|
||
|
|
||
|
module.exports.tests.parse_address = function(test, common) {
|
||
9 years ago
|
test('valid address, house number', function(t) {
|
||
|
var query_string = '123 main st new york ny';
|
||
|
var address = parser.get_parsed_address(query_string);
|
||
|
|
||
|
t.equal(typeof address, 'object', 'valid object for the address');
|
||
|
t.equal(address.number, 123, 'parsed house number');
|
||
|
t.equal(address.street, 'main st', 'parsed street');
|
||
|
t.deepEqual(address.regions, ['new york'], 'parsed city');
|
||
|
t.equal(address.state , 'NY', 'parsed state');
|
||
|
t.end();
|
||
|
});
|
||
|
test('valid address, zipcode', function(t) {
|
||
|
var query_string = '123 main st new york ny 10010';
|
||
|
var address = parser.get_parsed_address(query_string);
|
||
|
|
||
|
t.equal(typeof address, 'object', 'valid object for the address');
|
||
|
t.equal(address.number, 123, 'parsed house number');
|
||
|
t.equal(address.street, 'main st', 'parsed street');
|
||
|
t.deepEqual(address.regions, ['new york'], 'parsed city');
|
||
|
t.equal(address.state , 'NY', 'parsed state');
|
||
|
t.equal(address.postalcode, 10010, 'parsed zip');
|
||
|
t.end();
|
||
|
});
|
||
9 years ago
|
};
|
||
|
|
||
9 years ago
|
|
||
9 years ago
|
module.exports.all = function (tape, common) {
|
||
|
|
||
|
function test(name, testFunction) {
|
||
|
return tape('QUERY PARSING: ' + name, testFunction);
|
||
|
}
|
||
|
|
||
|
for( var testCase in module.exports.tests ){
|
||
|
module.exports.tests[testCase](test, common);
|
||
|
}
|
||
9 years ago
|
};
|