removing trailing whitespace in cuke/ruby files

This commit is contained in:
Emil Tin 2013-08-29 19:32:11 +02:00
parent b5bfdb56dc
commit 407d73a735
11 changed files with 54 additions and 53 deletions

View File

@ -7,6 +7,7 @@ Feature: Bike - Accessability of different way types
Scenario: Bike - Routability of way types Scenario: Bike - Routability of way types
Bikes are allowed on footways etc because you can pull your bike at a lower speed. Bikes are allowed on footways etc because you can pull your bike at a lower speed.
Pier is not allowed, since it's tagged using man_made=pier. Pier is not allowed, since it's tagged using man_made=pier.
Then routability should be Then routability should be
| highway | bothw | | highway | bothw |
| (nil) | | | (nil) | |

View File

@ -35,9 +35,9 @@ Given /^the node locations$/ do |table|
name = row['node'] name = row['node']
raise "*** duplicate node '#{name}'" if find_node_by_name name raise "*** duplicate node '#{name}'" if find_node_by_name name
if name.match /[a-z]/ if name.match /[a-z]/
add_osm_node name, row['lon'].to_f, row['lat'].to_f add_osm_node name, row['lon'].to_f, row['lat'].to_f
else else
add_location name, row['lon'].to_f, row['lat'].to_f add_location name, row['lon'].to_f, row['lat'].to_f
end end
end end
end end
@ -55,7 +55,7 @@ Given /^the ways$/ do |table|
table.hashes.each do |row| table.hashes.each do |row|
way = OSM::Way.new make_osm_id, OSM_USER, OSM_TIMESTAMP way = OSM::Way.new make_osm_id, OSM_USER, OSM_TIMESTAMP
way.uid = OSM_UID way.uid = OSM_UID
nodes = row.delete 'nodes' nodes = row.delete 'nodes'
raise "*** duplicate way '#{nodes}'" if name_way_hash[nodes] raise "*** duplicate way '#{nodes}'" if name_way_hash[nodes]
nodes.each_char do |c| nodes.each_char do |c|
@ -64,14 +64,14 @@ Given /^the ways$/ do |table|
raise "*** unknown node '#{c}'" unless node raise "*** unknown node '#{c}'" unless node
way << node way << node
end end
defaults = { 'highway' => 'primary' } defaults = { 'highway' => 'primary' }
tags = defaults.merge(row) tags = defaults.merge(row)
if row['highway'] == '(nil)' if row['highway'] == '(nil)'
tags.delete 'highway' tags.delete 'highway'
end end
if row['name'] == nil if row['name'] == nil
tags['name'] = nodes tags['name'] = nodes
elsif (row['name'] == '""') || (row['name'] == "''") elsif (row['name'] == '""') || (row['name'] == "''")
@ -81,7 +81,7 @@ Given /^the ways$/ do |table|
else else
tags['name'] = row['name'] tags['name'] = row['name']
end end
way << tags way << tags
osm_db << way osm_db << way
name_way_hash[nodes] = way name_way_hash[nodes] = way

View File

@ -16,9 +16,9 @@ When /^I request nearest I should get$/ do |table|
coord = json['mapped_coordinate'] coord = json['mapped_coordinate']
end end
end end
got = {'in' => row['in'], 'out' => coord } got = {'in' => row['in'], 'out' => coord }
ok = true ok = true
row.keys.each do |key| row.keys.each do |key|
if key=='out' if key=='out'
@ -30,12 +30,12 @@ When /^I request nearest I should get$/ do |table|
end end
end end
end end
unless ok unless ok
failed = { :attempt => 'nearest', :query => @query, :response => response } failed = { :attempt => 'nearest', :query => @query, :response => response }
log_fail row,got,[failed] log_fail row,got,[failed]
end end
actual << got actual << got
end end
end end

View File

