kosi 0.0.1
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 +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +8 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.html +273 -0
- data/README.md +290 -0
- data/Rakefile +8 -0
- data/kosi.gemspec +28 -0
- data/lib/kosi.rb +13 -0
- data/lib/kosi/align.rb +33 -0
- data/lib/kosi/char_option.rb +17 -0
- data/lib/kosi/connector_char.rb +26 -0
- data/lib/kosi/header.rb +18 -0
- data/lib/kosi/horizontal_border_char.rb +26 -0
- data/lib/kosi/options.rb +15 -0
- data/lib/kosi/separate_each_row.rb +15 -0
- data/lib/kosi/validators.rb +3 -0
- data/lib/kosi/validators/each_array_length_validator.rb +21 -0
- data/lib/kosi/validators/row_type_validator.rb +19 -0
- data/lib/kosi/version.rb +4 -0
- data/lib/kosi/vertical_border_char.rb +26 -0
- data/lib/table.rb +138 -0
- data/spec/kosi/align_spec.rb +77 -0
- data/spec/kosi/connector_char_spec.rb +59 -0
- data/spec/kosi/header_spec.rb +93 -0
- data/spec/kosi/horizontal_border_char_spec.rb +59 -0
- data/spec/kosi/separate_each_row_spec.rb +55 -0
- data/spec/kosi/validators/each_array_length_validator_spec.rb +56 -0
- data/spec/kosi/validators/row_type_validator_spec.rb +51 -0
- data/spec/kosi/vertical_border_char_spec.rb +59 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/table_spec.rb +134 -0
- metadata +173 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kosi'
|
3
|
+
|
4
|
+
describe Kosi::ConnectorChar do
|
5
|
+
context :value do
|
6
|
+
cases = [
|
7
|
+
{
|
8
|
+
case_no: 1,
|
9
|
+
case_title: 'no options case',
|
10
|
+
options: {},
|
11
|
+
expected: Kosi::ConnectorChar::DEFAULT
|
12
|
+
},
|
13
|
+
{
|
14
|
+
case_no: 2,
|
15
|
+
case_title: 'valid connector char options case',
|
16
|
+
options: { Kosi::OptionKeys::CONNECTOR_CHAR => '@' },
|
17
|
+
expected: '@'
|
18
|
+
},
|
19
|
+
{
|
20
|
+
case_no: 3,
|
21
|
+
case_title: 'invalid connector char options case',
|
22
|
+
options: { Kosi::OptionKeys::CONNECTOR_CHAR => '++' },
|
23
|
+
expect_error: true
|
24
|
+
}
|
25
|
+
]
|
26
|
+
|
27
|
+
cases.each do |c|
|
28
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
29
|
+
begin
|
30
|
+
case_before c
|
31
|
+
|
32
|
+
# -- given --
|
33
|
+
if c[:expect_error]
|
34
|
+
-> { Kosi::ConnectorChar.new(c[:options]) }
|
35
|
+
.should raise_error(ArgumentError)
|
36
|
+
next
|
37
|
+
end
|
38
|
+
connector_char = Kosi::ConnectorChar.new(c[:options])
|
39
|
+
|
40
|
+
# -- when --
|
41
|
+
actual = connector_char.value
|
42
|
+
|
43
|
+
# -- then --
|
44
|
+
expect(actual).to eq(c[:expected])
|
45
|
+
ensure
|
46
|
+
case_after c
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def case_before(c)
|
51
|
+
# implement each case before
|
52
|
+
end
|
53
|
+
|
54
|
+
def case_after(c)
|
55
|
+
# implement each case after
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'kosi'
|
4
|
+
|
5
|
+
describe Kosi::Header do
|
6
|
+
context :value do
|
7
|
+
cases = [
|
8
|
+
{
|
9
|
+
case_no: 1,
|
10
|
+
case_title: 'no options case',
|
11
|
+
options: {},
|
12
|
+
expected: nil
|
13
|
+
},
|
14
|
+
{
|
15
|
+
case_no: 2,
|
16
|
+
case_title: 'align options left case',
|
17
|
+
options: { Kosi::OptionKeys::HEADER => %w(header1 header2) },
|
18
|
+
expected: %w(header1 header2)
|
19
|
+
}
|
20
|
+
]
|
21
|
+
|
22
|
+
cases.each do |c|
|
23
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
24
|
+
begin
|
25
|
+
case_before c
|
26
|
+
|
27
|
+
# -- given --
|
28
|
+
header = Kosi::Header.new(c[:options])
|
29
|
+
|
30
|
+
# -- when --
|
31
|
+
actual = header.value
|
32
|
+
|
33
|
+
# -- then --
|
34
|
+
expect(actual).to eq(c[:expected])
|
35
|
+
ensure
|
36
|
+
case_after c
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def case_before(c)
|
41
|
+
# implement each case before
|
42
|
+
end
|
43
|
+
|
44
|
+
def case_after(c)
|
45
|
+
# implement each case after
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context :empty? do
|
51
|
+
cases = [
|
52
|
+
{
|
53
|
+
case_no: 1,
|
54
|
+
case_title: 'no options case',
|
55
|
+
options: {},
|
56
|
+
expected: true
|
57
|
+
},
|
58
|
+
{
|
59
|
+
case_no: 2,
|
60
|
+
case_title: 'align options left case',
|
61
|
+
options: { Kosi::OptionKeys::HEADER => %w(header1 header2) },
|
62
|
+
expected: false
|
63
|
+
}
|
64
|
+
]
|
65
|
+
|
66
|
+
cases.each do |c|
|
67
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
68
|
+
begin
|
69
|
+
case_before c
|
70
|
+
|
71
|
+
# -- given --
|
72
|
+
header = Kosi::Header.new(c[:options])
|
73
|
+
|
74
|
+
# -- when --
|
75
|
+
actual = header.empty?
|
76
|
+
|
77
|
+
# -- then --
|
78
|
+
expect(actual).to eq(c[:expected])
|
79
|
+
ensure
|
80
|
+
case_after c
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def case_before(c)
|
85
|
+
# implement each case before
|
86
|
+
end
|
87
|
+
|
88
|
+
def case_after(c)
|
89
|
+
# implement each case after
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kosi'
|
3
|
+
|
4
|
+
describe Kosi::HorizontalBorderChar do
|
5
|
+
context :value do
|
6
|
+
cases = [
|
7
|
+
{
|
8
|
+
case_no: 1,
|
9
|
+
case_title: 'no options case',
|
10
|
+
options: {},
|
11
|
+
expected: Kosi::HorizontalBorderChar::DEFAULT
|
12
|
+
},
|
13
|
+
{
|
14
|
+
case_no: 2,
|
15
|
+
case_title: 'valid horizontal_border_char options case',
|
16
|
+
options: { Kosi::OptionKeys::HORIZONTAL_BORDER_CHAR => '@' },
|
17
|
+
expected: '@'
|
18
|
+
},
|
19
|
+
{
|
20
|
+
case_no: 3,
|
21
|
+
case_title: 'invalid horizontal_border_char options case',
|
22
|
+
options: { Kosi::OptionKeys::HORIZONTAL_BORDER_CHAR => '--' },
|
23
|
+
expect_error: true
|
24
|
+
}
|
25
|
+
]
|
26
|
+
|
27
|
+
cases.each do |c|
|
28
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
29
|
+
begin
|
30
|
+
case_before c
|
31
|
+
|
32
|
+
# -- given --
|
33
|
+
if c[:expect_error]
|
34
|
+
-> { Kosi::HorizontalBorderChar.new(c[:options]) }
|
35
|
+
.should raise_error(ArgumentError)
|
36
|
+
next
|
37
|
+
end
|
38
|
+
horizontal_border_char = Kosi::HorizontalBorderChar.new(c[:options])
|
39
|
+
|
40
|
+
# -- when --
|
41
|
+
actual = horizontal_border_char.value
|
42
|
+
|
43
|
+
# -- then --
|
44
|
+
expect(actual).to eq(c[:expected])
|
45
|
+
ensure
|
46
|
+
case_after c
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def case_before(c)
|
51
|
+
# implement each case before
|
52
|
+
end
|
53
|
+
|
54
|
+
def case_after(c)
|
55
|
+
# implement each case after
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'kosi'
|
4
|
+
|
5
|
+
describe Kosi::SeparateEachRow do
|
6
|
+
context :value do
|
7
|
+
cases = [
|
8
|
+
{
|
9
|
+
case_no: 1,
|
10
|
+
case_title: 'no options case',
|
11
|
+
options: {},
|
12
|
+
expected: Kosi::SeparateEachRow::DEFAULT
|
13
|
+
},
|
14
|
+
{
|
15
|
+
case_no: 2,
|
16
|
+
case_title: 'seprate_each_row options true case',
|
17
|
+
options: { Kosi::OptionKeys::SEPARATE_EACH_ROW => true },
|
18
|
+
expected: true
|
19
|
+
},
|
20
|
+
{
|
21
|
+
case_no: 3,
|
22
|
+
case_title: 'seprate_each_row options false case',
|
23
|
+
options: { Kosi::OptionKeys::SEPARATE_EACH_ROW => false },
|
24
|
+
expected: false
|
25
|
+
}
|
26
|
+
]
|
27
|
+
|
28
|
+
cases.each do |c|
|
29
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
30
|
+
begin
|
31
|
+
case_before c
|
32
|
+
|
33
|
+
# -- given --
|
34
|
+
separate_each_row = Kosi::SeparateEachRow.new(c[:options])
|
35
|
+
|
36
|
+
# -- when --
|
37
|
+
actual = separate_each_row.value
|
38
|
+
|
39
|
+
# -- then --
|
40
|
+
expect(actual).to eq(c[:expected])
|
41
|
+
ensure
|
42
|
+
case_after c
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def case_before(c)
|
47
|
+
# implement each case before
|
48
|
+
end
|
49
|
+
|
50
|
+
def case_after(c)
|
51
|
+
# implement each case after
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'kosi/validators/each_array_length_validator'
|
4
|
+
|
5
|
+
describe Kosi::Validators::EachArrayLength do
|
6
|
+
context :validate do
|
7
|
+
cases = [
|
8
|
+
{
|
9
|
+
case_no: 1,
|
10
|
+
case_title: 'Same Length Array case',
|
11
|
+
inputs: [[*1..5], [*6..10]],
|
12
|
+
},
|
13
|
+
{
|
14
|
+
case_no: 2,
|
15
|
+
case_title: 'Zero Length Array case',
|
16
|
+
inputs: [[], []],
|
17
|
+
},
|
18
|
+
{
|
19
|
+
case_no: 3,
|
20
|
+
case_title: 'Different Length Array case',
|
21
|
+
inputs: [[*1..5], [*6..11]],
|
22
|
+
expect_error: true,
|
23
|
+
error_class: ArgumentError
|
24
|
+
},
|
25
|
+
]
|
26
|
+
|
27
|
+
cases.each do |c|
|
28
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
29
|
+
begin
|
30
|
+
case_before c
|
31
|
+
|
32
|
+
# -- given --
|
33
|
+
# nothing
|
34
|
+
|
35
|
+
# -- when/then --
|
36
|
+
if c[:expect_error]
|
37
|
+
expect{ Kosi::Validators::EachArrayLength.validate(c[:inputs]) }.to raise_error(c[:error_class])
|
38
|
+
next
|
39
|
+
else
|
40
|
+
expect{ Kosi::Validators::EachArrayLength.validate(c[:inputs]) }.not_to raise_error
|
41
|
+
end
|
42
|
+
ensure
|
43
|
+
case_after c
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def case_before(c)
|
48
|
+
# implement each case before
|
49
|
+
end
|
50
|
+
|
51
|
+
def case_after(c)
|
52
|
+
# implement each case after
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'kosi/validators/row_type_validator'
|
4
|
+
|
5
|
+
describe Kosi::Validators::RowType do
|
6
|
+
context :validate do
|
7
|
+
cases = [
|
8
|
+
{
|
9
|
+
case_no: 1,
|
10
|
+
case_title: 'Array case',
|
11
|
+
inputs: ['Array'],
|
12
|
+
},
|
13
|
+
{
|
14
|
+
case_no: 2,
|
15
|
+
case_title: 'Not Array case',
|
16
|
+
inputs: "not Array",
|
17
|
+
expect_error: true,
|
18
|
+
error_class: ArgumentError
|
19
|
+
},
|
20
|
+
]
|
21
|
+
|
22
|
+
cases.each do |c|
|
23
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
24
|
+
begin
|
25
|
+
case_before c
|
26
|
+
|
27
|
+
# -- given --
|
28
|
+
# nothing
|
29
|
+
|
30
|
+
# -- when/then --
|
31
|
+
if c[:expect_error]
|
32
|
+
expect{ Kosi::Validators::RowType.validate(c[:inputs]) }.to raise_error(c[:error_class])
|
33
|
+
next
|
34
|
+
else
|
35
|
+
expect{ Kosi::Validators::RowType.validate(c[:inputs]) }.not_to raise_error
|
36
|
+
end
|
37
|
+
ensure
|
38
|
+
case_after c
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def case_before(c)
|
43
|
+
# implement each case before
|
44
|
+
end
|
45
|
+
|
46
|
+
def case_after(c)
|
47
|
+
# implement each case after
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kosi'
|
3
|
+
|
4
|
+
describe Kosi::VerticalBorderChar do
|
5
|
+
context :value do
|
6
|
+
cases = [
|
7
|
+
{
|
8
|
+
case_no: 1,
|
9
|
+
case_title: 'no options case',
|
10
|
+
options: {},
|
11
|
+
expected: Kosi::VerticalBorderChar::DEFAULT
|
12
|
+
},
|
13
|
+
{
|
14
|
+
case_no: 2,
|
15
|
+
case_title: 'valid vertical_border_char options case',
|
16
|
+
options: { Kosi::OptionKeys::VERTICAL_BORDER_CHAR => '@' },
|
17
|
+
expected: '@'
|
18
|
+
},
|
19
|
+
{
|
20
|
+
case_no: 3,
|
21
|
+
case_title: 'invalid vertical_border_char options case',
|
22
|
+
options: { Kosi::OptionKeys::VERTICAL_BORDER_CHAR => '||' },
|
23
|
+
expect_error: true
|
24
|
+
}
|
25
|
+
]
|
26
|
+
|
27
|
+
cases.each do |c|
|
28
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
29
|
+
begin
|
30
|
+
case_before c
|
31
|
+
|
32
|
+
# -- given --
|
33
|
+
if c[:expect_error]
|
34
|
+
-> { Kosi::VerticalBorderChar.new(c[:options]) }
|
35
|
+
.should raise_error(ArgumentError)
|
36
|
+
next
|
37
|
+
end
|
38
|
+
vertical_border_char = Kosi::VerticalBorderChar.new(c[:options])
|
39
|
+
|
40
|
+
# -- when --
|
41
|
+
actual = vertical_border_char.value
|
42
|
+
|
43
|
+
# -- then --
|
44
|
+
expect(actual).to eq(c[:expected])
|
45
|
+
ensure
|
46
|
+
case_after c
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def case_before(c)
|
51
|
+
# implement each case before
|
52
|
+
end
|
53
|
+
|
54
|
+
def case_after(c)
|
55
|
+
# implement each case after
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls.wear!
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
Coveralls::SimpleCov::Formatter
|
8
|
+
]
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter '/spec/'
|
11
|
+
end
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.filter_run :focus
|
16
|
+
end
|