forked from faker-ruby/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_en_locale.rb
59 lines (45 loc) · 2.01 KB
/
test_en_locale.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true
require_relative 'test_helper'
class TestEnLocale < Test::Unit::TestCase
def setup
Faker::Config.locale = 'en'
end
def teardown
Faker::Config.locale = nil
end
def test_us_states_only_include_states
assert_equal(['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'], I18n.translate('faker.address.state'))
assert_equal(%w[AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY], I18n.translate('faker.address.state_abbr'))
end
def test_us_zip_codes
expected = /\d{5}(-\d{4})?/
assert_match(expected, Faker::Address.zip_code)
end
def test_valid_id_number
id_num = Faker::IdNumber.valid
assert(Faker::IdNumber::INVALID_SSN.none? { |regex| id_num =~ regex })
end
def test_invalid_id_number
id_num = Faker::IdNumber.invalid
assert(Faker::IdNumber::INVALID_SSN.any? { |regex| id_num =~ regex })
end
def test_values_trimmed
en_file = YAML.load_file('lib/locales/en.yml')
check_hash(en_file)
end
def check_hash(hash)
hash.each { |key, value| check_value(value) unless key == 'separator' }
end
def check_value(value)
if value.is_a?(Hash)
check_hash(value)
elsif value.is_a?(Array)
check_array(value)
else
assert_nil(value.strip!) unless value.nil?
end
end
def check_array(array)
array.each { |value| check_value(value) }
end
end