@ -8,11 +8,11 @@ When /^I route I should get$/ do |table|
node = find_node_by_name(row['from']) node = find_node_by_name(row['from'])
raise "*** unknown from-node '#{row['from']}" unless node raise "*** unknown from-node '#{row['from']}" unless node
waypoints << node waypoints << node
node = find_node_by_name(row['to']) node = find_node_by_name(row['to'])
raise "*** unknown to-node '#{row['to']}" unless node raise "*** unknown to-node '#{row['to']}" unless node
waypoints << node waypoints << node
got = {'from' => row['from'], 'to' => row['to'] } got = {'from' => row['from'], 'to' => row['to'] }
elsif row['waypoints'] elsif row['waypoints']
row['waypoints'].split(',').each do |n| row['waypoints'].split(',').each do |n|
@ -24,7 +24,7 @@ When /^I route I should get$/ do |table|
else else
raise "*** no waypoints" raise "*** no waypoints"
end end
params = {} params = {}
row.each_pair do |k,v| row.each_pair do |k,v|
if k =~ /param:(.*)/ if k =~ /param:(.*)/
@ -36,7 +36,7 @@ When /^I route I should get$/ do |table|
got[k]=v got[k]=v
end end
end end
response = request_route(waypoints, params) response = request_route(waypoints, params)
if response.code == "200" && response.body.empty? == false if response.code == "200" && response.body.empty? == false
json = JSON.parse response.body json = JSON.parse response.body
@ -48,7 +48,7 @@ When /^I route I should get$/ do |table|
modes = mode_list json['route_instructions'] modes = mode_list json['route_instructions']
end end
end end
if table.headers.include? 'start' if table.headers.include? 'start'
got['start'] = instructions ? json['route_summary']['start_point'] : nil got['start'] = instructions ? json['route_summary']['start_point'] : nil
end end
@ -83,7 +83,7 @@ When /^I route I should get$/ do |table|
got['#'] = row['#'] # copy value so it always match got['#'] = row['#'] # copy value so it always match
end end
end end
ok = true ok = true
row.keys.each do |key| row.keys.each do |key|
if FuzzyMatch.match got[key], row[key] if FuzzyMatch.match got[key], row[key]
@ -92,12 +92,12 @@ When /^I route I should get$/ do |table|
ok = false ok = false
end end
end end
unless ok unless ok
failed = { :attempt => 'route', :query => @query, :response => response } failed = { :attempt => 'route', :query => @query, :response => response }
log_fail row,got,[failed] log_fail row,got,[failed]
end end
actual << got actual << got
end end
end end

View File

@ -23,7 +23,7 @@ class Cucumber::Ast::Table
require_diff_lcs require_diff_lcs
cell_matrix.extend(Diff::LCS) cell_matrix.extend(Diff::LCS)
changes = cell_matrix.diff(other_table_cell_matrix).flatten changes = cell_matrix.diff(other_table_cell_matrix).flatten
inserted = 0 inserted = 0
missing = 0 missing = 0
@ -43,7 +43,7 @@ class Cucumber::Ast::Table
#change index so we interleave instead #change index so we interleave instead
insert_row_pos = change.position + inserted + 1 insert_row_pos = change.position + inserted + 1
#insert_row_pos = change.position + missing #original #insert_row_pos = change.position + missing #original
inserted_row = change.element inserted_row = change.element
inserted_row.each{|cell| cell.status = :comment} inserted_row.each{|cell| cell.status = :comment}
cell_matrix.insert(insert_row_pos, inserted_row) cell_matrix.insert(insert_row_pos, inserted_row)
@ -66,7 +66,7 @@ class Cucumber::Ast::Table
end end
clear_cache! clear_cache!
should_raise = should_raise =
missing_row_pos && options[:missing_row] || missing_row_pos && options[:missing_row] ||
insert_row_pos && options[:surplus_row] || insert_row_pos && options[:surplus_row] ||
missing_col && options[:missing_col] || missing_col && options[:missing_col] ||

View File

