]> git.openstreetmap.org Git - rails.git/commitdiff
Add some more tests for library code
authorTom Hughes <tom@compton.nu>
Wed, 26 Feb 2014 00:33:19 +0000 (00:33 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 26 Feb 2014 00:33:19 +0000 (00:33 +0000)
test/lib/country_test.rb [new file with mode: 0644]
test/lib/utf8_test.rb [new file with mode: 0644]

diff --git a/test/lib/country_test.rb b/test/lib/country_test.rb
new file mode 100644 (file)
index 0000000..14827c0
--- /dev/null
@@ -0,0 +1,28 @@
+require 'test_helper'
+
+class CountryTest < ActiveSupport::TestCase
+  def test_gb
+    gb = Country.find_by_code("GB")
+    assert_not_nil gb
+    assert_equal "GB", gb.code
+    assert_equal -8.623555, gb.min_lon
+    assert_equal 59.360249, gb.max_lat
+    assert_equal 1.759, gb.max_lon
+    assert_equal 49.906193, gb.min_lat
+  end
+
+  def test_au
+    au = Country.find_by_code("AU")
+    assert_not_nil au
+    assert_equal "AU", au.code
+    assert_equal 112.911057, au.min_lon
+    assert_equal -10.062805, au.max_lat
+    assert_equal 153.639252, au.max_lon
+    assert_equal -43.64397, au.min_lat
+  end
+
+  def test_xx
+    xx = Country.find_by_code("XX")
+    assert_nil xx
+  end
+end
diff --git a/test/lib/utf8_test.rb b/test/lib/utf8_test.rb
new file mode 100644 (file)
index 0000000..1604b52
--- /dev/null
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+require 'test_helper'
+
+class UTF8Test < ActiveSupport::TestCase
+  def test_valid?
+    assert_equal true, UTF8.valid?("test")
+    assert_equal true, UTF8.valid?("vergrößern")
+    assert_equal true, UTF8.valid?("ルシステムにも対応します")
+    assert_equal true, UTF8.valid?("輕觸搖晃的遊戲")
+
+    assert_equal false, UTF8.valid?("\xC0")         # always invalid utf8
+    assert_equal false, UTF8.valid?("\xC2\x4a")     # 2-byte multibyte identifier, followed by plain ASCII
+    assert_equal false, UTF8.valid?("\xC2\xC2")     # 2-byte multibyte identifier, followed by another one
+    assert_equal false, UTF8.valid?("\x4a\x82")     # plain ASCII, followed by multibyte continuation
+    assert_equal false, UTF8.valid?("\x82\x82")     # multibyte continuations without multibyte identifier
+    assert_equal false, UTF8.valid?("\xe1\x82\x4a") # three-byte identifier, contination and (incorrectly) plain ASCII
+  end
+end