@ -6,7 +6,8 @@ module.exports.tests = {};
module . exports . tests . interface = function ( test , common ) {
module . exports . tests . interface = function ( test , common ) {
test ( 'interface' , function ( t ) {
test ( 'interface' , function ( t ) {
t . equal ( typeof parser , 'function' , 'valid function' ) ;
t . equal ( typeof parser . get _parsed _address , 'function' , 'valid function' ) ;
t . equal ( typeof parser . get _layers , 'function' , 'valid function' ) ;
t . end ( ) ;
t . end ( ) ;
} ) ;
} ) ;
} ;
} ;
@ -17,7 +18,7 @@ module.exports.tests.split_on_comma = function(test, common) {
var testParse = function ( query ) {
var testParse = function ( query ) {
test ( 'naive parsing ' + query , function ( t ) {
test ( 'naive parsing ' + query , function ( t ) {
var address = parser ( query ) ;
var address = parser . get _parsed _address ( query ) ;
var delimIndex = query . indexOf ( delim ) ;
var delimIndex = query . indexOf ( delim ) ;
var name = query . substring ( 0 , delimIndex ) ;
var name = query . substring ( 0 , delimIndex ) ;
var admin _parts = query . substring ( delimIndex + 1 ) . trim ( ) ;
var admin _parts = query . substring ( delimIndex + 1 ) . trim ( ) ;
@ -41,11 +42,12 @@ module.exports.tests.parse_three_chars_or_less = function(test, common) {
var testParse = function ( query ) {
var testParse = function ( query ) {
test ( 'query length < 3 (' + query + ')' , function ( t ) {
test ( 'query length < 3 (' + query + ')' , function ( t ) {
var address = parser ( query ) ;
var address = parser . get _parsed _address ( query ) ;
var target _layer = get _layers ( [ 'admin' ] ) ;
var target _layer = get _layers ( [ 'admin' ] ) ;
var layers = parser . get _layers ( query ) ;
t . equal ( typeof address , 'object' , 'valid object' ) ;
t . equal ( typeof address , 'object' , 'valid object' ) ;
t . deepEqual ( address . target _ layer, target _layer , 'admin_parts set correctly to ' + target _layer . join ( ', ' ) ) ;
t . deepEqual ( layers , target _layer , 'admin_parts set correctly to ' + target _layer . join ( ', ' ) ) ;
t . end ( ) ;
t . end ( ) ;
} ) ;
} ) ;
} ;
} ;
@ -63,15 +65,16 @@ module.exports.tests.parse_one_or_more_tokens = function(test, common) {
var testParse = function ( query , parse _address ) {
var testParse = function ( query , parse _address ) {
test ( 'query with one or more tokens (' + query + ')' , function ( t ) {
test ( 'query with one or more tokens (' + query + ')' , function ( t ) {
var address = parser ( query ) ;
var address = parser . get _parsed _address ( query ) ;
var target _layer = get _layers ( [ 'admin' , 'poi' ] ) ;
var target _layer = get _layers ( [ 'admin' , 'poi' ] ) ;
var layers = parser . get _layers ( query ) ;
t . equal ( typeof address , 'object' , 'valid object' ) ;
t . equal ( typeof address , 'object' , 'valid object' ) ;
if ( parse _address ) {
if ( parse _address ) {
t . deepEqual ( address . regions . join ( '' ) , query , 'since query contained a number, it went through address parsing' ) ;
t . deepEqual ( address . regions . join ( '' ) , query , 'since query contained a number, it went through address parsing' ) ;
} else {
} else {
t . deepEqual ( address . target _ layer, target _layer , 'admin_parts set correctly to ' + target _layer . join ( ', ' ) ) ;
t . deepEqual ( layers , target _layer , 'admin_parts set correctly to ' + target _layer . join ( ', ' ) ) ;
}
}
t . end ( ) ;
t . end ( ) ;
@ -114,7 +117,7 @@ module.exports.tests.parse_address = function(test, common) {
// remove leading whitespace
// remove leading whitespace
query _string = query _string . substring ( 1 ) ;
query _string = query _string . substring ( 1 ) ;
var address = parser ( query _string ) ;
var address = parser . get _parsed _address ( query _string ) ;
var non _address _layer = get _layers ( [ 'admin' , 'poi' ] ) ;
var non _address _layer = get _layers ( [ 'admin' , 'poi' ] ) ;
t . equal ( typeof address , 'object' , 'valid object for the address (' + query _string + ')' ) ;
t . equal ( typeof address , 'object' , 'valid object for the address (' + query _string + ')' ) ;