test/phonelib_test.rb in phonelib-0.2.6 vs test/phonelib_test.rb in phonelib-0.2.7
- old
+ new
@@ -256,6 +256,59 @@
should 'show correct international' do
phone = Phonelib.parse('370 611 11 111')
assert_equal '+370 611 11111', phone.international
end
end
+
+ context 'issue #18' do
+ should 'not raise exceptions' do
+ assert_not_nil Phonelib.parse('54932', 'DE').national
+ assert_not_nil Phonelib.parse('33251304029', 'LU').national
+ assert_not_nil Phonelib.parse('61130374', 'AU').national
+ end
+ end
+
+ context 'example numbers' do
+ should 'be valid' do
+ data_file = File.dirname(__FILE__) + '/../data/phone_data.dat'
+ phone_data ||= Marshal.load(File.read(data_file))
+ phone_data.each do |data|
+ country = data[:id]
+ next unless country =~ /[A-Z]{2}/
+ data[:types].each do |type, type_data|
+ next unless Phonelib::Core::TYPES_DESC.keys.include? type
+ next unless type_data[:example_number]
+ number = "#{type_data[:example_number]}"
+ phone = Phonelib.parse(number, country)
+ msg = "Phone #{number} in #{country} of #{type}"
+
+ phone_assertions(phone, type, country, msg)
+ end
+ end
+ end
+
+ def phone_assertions(phone, type, country, msg)
+ assert phone.valid?, "#{msg} not valid"
+ assert !phone.invalid?, "#{msg} not valid"
+ assert phone.possible?, "#{msg} not possible"
+ assert !phone.impossible?, "#{msg} not possible"
+ assert phone.valid_for_country?(country),
+ "#{msg} not valid for country"
+ assert !phone.invalid_for_country?(country),
+ "#{msg} not valid for country"
+ assert phone.national.is_a? String
+ assert phone.national.length > 0
+ assert phone.international.is_a? String
+ assert phone.international.length > 0
+
+ assert_equal phone.country, country, "#{msg} wrong country "
+ if phone.type == Phonelib::Core::FIXED_OR_MOBILE
+ assert_contains [Phonelib::Core::FIXED_LINE, Phonelib::Core::MOBILE],
+ type,
+ "#{msg} wrong type #{phone.types}"
+ else
+ assert_contains phone.types, type,
+ "#{msg} wrong type #{phone.types}"
+ end
+ end
+ end
end