@ -20,7 +20,7 @@ ORIGIN = [1,1]
class Location class Location
attr_accessor :lon,:lat attr_accessor :lon,:lat
def initialize lon,lat def initialize lon,lat
@lat = lat @lat = lat
@lon = lon @lon = lon
@ -44,16 +44,16 @@ def build_ways_from_table table
#NOTE: #NOTE:
#currently osrm crashes when processing an isolated oneway with just 2 nodes, so we use 4 edges #currently osrm crashes when processing an isolated oneway with just 2 nodes, so we use 4 edges
#this is relatated to the fact that a oneway dead-end street doesn't make a lot of sense #this is relatated to the fact that a oneway dead-end street doesn't make a lot of sense
#if we stack ways on different x coordinates, routability tests get messed up, because osrm might pick a neighboring way if the one test can't be used. #if we stack ways on different x coordinates, routability tests get messed up, because osrm might pick a neighboring way if the one test can't be used.
#instead we place all lines as a string on the same y coordinate. this prevents using neightboring ways. #instead we place all lines as a string on the same y coordinate. this prevents using neightboring ways.
#a few nodes... #a few nodes...
node1 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(0+WAY_SPACING*ri)*@zoom, ORIGIN[1] node1 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(0+WAY_SPACING*ri)*@zoom, ORIGIN[1]
node2 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(1+WAY_SPACING*ri)*@zoom, ORIGIN[1] node2 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(1+WAY_SPACING*ri)*@zoom, ORIGIN[1]
node3 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(2+WAY_SPACING*ri)*@zoom, ORIGIN[1] node3 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(2+WAY_SPACING*ri)*@zoom, ORIGIN[1]
node4 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(3+WAY_SPACING*ri)*@zoom, ORIGIN[1] node4 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(3+WAY_SPACING*ri)*@zoom, ORIGIN[1]
node5 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(4+WAY_SPACING*ri)*@zoom, ORIGIN[1] node5 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(4+WAY_SPACING*ri)*@zoom, ORIGIN[1]
node1.uid = OSM_UID node1.uid = OSM_UID
node2.uid = OSM_UID node2.uid = OSM_UID
node3.uid = OSM_UID node3.uid = OSM_UID
@ -70,7 +70,7 @@ def build_ways_from_table table
osm_db << node3 osm_db << node3
osm_db << node4 osm_db << node4
osm_db << node5 osm_db << node5
#...with a way between them #...with a way between them
way = OSM::Way.new make_osm_id, OSM_USER, OSM_TIMESTAMP way = OSM::Way.new make_osm_id, OSM_USER, OSM_TIMESTAMP
way.uid = OSM_UID way.uid = OSM_UID
@ -79,22 +79,22 @@ def build_ways_from_table table
way << node3 way << node3
way << node4 way << node4
way << node5 way << node5
tags = row.dup tags = row.dup
# remove tags that describe expected test result # remove tags that describe expected test result
tags.reject! do |k,v| tags.reject! do |k,v|
k =~ /^forw\b/ || k =~ /^forw\b/ ||
k =~ /^backw\b/ || k =~ /^backw\b/ ||
k =~ /^bothw\b/ k =~ /^bothw\b/
end end
##remove empty tags ##remove empty tags
tags.reject! { |k,v| v=='' } tags.reject! { |k,v| v=='' }
# sort tag keys in the form of 'node/....' # sort tag keys in the form of 'node/....'
way_tags = { 'highway' => 'primary' } way_tags = { 'highway' => 'primary' }
node_tags = {} node_tags = {}
tags.each_pair do |k,v| tags.each_pair do |k,v|
if k =~ /node\/(.*)/ if k =~ /node\/(.*)/
@ -111,11 +111,11 @@ def build_ways_from_table table
end end
end end
end end
way_tags['name'] = "w#{ri}" way_tags['name'] = "w#{ri}"
way << way_tags way << way_tags
node3 << node_tags node3 << node_tags
osm_db << way osm_db << way
end end
end end
@ -207,7 +207,7 @@ def osm_str
@osm_str @osm_str
end end
def write_osm def write_osm
#write .oms file if needed #write .oms file if needed
Dir.mkdir DATA_FOLDER unless File.exist? DATA_FOLDER Dir.mkdir DATA_FOLDER unless File.exist? DATA_FOLDER
@osm_file = "#{DATA_FOLDER}/#{sanitized_scenario_title}_#{fingerprint}" @osm_file = "#{DATA_FOLDER}/#{sanitized_scenario_title}_#{fingerprint}"
@ -262,7 +262,7 @@ def reprocess
unless system "#{BIN_PATH}/osrm-prepare #{@osm_file}.osrm #{@osm_file}.osrm.restrictions 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE} #{PROFILES_PATH}/#{@profile}.lua" unless system "#{BIN_PATH}/osrm-prepare #{@osm_file}.osrm #{@osm_file}.osrm.restrictions 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE} #{PROFILES_PATH}/#{@profile}.lua"
log "*** Exited with code #{$?.exitstatus}.", :preprocess log "*** Exited with code #{$?.exitstatus}.", :preprocess
raise PrepareError.new $?.exitstatus, "osrm-prepare exited with code #{$?.exitstatus}." raise PrepareError.new $?.exitstatus, "osrm-prepare exited with code #{$?.exitstatus}."
end end
log '', :preprocess log '', :preprocess
end end
log_preprocess_done log_preprocess_done

