1@extract
2Feature: osrm-extract lua ways:get_nodes()
3
4    Scenario: osrm-extract - Passing base file
5        Given the profile file
6        """
7        functions = require('testbot')
8
9        functions.process_way = function(profile, way, result)
10          for _, node in ipairs(way:get_nodes()) do
11            print('node id ' .. node:id())
12          end
13          result.forward_mode = mode.driving
14          result.forward_speed = 1
15        end
16
17        return functions
18        """
19        And the node map
20            """
21            a b
22            """
23        And the ways
24            | nodes |
25            | ab    |
26        And the data has been saved to disk
27
28        When I run "osrm-extract --profile {profile_file} {osm_file}"
29        Then it should exit successfully
30        And stdout should contain "node id 1"
31        And stdout should contain "node id 2"
32
33
34    Scenario: osrm-extract location-dependent data without add-locations-to-ways preprocessing and node locations cache
35        Given the profile file
36        """
37        functions = require('testbot')
38
39        functions.process_way = function(profile, way, result, relations)
40           print(way:get_location_tag('driving_side'))
41        end
42
43        return functions
44        """
45        And the node map
46            """
47            a b
48            """
49        And the ways
50            | nodes |
51            | ab    |
52        And the data has been saved to disk
53
54        When I try to run "osrm-extract --profile {profile_file} {osm_file} --location-dependent-data test/data/regions/null-island.geojson --disable-location-cache"
55        Then it should exit with an error
56        And stderr should contain "invalid location"
57
58    Scenario: osrm-extract location-dependent data
59        Given the profile file
60        """
61        functions = require('testbot')
62
63        functions.process_way = function(profile, way, result, relations)
64           for _, key in ipairs({'answer', 'boolean', 'object', 'array'}) do
65             print (key .. ' ' .. tostring(way:get_location_tag(key)))
66           end
67           result.forward_mode = mode.driving
68           result.forward_speed = 1
69        end
70
71        return functions
72        """
73        And the node map
74            """
75            a b
76            """
77        And the ways with locations
78            | nodes |
79            | ab    |
80        And the data has been saved to disk
81
82        When I run "osrm-extract --profile {profile_file} {osm_file} --location-dependent-data test/data/regions/null-island.geojson  --disable-location-cache"
83        Then it should exit successfully
84        And stdout should contain "answer 42"
85        And stdout should contain "boolean true"
86        And stdout should contain "array nil"
87        And stdout should contain "object nil"
88
89
90    Scenario: osrm-extract location-dependent data with multi-polygons
91        Given the profile file
92        """
93        functions = require('testbot')
94
95        functions.process_way = function(profile, way, result, relations)
96           print('ISO3166-1 ' .. (way:get_location_tag('ISO3166-1') or 'none'))
97           print('answer ' .. (way:get_location_tag('answer') or 'none'))
98           result.forward_mode = mode.driving
99           result.forward_speed = 1
100        end
101
102        return functions
103        """
104        And the node locations
105            | node |        lat |         lon | id |
106            | a    | 22.4903670 | 113.9455227 |  1 |
107            | b    | 22.4901701 | 113.9455899 |  2 |
108            | c    | 22.4901852 | 113.9458608 |  3 |
109            | d    | 22.4904033 | 113.9456999 |  4 |
110            | e    |        1.1 |           1 |  5 |
111            | f    |        1.2 |           1 |  6 |
112        And the ways with locations
113            | nodes | #              |
114            | ab    | Hong Kong      |
115            | cd    | China Mainland |
116            | ef    | Null Island    |
117        And the data has been saved to disk
118
119        When I run "osrm-extract --profile {profile_file} {osm_file} --location-dependent-data test/data/regions/null-island.geojson --location-dependent-data test/data/regions/hong-kong.geojson --disable-location-cache"
120        Then it should exit successfully
121        And stdout should not contain "1 GeoJSON polygon"
122        And stdout should contain "2 GeoJSON polygons"
123        And stdout should contain "ISO3166-1 HK"
124        And stdout should contain "ISO3166-1 none"
125        And stdout should contain "answer 42"
126
127    Scenario: osrm-extract location-dependent data via locations cache
128        Given the profile file
129        """
130        functions = require('testbot')
131
132        functions.process_node = function(profile, node, result, relations)
133           print ('node ' .. tostring(node:get_location_tag('answer')))
134        end
135
136        functions.process_way = function(profile, way, result, relations)
137           print ('way ' .. tostring(way:get_location_tag('answer')))
138           result.forward_mode = mode.driving
139           result.forward_speed = 1
140        end
141
142        return functions
143        """
144        And the node map
145            """
146            a b
147            """
148        And the ways
149            | nodes |
150            | ab    |
151        And the data has been saved to disk
152
153        When I run "osrm-extract --profile {profile_file} {osm_file} --location-dependent-data test/data/regions/null-island.geojson"
154        Then it should exit successfully
155        And stdout should contain "node 42"
156        And stdout should contain "way 42"
157