Skip to content
Browse files

Spanish Bank Account Number

  • Loading branch information...
1 parent 4d249e6 commit 62f520b3e7d4a1601a6bbdc1f77cd5c112e09158 @fguillen fguillen committed Sep 22, 2012
Showing with 36 additions and 2 deletions.
  1. +3 −0 lib/ruby_regex.rb
  2. +22 −0 test/fixtures/spanish_bank_account_numbers.yml
  3. +11 −2 test/ruby_regex_test.rb
View
3 lib/ruby_regex.rb
@@ -60,4 +60,7 @@ module RubyRegex
# Date Time DB format YYYY-MM-DD hh:mm:ss
DBDateTime = /\A\d{4}-(#{("01".."12").to_a.join("|")})-(#{("01".."31").to_a.join("|")})\s(#{("00".."23").to_a.join("|")}):(#{("00".."59").to_a.join("|")}):(#{("00".."59").to_a.join("|")})\z/
+
+ # SpanishBankAccountNumber
+ SpanishBankAccountNumber = /\A\d{4}[ -]?\d{4}[ -]?\d{2}[ -]?\d{10}\z/
end
View
22 test/fixtures/spanish_bank_account_numbers.yml
@@ -0,0 +1,22 @@
+valid:
+ - "11112222334444444444"
+ - "1111222233-4444444444"
+ - "11112222-33-4444444444"
+ - "1111-2222-33-4444444444"
+ - "1111222233 4444444444"
+ - "11112222 33 4444444444"
+ - "1111 2222 33 4444444444"
+ - "1111 2222-33-4444444444"
+
+
+invalid:
+ - ""
+ - "11"
+ - "111122223344444444445"
+ - "AAAA2222334444444444"
+ - "1111222233-4444-444444"
+ - "1111-2222-33-4444444444-"
+ - "-1111-2222-33-4444444444"
+ - "1111222233--4444444444"
+ - "1111222233 4444444444"
+ - "1111222233 -4444444444"
View
13 test/ruby_regex_test.rb
@@ -147,21 +147,30 @@ def test_invalid_db_date_times
check_invalid_regex RubyRegex::DBDateTime, load_fixture('db_date_times')['invalid']
end
+ # SpanishBankAccountNumber
+ def test_valid_spanish_bank_account_numbers
+ check_valid_regex RubyRegex::SpanishBankAccountNumber, load_fixture('spanish_bank_account_numbers')['valid']
+ end
+
+ def test_invalid_spanish_bank_account_numbers
+ check_invalid_regex RubyRegex::SpanishBankAccountNumber, load_fixture('spanish_bank_account_numbers')['invalid']
+ end
+
private
def load_fixture( name )
YAML.load( File.read( File.join( File.dirname(__FILE__), 'fixtures', "#{name}.yml" ) ) )
end
def check_valid_regex(regexp, strings)
strings.each do |str|
- message = build_message(message, '<?> does not pass the test', str)
+ message = build_message(message, '<?> should be valid but it is not', str)
assert(str =~ regexp, message)
end
end
def check_invalid_regex(regexp, strings)
strings.each do |str|
- message = build_message(message, '<?> does not pass the test', str)
+ message = build_message(message, '<?> should be invalid but it is not', str)
assert(str !~ regexp, message)
end
end

0 comments on commit 62f520b

Please sign in to comment.
Something went wrong with that request. Please try again.