View File

@ -10,13 +10,13 @@ class OSRMError < StandardError
@log = log @log = log
@extract = log_tail @log, @lines @extract = log_tail @log, @lines
end end
def to_s def to_s
"*** #{@msg}\nLast #{@lines} lines from #{@log}:\n#{@extract}\n" "*** #{@msg}\nLast #{@lines} lines from #{@log}:\n#{@extract}\n"
end end
private private
def log_tail path, n def log_tail path, n
File.open(path) do |f| File.open(path) do |f|
return f.tail(n).map { |line| " > #{line}" }.join "\n" return f.tail(n).map { |line| " > #{line}" }.join "\n"

View File

@ -22,13 +22,13 @@ class FuzzyMatch
return got =~ /#{$1}/ return got =~ /#{$1}/
else else
return false return false
end end
end end
def self.match_location got, want def self.match_location got, want
match( got[0], "#{want.lat} ~0.0025%" ) && match( got[0], "#{want.lat} ~0.0025%" ) &&
match( got[1], "#{want.lon} ~0.0025%" ) match( got[1], "#{want.lon} ~0.0025%" )
end end
end end

View File

@ -18,7 +18,7 @@ class OSRMLauncher
end end
private private
def launch def launch
Timeout.timeout(LAUNCH_TIMEOUT) do Timeout.timeout(LAUNCH_TIMEOUT) do
osrm_up osrm_up
@ -27,7 +27,7 @@ class OSRMLauncher
rescue Timeout::Error rescue Timeout::Error
raise RoutedError.new "Launching osrm-routed timed out." raise RoutedError.new "Launching osrm-routed timed out."
end end
def shutdown def shutdown
Timeout.timeout(SHUTDOWN_TIMEOUT) do Timeout.timeout(SHUTDOWN_TIMEOUT) do
osrm_down osrm_down
@ -36,8 +36,8 @@ class OSRMLauncher
kill kill
raise RoutedError.new "Shutting down osrm-routed timed out." raise RoutedError.new "Shutting down osrm-routed timed out."
end end
def osrm_up? def osrm_up?
if @pid if @pid
`ps -o state -p #{@pid}`.split[1].to_s =~ /^[DRST]/ `ps -o state -p #{@pid}`.split[1].to_s =~ /^[DRST]/

View File

@ -4,12 +4,12 @@ locations = nil
class OSMTestParserCallbacks < OSM::Callbacks class OSMTestParserCallbacks < OSM::Callbacks
locations = nil locations = nil
def self.locations def self.locations
if locations if locations
locations locations
else else
#parse the test file, so we can later reference nodes and ways by name in tests #parse the test file, so we can later reference nodes and ways by name in tests
locations = {} locations = {}
file = 'test/data/test.osm' file = 'test/data/test.osm'
callbacks = OSMTestParserCallbacks.new callbacks = OSMTestParserCallbacks.new

View File

@ -128,7 +128,7 @@ def turn_list instructions
r[0].to_s.gsub!(/^\d*/) do |match| r[0].to_s.gsub!(/^\d*/) do |match|
types[match.to_i].to_s types[match.to_i].to_s
end end
end.join(',') end.join(',')
end end
def mode_list instructions def mode_list instructions