Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update regex used for Faker::Vehicle#vin #2475

Merged
merged 6 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/faker/default/vehicle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Vehicle < Base
VIN_LETTERS = 'ABCDEFGHJKLMNPRSTUVWXYZ'
VIN_MAP = '0123456789X'
VIN_WEIGHTS = '8765432X098765432'
VIN_REGEX = /^[A-Z0-9]{3}[A-Z0-9]{5}[A-Z0-9]{1}[A-Z0-9]{1}[A-Z0-0]{1}[A-Z0-9]{1}\d{5}$/.freeze
VIN_REGEX = /^([A-HJ-NPR-Z0-9]){3}[A-HJ-NPR-Z0-9]{5}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-0]{1}[A-HJ-NPR-Z0-9]{1}\d{5}$/.freeze
SG_CHECKSUM_WEIGHTS = [3, 14, 2, 12, 2, 11, 1].freeze
SG_CHECKSUM_CHARS = 'AYUSPLJGDBZXTRMKHEC'

Expand Down
5 changes: 5 additions & 0 deletions test/faker/default/test_faker_vehicle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class TestFakerVehicle < Test::Unit::TestCase
WORD_MATCH = /\w+\.?/.freeze
VALIDITY_MATCH = /^([A-HJ-NPR-Z0-9])+/.freeze

def setup
@tester = Faker::Vehicle
Expand All @@ -13,6 +14,10 @@ def test_vin
assert_match Faker::Vehicle::VIN_REGEX, @tester.vin
end

def test_vin_validity
assert_match VALIDITY_MATCH, @tester.vin
end

def test_manufacture
assert_match WORD_MATCH, @tester.manufacture
end
Expand Down