From f1d47328e9e6f8bb2ea3b9feffecedf2bee7ea3c Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Fri, 30 Nov 2012 13:40:21 +0100 Subject: [PATCH] support testing of all relation types --- features/bicycle/restrictions.feature | 46 ++++----- features/car/restrictions.feature | 132 +++++++++++++------------- features/step_definitions/data.rb | 29 +++--- 3 files changed, 104 insertions(+), 103 deletions(-) diff --git a/features/bicycle/restrictions.feature b/features/bicycle/restrictions.feature index d009fec04..073233114 100644 --- a/features/bicycle/restrictions.feature +++ b/features/bicycle/restrictions.feature @@ -21,8 +21,8 @@ Feature: Bike - Turn restrictions | ej | -1 | And the relations - | from | to | via | restriction | - | sj | wj | j | no_left_turn | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | wj | j | no_left_turn | When I route I should get | from | to | route | @@ -45,8 +45,8 @@ Feature: Bike - Turn restrictions | ej | -1 | And the relations - | from | to | via | restriction | - | sj | ej | j | no_right_turn | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | ej | j | no_right_turn | When I route I should get | from | to | route | @@ -69,8 +69,8 @@ Feature: Bike - Turn restrictions | ej | -1 | And the relations - | from | to | via | restriction | - | sj | wj | j | no_u_turn | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | wj | j | no_u_turn | When I route I should get | from | to | route | @@ -93,8 +93,8 @@ Feature: Bike - Turn restrictions | ej | -1 | And the relations - | from | to | via | restriction | - | sj | wj | j | no_weird_zigzags | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | wj | j | no_weird_zigzags | When I route I should get | from | to | route | @@ -117,8 +117,8 @@ Feature: Bike - Turn restrictions | ej | -1 | And the relations - | from | to | via | restriction | - | sj | wj | j | only_left_turn | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | wj | j | only_left_turn | When I route I should get | from | to | route | @@ -141,8 +141,8 @@ Feature: Bike - Turn restrictions | ej | -1 | And the relations - | from | to | via | restriction | - | sj | ej | j | only_right_turn | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | ej | j | only_right_turn | When I route I should get | from | to | route | @@ -165,8 +165,8 @@ Feature: Bike - Turn restrictions | ej | -1 | And the relations - | from | to | via | restriction | - | sj | nj | j | only_straight_on | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | nj | j | only_straight_on | When I route I should get | from | to | route | @@ -189,8 +189,8 @@ Feature: Bike - Turn restrictions | ej | -1 | And the relations - | from | to | via | restriction | - | sj | nj | j | only_weird_zigzags | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | nj | j | only_weird_zigzags | When I route I should get | from | to | route | @@ -215,11 +215,11 @@ Feature: Bike - Turn restrictions | dj | -1 | And the relations - | from | to | via | restriction | except | - | sj | aj | j | no_left_turn | bicycle | - | sj | bj | j | no_left_turn | | - | sj | cj | j | no_right_turn | bicycle | - | sj | dj | j | no_right_turn | | + | type | way:from | way:to | node:via | restriction | except | + | restriction | sj | aj | j | no_left_turn | bicycle | + | restriction | sj | bj | j | no_left_turn | | + | restriction | sj | cj | j | no_right_turn | bicycle | + | restriction | sj | dj | j | no_right_turn | | When I route I should get | from | to | route | @@ -242,8 +242,8 @@ Feature: Bike - Turn restrictions | bj | -1 | And the relations - | from | to | via | restriction | except | - | sj | aj | j | only_straight_on | bicycle | + | type | way:from | way:to | node:via | restriction | except | + | restriction | sj | aj | j | only_straight_on | bicycle | When I route I should get | from | to | route | diff --git a/features/car/restrictions.feature b/features/car/restrictions.feature index a20182ce6..2bc00f4a9 100644 --- a/features/car/restrictions.feature +++ b/features/car/restrictions.feature @@ -14,15 +14,15 @@ Feature: Car - Turn restrictions | | s | | And the ways - | nodes | oneway | - | sj | yes | - | nj | -1 | - | wj | -1 | - | ej | -1 | + | nodes | oneway | + | sj | yes | + | nj | -1 | + | wj | -1 | + | ej | -1 | And the relations - | from | to | via | restriction | - | sj | wj | j | no_left_turn | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | wj | j | no_left_turn | When I route I should get | from | to | route | @@ -38,15 +38,15 @@ Feature: Car - Turn restrictions | | s | | And the ways - | nodes | oneway | - | sj | yes | - | nj | -1 | - | wj | -1 | - | ej | -1 | + | nodes | oneway | + | sj | yes | + | nj | -1 | + | wj | -1 | + | ej | -1 | And the relations - | from | to | via | restriction | - | sj | ej | j | no_right_turn | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | ej | j | no_right_turn | When I route I should get | from | to | route | @@ -62,15 +62,15 @@ Feature: Car - Turn restrictions | | s | | And the ways - | nodes | oneway | - | sj | yes | - | nj | -1 | - | wj | -1 | - | ej | -1 | + | nodes | oneway | + | sj | yes | + | nj | -1 | + | wj | -1 | + | ej | -1 | And the relations - | from | to | via | restriction | - | sj | wj | j | no_u_turn | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | wj | j | no_u_turn | When I route I should get | from | to | route | @@ -86,15 +86,15 @@ Feature: Car - Turn restrictions | | s | | And the ways - | nodes | oneway | - | sj | yes | - | nj | -1 | - | wj | -1 | - | ej | -1 | + | nodes | oneway | + | sj | yes | + | nj | -1 | + | wj | -1 | + | ej | -1 | And the relations - | from | to | via | restriction | - | sj | wj | j | no_weird_zigzags | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | wj | j | no_weird_zigzags | When I route I should get | from | to | route | @@ -110,21 +110,21 @@ Feature: Car - Turn restrictions | | s | | And the ways - | nodes | oneway | - | sj | yes | - | nj | -1 | - | wj | -1 | - | ej | -1 | + | nodes | oneway | + | sj | yes | + | nj | -1 | + | wj | -1 | + | ej | -1 | And the relations - | from | to | via | restriction | - | sj | wj | j | only_left_turn | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | wj | j | only_left_turn | When I route I should get | from | to | route | - | s | w | sj,wj | - | s | n | | - | s | e | | + | s | w | sj,wj | + | s | n | | + | s | e | | @only_turning Scenario: Car - Only right turn @@ -134,15 +134,15 @@ Feature: Car - Turn restrictions | | s | | And the ways - | nodes | oneway | - | sj | yes | - | nj | -1 | - | wj | -1 | - | ej | -1 | + | nodes | oneway | + | sj | yes | + | nj | -1 | + | wj | -1 | + | ej | -1 | And the relations - | from | to | via | restriction | - | sj | ej | j | only_right_turn | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | ej | j | only_right_turn | When I route I should get | from | to | route | @@ -158,15 +158,15 @@ Feature: Car - Turn restrictions | | s | | And the ways - | nodes | oneway | - | sj | yes | - | nj | -1 | - | wj | -1 | - | ej | -1 | + | nodes | oneway | + | sj | yes | + | nj | -1 | + | wj | -1 | + | ej | -1 | And the relations - | from | to | via | restriction | - | sj | nj | j | only_straight_on | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | nj | j | only_straight_on | When I route I should get | from | to | route | @@ -182,15 +182,15 @@ Feature: Car - Turn restrictions | | s | | And the ways - | nodes | oneway | - | sj | yes | - | nj | -1 | - | wj | -1 | - | ej | -1 | + | nodes | oneway | + | sj | yes | + | nj | -1 | + | wj | -1 | + | ej | -1 | And the relations - | from | to | via | restriction | - | sj | nj | j | only_weird_zigzags | + | type | way:from | way:to | node:via | restriction | + | restriction | sj | nj | j | only_weird_zigzags | When I route I should get | from | to | route | @@ -215,11 +215,11 @@ Feature: Car - Turn restrictions | dj | -1 | And the relations - | from | to | via | restriction | except | - | sj | aj | j | no_left_turn | motorcar | - | sj | bj | j | no_left_turn | | - | sj | cj | j | no_right_turn | motorcar | - | sj | dj | j | no_right_turn | | + | type | way:from | way:to | node:via | restriction | except | + | restriction | sj | aj | j | no_left_turn | motorcar | + | restriction | sj | bj | j | no_left_turn | | + | restriction | sj | cj | j | no_right_turn | motorcar | + | restriction | sj | dj | j | no_right_turn | | When I route I should get | from | to | route | @@ -242,8 +242,8 @@ Feature: Car - Turn restrictions | bj | -1 | And the relations - | from | to | via | restriction | except | - | sj | aj | j | only_straight_on | motorcar | + | type | way:from | way:to | node:via | restriction | except | + | restriction | sj | aj | j | only_straight_on | motorcar | When I route I should get | from | to | route | diff --git a/features/step_definitions/data.rb b/features/step_definitions/data.rb index 5ea64166d..f4e5de00e 100644 --- a/features/step_definitions/data.rb +++ b/features/step_definitions/data.rb @@ -88,20 +88,21 @@ end Given /^the relations$/ do |table| table.hashes.each do |row| relation = OSM::Relation.new make_osm_id, OSM_USER, OSM_TIMESTAMP - relation << { :type => :restriction, :restriction => row['restriction'] } - from_way = find_way_by_name(row['from']) - raise "*** unknown way '#{row['from']}'" unless from_way - to_way = find_way_by_name(row['to']) - raise "*** unknown way '#{row['to']}'" unless to_way - relation << OSM::Member.new( 'way', from_way.id, 'from' ) - relation << OSM::Member.new( 'way', to_way.id, 'to' ) - c = row['via'] - unless c.empty? - raise "*** node invalid name '#{c}', must be single characters" unless c.size == 1 - raise "*** via node cannot use numbered nodes, '#{c}'" unless c.match /[a-z]/ - via_node = find_node_by_name(c) - raise "*** unknown node '#{row['via']}'" unless via_node - relation << OSM::Member.new( 'node', via_node.id, 'via' ) + row.each_pair do |key,value| + if key =~ /^node:(.*)/ + raise "***invalid relation node member '#{value}', must be single character" unless value.size == 1 + node = find_node_by_name(value) + raise "*** unknown relation node member '#{value}'" unless node + relation << OSM::Member.new( 'node', node.id, $1 ) + elsif key =~ /^way:(.*)/ + way = find_way_by_name(value) + raise "*** unknown relation way member '#{value}'" unless way + relation << OSM::Member.new( 'way', way.id, $1 ) + elsif key =~ /^(.*):(.*)/ + raise "*** unknown relation member type '#{$1}', must be either 'node' or 'way'" + else + relation << { key => value } + end end relation.uid = OSM_UID osm_db << relation