]> git.openstreetmap.org Git - rails.git/commitdiff
Test that geocoder results are not in scientific form
authorTom Hughes <tom@compton.nu>
Tue, 9 Jul 2024 17:23:15 +0000 (18:23 +0100)
committerTom Hughes <tom@compton.nu>
Fri, 12 Jul 2024 13:43:54 +0000 (14:43 +0100)
test/controllers/geocoder_controller_test.rb

index 85baaafef48b508cf23534370525469391aa7b0e..4d5d345c3189327df6a9afc5e982d99c23a020f2 100644 (file)
@@ -261,6 +261,18 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest
     end
   end
 
+  #
+  # Test identification of lat/lon pairs with values close to zero
+  def test_identify_latlon_close_to_zero
+    [
+      "0.0000123 -0.0000456",
+      "+0.0000123 -0.0000456",
+      "N 0° 0' 0.4428\", W 0° 0' 1.6416\""
+    ].each do |code|
+      latlon_check code, 0.0000123, -0.0000456
+    end
+  end
+
   ##
   # Test identification of US zipcodes
   def test_identify_us_postcode
@@ -406,6 +418,8 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest
     assert_template :layout => "map"
     assert_equal %w[latlon osm_nominatim_reverse], assigns(:sources).pluck(:name)
     assert_nil @controller.params[:query]
+    assert_match(/^[+-]?\d+(?:\.\d*)?$/, @controller.params[:lat])
+    assert_match(/^[+-]?\d+(?:\.\d*)?$/, @controller.params[:lon])
     assert_in_delta lat, @controller.params[:lat].to_f
     assert_in_delta lon, @controller.params[:lon].to_f
 
@@ -415,6 +429,8 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest
     assert_template :layout => "xhr"
     assert_equal %w[latlon osm_nominatim_reverse], assigns(:sources).pluck(:name)
     assert_nil @controller.params[:query]
+    assert_match(/^[+-]?\d+(?:\.\d*)?$/, @controller.params[:lat])
+    assert_match(/^[+-]?\d+(?:\.\d*)?$/, @controller.params[:lon])
     assert_in_delta lat, @controller.params[:lat].to_f
     assert_in_delta lon, @controller.params[:lon].to_f
   end