cpf_cnpj 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.github/dependabot.yml +15 -0
- data/.github/workflows/ruby-tests.yml +47 -0
- data/.rubocop.yml +10 -56
- data/README.md +24 -14
- data/Rakefile +4 -1
- data/bin/cnpj +1 -1
- data/bin/cpf +1 -1
- data/cpf_cnpj.gemspec +21 -14
- data/lib/cnpj/formatter.rb +4 -3
- data/lib/cnpj/verifier_digit.rb +1 -1
- data/lib/cnpj.rb +22 -13
- data/lib/cpf/formatter.rb +2 -2
- data/lib/cpf/verifier_digit.rb +1 -1
- data/lib/cpf.rb +22 -14
- data/lib/cpf_cnpj/cli.rb +1 -2
- data/lib/cpf_cnpj/generator.rb +2 -2
- data/lib/cpf_cnpj/version.rb +1 -1
- data/test/cnpj/cli_test.rb +112 -0
- data/test/{unit/cnpj → cnpj}/formatter_test.rb +2 -0
- data/test/{unit/cnpj_test.rb → cnpj_test.rb} +21 -2
- data/test/cpf/cli_test.rb +112 -0
- data/test/{unit/cpf → cpf}/formatter_test.rb +6 -4
- data/test/{unit/cpf_test.rb → cpf_test.rb} +15 -2
- data/test/support/run_command.rb +30 -0
- data/test/test_helper.rb +1 -1
- metadata +54 -32
- data/.travis.yml +0 -8
- data/test/support/capture_syscall.rb +0 -18
- data/test/unit/cnpj/cli_test.rb +0 -134
- data/test/unit/cpf/cli_test.rb +0 -134
- /data/test/{unit/cnpj → cnpj}/generator_test.rb +0 -0
- /data/test/{unit/cpf → cpf}/generator_test.rb +0 -0
@@ -3,7 +3,7 @@
|
|
3
3
|
require "test_helper"
|
4
4
|
|
5
5
|
class CnpjTest < Minitest::Test
|
6
|
-
test "
|
6
|
+
test "rejects common numbers" do
|
7
7
|
refute CNPJ.valid?("00000000000000")
|
8
8
|
refute CNPJ.valid?("11111111111111")
|
9
9
|
refute CNPJ.valid?("22222222222222")
|
@@ -26,16 +26,26 @@ class CnpjTest < Minitest::Test
|
|
26
26
|
|
27
27
|
test "validates formatted strings" do
|
28
28
|
number = "54.550.752/0001-55"
|
29
|
+
|
29
30
|
assert CNPJ.valid?(number)
|
30
31
|
end
|
31
32
|
|
33
|
+
test "formats number" do
|
34
|
+
cnpj = CNPJ.new("54550752000155")
|
35
|
+
|
36
|
+
assert_equal "54.550.752/0001-55", cnpj.formatted
|
37
|
+
assert_equal "54.550.752/0001-55", CNPJ.format("54550752000155")
|
38
|
+
end
|
39
|
+
|
32
40
|
test "validates unformatted strings" do
|
33
41
|
number = "54550752000155"
|
42
|
+
|
34
43
|
assert CNPJ.valid?(number)
|
35
44
|
end
|
36
45
|
|
37
46
|
test "validates messed strings" do
|
38
47
|
number = "54550[752#0001..$55"
|
48
|
+
|
39
49
|
assert CNPJ.valid?(number)
|
40
50
|
end
|
41
51
|
|
@@ -51,8 +61,11 @@ class CnpjTest < Minitest::Test
|
|
51
61
|
refute CNPJ.valid?("aa.bb.ccc/dddd-ee")
|
52
62
|
end
|
53
63
|
|
54
|
-
test "
|
64
|
+
test "strictly validates strings" do
|
55
65
|
refute CNPJ.valid?("aa.bb.ccc/dddd-ee", strict: true)
|
66
|
+
refute CNPJ.valid?("54....550....752///0001---55", strict: true)
|
67
|
+
assert CNPJ.valid?("54.550.752/0001-55", strict: true)
|
68
|
+
assert CNPJ.valid?("54550752000155", strict: true)
|
56
69
|
end
|
57
70
|
|
58
71
|
test "compare objects by their numeric value" do
|
@@ -65,4 +78,10 @@ class CnpjTest < Minitest::Test
|
|
65
78
|
refute_equal one, different
|
66
79
|
refute_equal other, different
|
67
80
|
end
|
81
|
+
|
82
|
+
test "returns number without verifier" do
|
83
|
+
cnpj = CNPJ.new("54550752000155")
|
84
|
+
|
85
|
+
assert_equal "545507520001", cnpj.number_without_verifier
|
86
|
+
end
|
68
87
|
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
module CPFCli
|
6
|
+
class CheckTest < Minitest::Test
|
7
|
+
include RunCommand
|
8
|
+
|
9
|
+
%w[-c --check].each do |switch|
|
10
|
+
test "checks if provided number is valid [using #{switch}]" do
|
11
|
+
exit_status, stdout = run_command([switch, "76616598837"])
|
12
|
+
|
13
|
+
assert_equal 0, exit_status
|
14
|
+
assert_equal "", stdout
|
15
|
+
end
|
16
|
+
|
17
|
+
test "outputs error if provided number is invalid [using #{switch}]" do
|
18
|
+
exit_status, _, stderr = run_command([switch, "invalid"])
|
19
|
+
|
20
|
+
assert_equal 1, exit_status
|
21
|
+
assert_includes stderr, "Error: Invalid number"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class HelpTest < Minitest::Test
|
27
|
+
include RunCommand
|
28
|
+
|
29
|
+
%w[-h --help].each do |switch|
|
30
|
+
test "outputs help [using #{switch}]" do
|
31
|
+
exit_status, _, stderr = run_command([switch])
|
32
|
+
|
33
|
+
assert_equal 1, exit_status
|
34
|
+
assert_includes stderr, "Usage: cpf"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test "outputs help on tail" do
|
39
|
+
exit_status, _, stderr = run_command([])
|
40
|
+
|
41
|
+
assert_equal 1, exit_status
|
42
|
+
assert_includes stderr, "Usage: cpf"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class VersionTest < Minitest::Test
|
47
|
+
include RunCommand
|
48
|
+
|
49
|
+
%w[-v --version].each do |switch|
|
50
|
+
test "outputs version [using #{switch}]" do
|
51
|
+
exit_status, stdout, _stderr = run_command([switch])
|
52
|
+
|
53
|
+
assert_equal 0, exit_status
|
54
|
+
assert_includes stdout, CPF::VERSION.to_s
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class GenerateTest < Minitest::Test
|
60
|
+
include RunCommand
|
61
|
+
|
62
|
+
%w[-g --generate].each do |switch|
|
63
|
+
test "generates number [using #{switch}]" do
|
64
|
+
exit_status, stdout = run_command([switch])
|
65
|
+
|
66
|
+
assert_equal 0, exit_status
|
67
|
+
assert_match CPF::REGEX, stdout
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
test "generates stripped number" do
|
72
|
+
exit_status, stdout = run_command(["-gs"])
|
73
|
+
|
74
|
+
assert_equal 0, exit_status
|
75
|
+
assert_match(/\A\d{11}\Z/, stdout)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class FormatTest < Minitest::Test
|
80
|
+
include RunCommand
|
81
|
+
|
82
|
+
%w[-f --format].each do |switch|
|
83
|
+
test "formats argument [using #{switch}]" do
|
84
|
+
exit_status, stdout = run_command([switch, "76616598837"])
|
85
|
+
|
86
|
+
assert_equal 0, exit_status
|
87
|
+
assert_includes stdout, "766.165.988-37"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
test "formats argument using stdin" do
|
92
|
+
exit_status, stdout = run_command(["--format"], input: "76616598837")
|
93
|
+
|
94
|
+
assert_equal 0, exit_status
|
95
|
+
assert_includes stdout, "766.165.988-37"
|
96
|
+
end
|
97
|
+
|
98
|
+
test "fails when providing invalid number" do
|
99
|
+
exit_status, _, stderr = run_command(["--format", "invalid"])
|
100
|
+
|
101
|
+
assert_equal 1, exit_status
|
102
|
+
assert_includes stderr, "Error: Invalid number"
|
103
|
+
end
|
104
|
+
|
105
|
+
test "fails when not providing a number" do
|
106
|
+
exit_status, _, stderr = run_command(["--format"])
|
107
|
+
|
108
|
+
assert_equal 1, exit_status
|
109
|
+
assert_includes stderr, "Error: Invalid number"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -4,12 +4,14 @@ require "test_helper"
|
|
4
4
|
|
5
5
|
class CPFFormatterTest < Minitest::Test
|
6
6
|
test "formats strings without separators" do
|
7
|
-
number = "
|
8
|
-
|
7
|
+
number = "12345678901"
|
8
|
+
|
9
|
+
assert_equal "123.456.789-01", CPF::Formatter.format(number)
|
9
10
|
end
|
10
11
|
|
11
12
|
test "removes any non-numeric characters" do
|
12
|
-
number = "\n12$345[678/
|
13
|
-
|
13
|
+
number = "\n12$345[678/901-"
|
14
|
+
|
15
|
+
assert_equal "12345678901", CPF::Formatter.strip(number)
|
14
16
|
end
|
15
17
|
end
|
@@ -3,8 +3,7 @@
|
|
3
3
|
require "test_helper"
|
4
4
|
|
5
5
|
class CpfTest < Minitest::Test
|
6
|
-
test "
|
7
|
-
refute CPF.valid?("01234567890")
|
6
|
+
test "rejects common numbers" do
|
8
7
|
refute CPF.valid?("11111111111")
|
9
8
|
refute CPF.valid?("22222222222")
|
10
9
|
refute CPF.valid?("33333333333")
|
@@ -14,6 +13,7 @@ class CpfTest < Minitest::Test
|
|
14
13
|
refute CPF.valid?("77777777777")
|
15
14
|
refute CPF.valid?("88888888888")
|
16
15
|
refute CPF.valid?("99999999999")
|
16
|
+
refute CPF.valid?("00000000000")
|
17
17
|
refute CPF.valid?("12345678909")
|
18
18
|
end
|
19
19
|
|
@@ -31,21 +31,25 @@ class CpfTest < Minitest::Test
|
|
31
31
|
|
32
32
|
test "validates formatted strings" do
|
33
33
|
number = "295.379.955-93"
|
34
|
+
|
34
35
|
assert CPF.valid?(number)
|
35
36
|
end
|
36
37
|
|
37
38
|
test "validates unformatted strings" do
|
38
39
|
number = "29537995593"
|
40
|
+
|
39
41
|
assert CPF.valid?(number)
|
40
42
|
end
|
41
43
|
|
42
44
|
test "validates messed strings" do
|
43
45
|
number = "295$379\n955...93"
|
46
|
+
|
44
47
|
assert CPF.valid?(number)
|
45
48
|
end
|
46
49
|
|
47
50
|
test "strictly validates strings" do
|
48
51
|
refute CPF.valid?("295$379\n955...93", strict: true)
|
52
|
+
refute CPF.valid?("295.......379.......955-----93", strict: true)
|
49
53
|
assert CPF.valid?("295.379.955-93", strict: true)
|
50
54
|
assert CPF.valid?("29537995593", strict: true)
|
51
55
|
end
|
@@ -56,12 +60,15 @@ class CpfTest < Minitest::Test
|
|
56
60
|
|
57
61
|
test "returns stripped number" do
|
58
62
|
cpf = CPF.new("295.379.955-93")
|
63
|
+
|
59
64
|
assert_equal "29537995593", cpf.stripped
|
60
65
|
end
|
61
66
|
|
62
67
|
test "formats number" do
|
63
68
|
cpf = CPF.new("29537995593")
|
69
|
+
|
64
70
|
assert_equal "295.379.955-93", cpf.formatted
|
71
|
+
assert_equal "295.379.955-93", CPF.format("29537995593")
|
65
72
|
end
|
66
73
|
|
67
74
|
test "generates formatted number" do
|
@@ -90,4 +97,10 @@ class CpfTest < Minitest::Test
|
|
90
97
|
refute_equal one, different
|
91
98
|
refute_equal other, different
|
92
99
|
end
|
100
|
+
|
101
|
+
test "returns number without verifier" do
|
102
|
+
cpf = CPF.new("29537995593")
|
103
|
+
|
104
|
+
assert_equal "295379955", cpf.number_without_verifier
|
105
|
+
end
|
93
106
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RunCommand
|
4
|
+
class TTYStringIO < StringIO
|
5
|
+
def tty?
|
6
|
+
true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_command(args, input: nil)
|
11
|
+
stdout = StringIO.new
|
12
|
+
stderr = StringIO.new
|
13
|
+
stdin = input ? StringIO.new(input) : TTYStringIO.new
|
14
|
+
exit_status = 0
|
15
|
+
|
16
|
+
mod = if self.class.name.start_with?("CPF")
|
17
|
+
CPF
|
18
|
+
else
|
19
|
+
CNPJ
|
20
|
+
end
|
21
|
+
|
22
|
+
begin
|
23
|
+
CpfCnpj::CLI.new(mod, args, stdin, stdout, stderr).start
|
24
|
+
rescue SystemExit => error
|
25
|
+
exit_status = error.status
|
26
|
+
end
|
27
|
+
|
28
|
+
[exit_status, stdout.tap(&:rewind).read, stderr.tap(&:rewind).read]
|
29
|
+
end
|
30
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cpf_cnpj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest-utils
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: pry-meta
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +53,21 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-fnando
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
73
|
- - ">="
|
@@ -62,9 +90,11 @@ executables:
|
|
62
90
|
extensions: []
|
63
91
|
extra_rdoc_files: []
|
64
92
|
files:
|
93
|
+
- ".github/FUNDING.yml"
|
94
|
+
- ".github/dependabot.yml"
|
95
|
+
- ".github/workflows/ruby-tests.yml"
|
65
96
|
- ".gitignore"
|
66
97
|
- ".rubocop.yml"
|
67
|
-
- ".travis.yml"
|
68
98
|
- Gemfile
|
69
99
|
- LICENSE
|
70
100
|
- README.md
|
@@ -82,20 +112,23 @@ files:
|
|
82
112
|
- lib/cpf_cnpj/cli.rb
|
83
113
|
- lib/cpf_cnpj/generator.rb
|
84
114
|
- lib/cpf_cnpj/version.rb
|
85
|
-
- test/
|
115
|
+
- test/cnpj/cli_test.rb
|
116
|
+
- test/cnpj/formatter_test.rb
|
117
|
+
- test/cnpj/generator_test.rb
|
118
|
+
- test/cnpj_test.rb
|
119
|
+
- test/cpf/cli_test.rb
|
120
|
+
- test/cpf/formatter_test.rb
|
121
|
+
- test/cpf/generator_test.rb
|
122
|
+
- test/cpf_test.rb
|
123
|
+
- test/support/run_command.rb
|
86
124
|
- test/test_helper.rb
|
87
|
-
|
88
|
-
- test/unit/cnpj/formatter_test.rb
|
89
|
-
- test/unit/cnpj/generator_test.rb
|
90
|
-
- test/unit/cnpj_test.rb
|
91
|
-
- test/unit/cpf/cli_test.rb
|
92
|
-
- test/unit/cpf/formatter_test.rb
|
93
|
-
- test/unit/cpf/generator_test.rb
|
94
|
-
- test/unit/cpf_test.rb
|
95
|
-
homepage:
|
125
|
+
homepage: https://github.com/fnando/cpf_cnpj
|
96
126
|
licenses: []
|
97
|
-
metadata:
|
98
|
-
|
127
|
+
metadata:
|
128
|
+
homepage_uri: https://github.com/fnando/cpf_cnpj
|
129
|
+
source_code_uri: https://github.com/fnando/cpf_cnpj
|
130
|
+
rubygems_mfa_required: 'true'
|
131
|
+
post_install_message:
|
99
132
|
rdoc_options: []
|
100
133
|
require_paths:
|
101
134
|
- lib
|
@@ -103,26 +136,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
136
|
requirements:
|
104
137
|
- - ">="
|
105
138
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
139
|
+
version: 2.7.0
|
107
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
141
|
requirements:
|
109
142
|
- - ">="
|
110
143
|
- !ruby/object:Gem::Version
|
111
144
|
version: '0'
|
112
145
|
requirements: []
|
113
|
-
|
114
|
-
|
115
|
-
signing_key:
|
146
|
+
rubygems_version: 3.5.16
|
147
|
+
signing_key:
|
116
148
|
specification_version: 4
|
117
149
|
summary: Validate, generate and format CPF/CNPJ numbers. Include command-line tools.
|
118
|
-
test_files:
|
119
|
-
- test/support/capture_syscall.rb
|
120
|
-
- test/test_helper.rb
|
121
|
-
- test/unit/cnpj/cli_test.rb
|
122
|
-
- test/unit/cnpj/formatter_test.rb
|
123
|
-
- test/unit/cnpj/generator_test.rb
|
124
|
-
- test/unit/cnpj_test.rb
|
125
|
-
- test/unit/cpf/cli_test.rb
|
126
|
-
- test/unit/cpf/formatter_test.rb
|
127
|
-
- test/unit/cpf/generator_test.rb
|
128
|
-
- test/unit/cpf_test.rb
|
150
|
+
test_files: []
|
data/.travis.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "timeout"
|
4
|
-
|
5
|
-
module CaptureSyscall
|
6
|
-
def capture_syscall
|
7
|
-
exit_status = nil
|
8
|
-
|
9
|
-
stdout, stderr = Timeout.timeout(1) do
|
10
|
-
capture_subprocess_io do
|
11
|
-
yield
|
12
|
-
exit_status = $CHILD_STATUS.exitstatus
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
[exit_status, stdout, stderr]
|
17
|
-
end
|
18
|
-
end
|
data/test/unit/cnpj/cli_test.rb
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
module CNPJCli
|
6
|
-
class CheckTest < Minitest::Test
|
7
|
-
include CaptureSyscall
|
8
|
-
|
9
|
-
%w[-c --check].each do |switch|
|
10
|
-
test "checks if provided number is valid [using #{switch}]" do
|
11
|
-
exit_status, stdout = capture_syscall do
|
12
|
-
system "./bin/cnpj #{switch} 54550752000155"
|
13
|
-
end
|
14
|
-
|
15
|
-
assert_equal 0, exit_status
|
16
|
-
assert_equal stdout, ""
|
17
|
-
end
|
18
|
-
|
19
|
-
test "outputs error message if provided number is invalid [using #{switch}]" do
|
20
|
-
exit_status, _, stderr = capture_syscall do
|
21
|
-
system "./bin/cnpj #{switch} invalid"
|
22
|
-
end
|
23
|
-
|
24
|
-
assert_equal 1, exit_status
|
25
|
-
assert stderr.include?("Error: Invalid number")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class HelpTest < Minitest::Test
|
31
|
-
include CaptureSyscall
|
32
|
-
|
33
|
-
%w[-h --help].each do |switch|
|
34
|
-
test "outputs help [using #{switch}]" do
|
35
|
-
exit_status, _, stderr = capture_syscall do
|
36
|
-
system "./bin/cnpj #{switch}"
|
37
|
-
end
|
38
|
-
|
39
|
-
assert_equal 1, exit_status
|
40
|
-
assert stderr.include?("Usage: cnpj")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
test "outputs help on tail" do
|
45
|
-
exit_status, _, stderr = capture_syscall do
|
46
|
-
system "./bin/cnpj"
|
47
|
-
end
|
48
|
-
|
49
|
-
assert_equal 1, exit_status
|
50
|
-
assert stderr.include?("Usage: cnpj")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class VersionTest < Minitest::Test
|
55
|
-
include CaptureSyscall
|
56
|
-
|
57
|
-
%w[-v --version].each do |switch|
|
58
|
-
test "outputs version [using #{switch}]" do
|
59
|
-
exit_status, stdout = capture_syscall do
|
60
|
-
system "./bin/cnpj #{switch}"
|
61
|
-
end
|
62
|
-
|
63
|
-
assert_equal 0, exit_status
|
64
|
-
assert stdout.include?(CNPJ::VERSION.to_s)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class GenerateTest < Minitest::Test
|
70
|
-
include CaptureSyscall
|
71
|
-
|
72
|
-
%w[-g --generate].each do |switch|
|
73
|
-
test "generates number [using #{switch}]" do
|
74
|
-
exit_status, stdout = capture_syscall do
|
75
|
-
system "./bin/cnpj #{switch}"
|
76
|
-
end
|
77
|
-
|
78
|
-
assert_equal 0, exit_status
|
79
|
-
assert_match CNPJ::REGEX, stdout
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
test "generates stripped number" do
|
84
|
-
exit_status, stdout = capture_syscall do
|
85
|
-
system "./bin/cnpj -gs"
|
86
|
-
end
|
87
|
-
|
88
|
-
assert_equal 0, exit_status
|
89
|
-
assert_match(/\A\d{14}\Z/, stdout)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
class FormatTest < Minitest::Test
|
94
|
-
include CaptureSyscall
|
95
|
-
|
96
|
-
%w[-f --format].each do |switch|
|
97
|
-
test "formats argument [using #{switch}]" do
|
98
|
-
exit_status, stdout = capture_syscall do
|
99
|
-
system "./bin/cnpj #{switch} 54550752000155"
|
100
|
-
end
|
101
|
-
|
102
|
-
assert_equal 0, exit_status
|
103
|
-
assert stdout.include?("54.550.752/0001-55")
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
test "formats argument using stdin" do
|
108
|
-
exit_status, stdout = capture_syscall do
|
109
|
-
system "echo 54550752000155 | ./bin/cnpj --format"
|
110
|
-
end
|
111
|
-
|
112
|
-
assert_equal 0, exit_status
|
113
|
-
assert stdout.include?("54.550.752/0001-55")
|
114
|
-
end
|
115
|
-
|
116
|
-
test "fails when providing invalid number" do
|
117
|
-
exit_status, _, stderr = capture_syscall do
|
118
|
-
system "./bin/cnpj --format invalid"
|
119
|
-
end
|
120
|
-
|
121
|
-
assert_equal 1, exit_status
|
122
|
-
assert stderr.include?("Error: Invalid number")
|
123
|
-
end
|
124
|
-
|
125
|
-
test "fails when not providing a number" do
|
126
|
-
exit_status, _, stderr = capture_syscall do
|
127
|
-
system "./bin/cnpj --format"
|
128
|
-
end
|
129
|
-
|
130
|
-
assert_equal 1, exit_status
|
131
|
-
assert stderr.include?("Error: Invalid number")
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|