Sha256: 488f05d09cc227082c6e70c8b5a182e3e847337f719f7ed6281b99012aacfb6a
Contents?: true
Size: 1.98 KB
Versions: 1
Compression:
Stored size: 1.98 KB
Contents
# frozen_string_literal: true require "test_helper" class CpfTest < Minitest::Test test "blacklists common numbers" do refute CPF.valid?("01234567890") refute CPF.valid?("11111111111") refute CPF.valid?("22222222222") refute CPF.valid?("33333333333") refute CPF.valid?("44444444444") refute CPF.valid?("55555555555") refute CPF.valid?("66666666666") refute CPF.valid?("77777777777") refute CPF.valid?("88888888888") refute CPF.valid?("99999999999") refute CPF.valid?("12345678909") end test "rejects blank strings" do refute CPF.valid?("") end test "rejects strings" do refute CPF.valid?("aaa.bbb.ccc-dd") end test "rejects nil values" do refute CPF.valid?(nil) end test "validates formatted strings" do number = "295.379.955-93" assert CPF.valid?(number) end test "validates unformatted strings" do number = "29537995593" assert CPF.valid?(number) end test "validates messed strings" do number = "295$379\n955...93" assert CPF.valid?(number) end test "strictly validates strings" do refute CPF.valid?("295$379\n955...93", strict: true) assert CPF.valid?("295.379.955-93", strict: true) assert CPF.valid?("29537995593", strict: true) end test "rejects strings (strict)" do refute CPF.valid?("aaa.bbb.ccc-dd", strict: true) end test "returns stripped number" do cpf = CPF.new("295.379.955-93") assert_equal "29537995593", cpf.stripped end test "formats number" do cpf = CPF.new("29537995593") assert_equal "295.379.955-93", cpf.formatted end test "generates formatted number" do assert_match(/\A\d{3}\.\d{3}\.\d{3}-\d{2}\z/, CPF.generate(true)) end test "generates stripped number" do assert_match(/\A\d{11}\z/, CPF.generate) end test "invalidates memoization cache" do cpf = CPF.new("29537995593") cpf.number = "52139989171" assert_equal "52139989171", cpf.stripped assert_equal "521.399.891-71", cpf.formatted end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cpf_cnpj-0.4.1 | test/unit/cpf_test.rb |