csvops 0.1.0.alpha → 0.2.0.alpha
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/README.md +49 -10
- data/docs/release-v0.2.0-alpha.md +80 -0
- data/lib/csvtool/application/use_cases/run_extraction.rb +17 -17
- data/lib/csvtool/application/use_cases/run_row_extraction.rb +111 -0
- data/lib/csvtool/cli.rb +6 -2
- data/lib/csvtool/domain/{extraction_session → column_session}/column_selection.rb +1 -1
- data/lib/csvtool/domain/{extraction_session/extraction_session.rb → column_session/column_session.rb} +2 -2
- data/lib/csvtool/domain/{extraction_session → column_session}/csv_source.rb +1 -1
- data/lib/csvtool/domain/{extraction_session → column_session}/extraction_options.rb +1 -1
- data/lib/csvtool/domain/{extraction_session → column_session}/extraction_value.rb +1 -1
- data/lib/csvtool/domain/{extraction_session → column_session}/output_destination.rb +1 -1
- data/lib/csvtool/domain/{extraction_session → column_session}/preview.rb +1 -1
- data/lib/csvtool/domain/{extraction_session → column_session}/separator.rb +1 -1
- data/lib/csvtool/domain/row_session/row_output_destination.rb +31 -0
- data/lib/csvtool/domain/row_session/row_range.rb +39 -0
- data/lib/csvtool/domain/row_session/row_session.rb +25 -0
- data/lib/csvtool/domain/row_session/row_source.rb +16 -0
- data/lib/csvtool/infrastructure/csv/row_streamer.rb +27 -0
- data/lib/csvtool/infrastructure/output/csv_row_console_writer.rb +34 -0
- data/lib/csvtool/infrastructure/output/csv_row_file_writer.rb +45 -0
- data/lib/csvtool/interface/cli/errors/presenter.rb +16 -0
- data/lib/csvtool/interface/cli/menu_loop.rb +10 -5
- data/lib/csvtool/version.rb +1 -1
- data/test/csvtool/application/use_cases/run_row_extraction_test.rb +140 -0
- data/test/csvtool/cli_test.rb +132 -6
- data/test/csvtool/cli_unit_test.rb +12 -1
- data/test/csvtool/domain/{extraction_session → column_session}/column_selection_test.rb +2 -2
- data/test/csvtool/domain/column_session/column_session_test.rb +35 -0
- data/test/csvtool/domain/column_session/csv_source_test.rb +14 -0
- data/test/csvtool/domain/{extraction_session → column_session}/extraction_options_test.rb +3 -3
- data/test/csvtool/domain/{extraction_session → column_session}/extraction_value_test.rb +2 -2
- data/test/csvtool/domain/{extraction_session → column_session}/output_destination_test.rb +3 -3
- data/test/csvtool/domain/column_session/preview_test.rb +18 -0
- data/test/csvtool/domain/{extraction_session → column_session}/separator_test.rb +3 -3
- data/test/csvtool/domain/row_session/row_output_destination_test.rb +23 -0
- data/test/csvtool/domain/row_session/row_range_test.rb +30 -0
- data/test/csvtool/domain/row_session/row_session_test.rb +22 -0
- data/test/csvtool/domain/row_session/row_source_test.rb +12 -0
- data/test/csvtool/infrastructure/csv/row_streamer_test.rb +41 -0
- data/test/csvtool/infrastructure/output/csv_row_console_writer_test.rb +24 -0
- data/test/csvtool/infrastructure/output/csv_row_file_writer_test.rb +40 -0
- data/test/csvtool/interface/cli/errors/presenter_test.rb +8 -0
- data/test/csvtool/interface/cli/menu_loop_test.rb +37 -12
- data/test/fixtures/sample_people_bad_tail.csv +5 -0
- metadata +35 -17
- data/test/csvtool/domain/extraction_session/csv_source_test.rb +0 -14
- data/test/csvtool/domain/extraction_session/extraction_session_test.rb +0 -35
- data/test/csvtool/domain/extraction_session/preview_test.rb +0 -18
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../test_helper"
|
|
4
|
+
require "csvtool/domain/row_session/row_output_destination"
|
|
5
|
+
|
|
6
|
+
class RowRangeOutputDestinationTest < Minitest::Test
|
|
7
|
+
def test_console_destination
|
|
8
|
+
destination = Csvtool::Domain::RowSession::RowOutputDestination.console
|
|
9
|
+
refute destination.file?
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_file_destination
|
|
13
|
+
destination = Csvtool::Domain::RowSession::RowOutputDestination.file(path: "/tmp/out.csv")
|
|
14
|
+
assert destination.file?
|
|
15
|
+
assert_equal "/tmp/out.csv", destination.path
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_rejects_empty_file_path
|
|
19
|
+
assert_raises(ArgumentError) do
|
|
20
|
+
Csvtool::Domain::RowSession::RowOutputDestination.file(path: "")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../test_helper"
|
|
4
|
+
require "csvtool/domain/row_session/row_range"
|
|
5
|
+
|
|
6
|
+
class RowRangeTest < Minitest::Test
|
|
7
|
+
def test_builds_from_valid_inputs
|
|
8
|
+
row_range = Csvtool::Domain::RowSession::RowRange.from_inputs(start_row_input: "2", end_row_input: "4")
|
|
9
|
+
assert_equal 2, row_range.start_row
|
|
10
|
+
assert_equal 4, row_range.end_row
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_rejects_invalid_start_row
|
|
14
|
+
assert_raises(Csvtool::Domain::RowSession::InvalidStartRowError) do
|
|
15
|
+
Csvtool::Domain::RowSession::RowRange.from_inputs(start_row_input: "0", end_row_input: "2")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_rejects_invalid_end_row
|
|
20
|
+
assert_raises(Csvtool::Domain::RowSession::InvalidEndRowError) do
|
|
21
|
+
Csvtool::Domain::RowSession::RowRange.from_inputs(start_row_input: "1", end_row_input: "abc")
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_rejects_end_before_start
|
|
26
|
+
assert_raises(Csvtool::Domain::RowSession::InvalidRowRangeOrderError) do
|
|
27
|
+
Csvtool::Domain::RowSession::RowRange.from_inputs(start_row_input: "3", end_row_input: "2")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../test_helper"
|
|
4
|
+
require "csvtool/domain/row_session/row_session"
|
|
5
|
+
require "csvtool/domain/row_session/row_source"
|
|
6
|
+
require "csvtool/domain/row_session/row_range"
|
|
7
|
+
require "csvtool/domain/row_session/row_output_destination"
|
|
8
|
+
|
|
9
|
+
class RowSessionTest < Minitest::Test
|
|
10
|
+
def test_starts_and_sets_output_destination
|
|
11
|
+
source = Csvtool::Domain::RowSession::RowSource.new(path: "/tmp/a.csv", separator: ",")
|
|
12
|
+
row_range = Csvtool::Domain::RowSession::RowRange.new(start_row: 1, end_row: 2)
|
|
13
|
+
|
|
14
|
+
session = Csvtool::Domain::RowSession::RowSession.start(source: source, row_range: row_range)
|
|
15
|
+
destination = Csvtool::Domain::RowSession::RowOutputDestination.console
|
|
16
|
+
updated = session.with_output_destination(destination)
|
|
17
|
+
|
|
18
|
+
assert_equal source, updated.source
|
|
19
|
+
assert_equal row_range, updated.row_range
|
|
20
|
+
assert_equal destination, updated.output_destination
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../test_helper"
|
|
4
|
+
require "csvtool/domain/row_session/row_source"
|
|
5
|
+
|
|
6
|
+
class RowSourceTest < Minitest::Test
|
|
7
|
+
def test_holds_path_and_separator
|
|
8
|
+
source = Csvtool::Domain::RowSession::RowSource.new(path: "/tmp/a.csv", separator: "\t")
|
|
9
|
+
assert_equal "/tmp/a.csv", source.path
|
|
10
|
+
assert_equal "\t", source.separator
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../test_helper"
|
|
4
|
+
require "csvtool/infrastructure/csv/row_streamer"
|
|
5
|
+
|
|
6
|
+
class InfrastructureRowStreamerTest < Minitest::Test
|
|
7
|
+
def fixture_path(name)
|
|
8
|
+
File.expand_path("../../../fixtures/#{name}", __dir__)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_streams_only_requested_row_range
|
|
12
|
+
streamer = Csvtool::Infrastructure::CSV::RowStreamer.new
|
|
13
|
+
rows = []
|
|
14
|
+
|
|
15
|
+
stats = streamer.each_in_range(
|
|
16
|
+
file_path: fixture_path("sample_people.csv"),
|
|
17
|
+
col_sep: ",",
|
|
18
|
+
start_row: 2,
|
|
19
|
+
end_row: 3
|
|
20
|
+
) { |fields| rows << fields }
|
|
21
|
+
|
|
22
|
+
assert_equal [["Bob", "Paris"], ["Cara", "Berlin"]], rows
|
|
23
|
+
assert_equal true, stats[:matched]
|
|
24
|
+
assert_equal 3, stats[:row_count]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_stops_before_malformed_tail_when_end_row_reached
|
|
28
|
+
streamer = Csvtool::Infrastructure::CSV::RowStreamer.new
|
|
29
|
+
rows = []
|
|
30
|
+
|
|
31
|
+
stats = streamer.each_in_range(
|
|
32
|
+
file_path: fixture_path("sample_people_bad_tail.csv"),
|
|
33
|
+
col_sep: ",",
|
|
34
|
+
start_row: 1,
|
|
35
|
+
end_row: 2
|
|
36
|
+
) { |fields| rows << fields }
|
|
37
|
+
|
|
38
|
+
assert_equal [["Alice", "London"], ["Bob", "Paris"]], rows
|
|
39
|
+
assert_equal true, stats[:matched]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../test_helper"
|
|
4
|
+
require "csvtool/infrastructure/output/csv_row_console_writer"
|
|
5
|
+
|
|
6
|
+
class InfrastructureCsvRowConsoleWriterTest < Minitest::Test
|
|
7
|
+
class FakeRowStreamer
|
|
8
|
+
def each_in_range(file_path:, col_sep:, start_row:, end_row:)
|
|
9
|
+
yield ["Bob", "Paris"]
|
|
10
|
+
yield ["Cara", "Berlin"]
|
|
11
|
+
{ matched: true, row_count: 3 }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_writes_header_and_rows_to_stdout
|
|
16
|
+
out = StringIO.new
|
|
17
|
+
writer = Csvtool::Infrastructure::Output::CsvRowConsoleWriter.new(stdout: out, row_streamer: FakeRowStreamer.new)
|
|
18
|
+
|
|
19
|
+
stats = writer.call(file_path: "x.csv", col_sep: ",", headers: ["name", "city"], start_row: 2, end_row: 3)
|
|
20
|
+
|
|
21
|
+
assert_equal "name,city\nBob,Paris\nCara,Berlin\n", out.string
|
|
22
|
+
assert_equal true, stats[:matched]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../test_helper"
|
|
4
|
+
require "csvtool/infrastructure/output/csv_row_file_writer"
|
|
5
|
+
require "csvtool/interface/cli/errors/presenter"
|
|
6
|
+
require "tmpdir"
|
|
7
|
+
|
|
8
|
+
class InfrastructureCsvRowFileWriterTest < Minitest::Test
|
|
9
|
+
class FakeRowStreamer
|
|
10
|
+
def each_in_range(file_path:, col_sep:, start_row:, end_row:)
|
|
11
|
+
yield ["Bob", "Paris"]
|
|
12
|
+
yield ["Cara", "Berlin"]
|
|
13
|
+
{ matched: true, row_count: 3 }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_writes_header_and_rows_to_file
|
|
18
|
+
stdout = StringIO.new
|
|
19
|
+
writer = Csvtool::Infrastructure::Output::CsvRowFileWriter.new(
|
|
20
|
+
stdout: stdout,
|
|
21
|
+
errors: Csvtool::Interface::CLI::Errors::Presenter.new(stdout: stdout),
|
|
22
|
+
row_streamer: FakeRowStreamer.new
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
Dir.mktmpdir do |dir|
|
|
26
|
+
output_path = File.join(dir, "rows.csv")
|
|
27
|
+
stats = writer.call(
|
|
28
|
+
file_path: "x.csv",
|
|
29
|
+
col_sep: ",",
|
|
30
|
+
headers: ["name", "city"],
|
|
31
|
+
start_row: 2,
|
|
32
|
+
end_row: 3,
|
|
33
|
+
output_path: output_path
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
assert_equal "name,city\nBob,Paris\nCara,Berlin\n", File.read(output_path)
|
|
37
|
+
assert_equal true, stats[:matched]
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -19,6 +19,10 @@ class ErrorsPresenterTest < Minitest::Test
|
|
|
19
19
|
presenter.empty_custom_separator
|
|
20
20
|
presenter.invalid_separator_choice
|
|
21
21
|
presenter.canceled
|
|
22
|
+
presenter.invalid_start_row
|
|
23
|
+
presenter.invalid_end_row
|
|
24
|
+
presenter.invalid_row_range_order
|
|
25
|
+
presenter.row_range_out_of_bounds(3)
|
|
22
26
|
|
|
23
27
|
text = out.string
|
|
24
28
|
assert_includes text, "File not found: /tmp/x.csv"
|
|
@@ -32,5 +36,9 @@ class ErrorsPresenterTest < Minitest::Test
|
|
|
32
36
|
assert_includes text, "Separator cannot be empty."
|
|
33
37
|
assert_includes text, "Invalid separator choice."
|
|
34
38
|
assert_includes text, "Canceled."
|
|
39
|
+
assert_includes text, "Start row must be a positive integer."
|
|
40
|
+
assert_includes text, "End row must be a positive integer."
|
|
41
|
+
assert_includes text, "End row must be greater than or equal to start row."
|
|
42
|
+
assert_includes text, "Row range is out of bounds. File has 3 data rows."
|
|
35
43
|
end
|
|
36
44
|
end
|
|
@@ -16,36 +16,61 @@ class MenuLoopTest < Minitest::Test
|
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
def
|
|
20
|
-
|
|
19
|
+
def test_routes_extract_column_then_exit
|
|
20
|
+
column_action = FakeAction.new
|
|
21
|
+
rows_action = FakeAction.new
|
|
21
22
|
stdout = StringIO.new
|
|
22
23
|
menu = Csvtool::Interface::CLI::MenuLoop.new(
|
|
23
|
-
stdin: StringIO.new("1\
|
|
24
|
+
stdin: StringIO.new("1\n3\n"),
|
|
24
25
|
stdout: stdout,
|
|
25
|
-
menu_options: ["Extract column", "Exit"],
|
|
26
|
-
|
|
26
|
+
menu_options: ["Extract column", "Extract rows (range)", "Exit"],
|
|
27
|
+
extract_column_action: column_action,
|
|
28
|
+
extract_rows_action: rows_action
|
|
27
29
|
)
|
|
28
30
|
|
|
29
31
|
status = menu.run
|
|
30
32
|
|
|
31
33
|
assert_equal 0, status
|
|
32
|
-
assert_equal 1,
|
|
34
|
+
assert_equal 1, column_action.runs
|
|
35
|
+
assert_equal 0, rows_action.runs
|
|
33
36
|
assert_includes stdout.string, "CSV Tool Menu"
|
|
34
37
|
end
|
|
35
38
|
|
|
39
|
+
def test_routes_extract_rows_then_exit
|
|
40
|
+
column_action = FakeAction.new
|
|
41
|
+
rows_action = FakeAction.new
|
|
42
|
+
stdout = StringIO.new
|
|
43
|
+
menu = Csvtool::Interface::CLI::MenuLoop.new(
|
|
44
|
+
stdin: StringIO.new("2\n3\n"),
|
|
45
|
+
stdout: stdout,
|
|
46
|
+
menu_options: ["Extract column", "Extract rows (range)", "Exit"],
|
|
47
|
+
extract_column_action: column_action,
|
|
48
|
+
extract_rows_action: rows_action
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
status = menu.run
|
|
52
|
+
|
|
53
|
+
assert_equal 0, status
|
|
54
|
+
assert_equal 0, column_action.runs
|
|
55
|
+
assert_equal 1, rows_action.runs
|
|
56
|
+
end
|
|
57
|
+
|
|
36
58
|
def test_invalid_choice_shows_prompt
|
|
37
|
-
|
|
59
|
+
column_action = FakeAction.new
|
|
60
|
+
rows_action = FakeAction.new
|
|
38
61
|
stdout = StringIO.new
|
|
39
62
|
menu = Csvtool::Interface::CLI::MenuLoop.new(
|
|
40
|
-
stdin: StringIO.new("x\
|
|
63
|
+
stdin: StringIO.new("x\n3\n"),
|
|
41
64
|
stdout: stdout,
|
|
42
|
-
menu_options: ["Extract column", "Exit"],
|
|
43
|
-
|
|
65
|
+
menu_options: ["Extract column", "Extract rows (range)", "Exit"],
|
|
66
|
+
extract_column_action: column_action,
|
|
67
|
+
extract_rows_action: rows_action
|
|
44
68
|
)
|
|
45
69
|
|
|
46
70
|
menu.run
|
|
47
71
|
|
|
48
|
-
assert_includes stdout.string, "Please choose 1 or
|
|
49
|
-
assert_equal 0,
|
|
72
|
+
assert_includes stdout.string, "Please choose 1, 2, or 3."
|
|
73
|
+
assert_equal 0, column_action.runs
|
|
74
|
+
assert_equal 0, rows_action.runs
|
|
50
75
|
end
|
|
51
76
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: csvops
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0.alpha
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robert Hall
|
|
@@ -68,21 +68,30 @@ files:
|
|
|
68
68
|
- bin/tool
|
|
69
69
|
- csvops.gemspec
|
|
70
70
|
- docs/release-v0.1.0-alpha.md
|
|
71
|
+
- docs/release-v0.2.0-alpha.md
|
|
71
72
|
- exe/csvtool
|
|
72
73
|
- lib/csvtool/application/use_cases/run_extraction.rb
|
|
74
|
+
- lib/csvtool/application/use_cases/run_row_extraction.rb
|
|
73
75
|
- lib/csvtool/cli.rb
|
|
74
|
-
- lib/csvtool/domain/
|
|
75
|
-
- lib/csvtool/domain/
|
|
76
|
-
- lib/csvtool/domain/
|
|
77
|
-
- lib/csvtool/domain/
|
|
78
|
-
- lib/csvtool/domain/
|
|
79
|
-
- lib/csvtool/domain/
|
|
80
|
-
- lib/csvtool/domain/
|
|
81
|
-
- lib/csvtool/domain/
|
|
76
|
+
- lib/csvtool/domain/column_session/column_selection.rb
|
|
77
|
+
- lib/csvtool/domain/column_session/column_session.rb
|
|
78
|
+
- lib/csvtool/domain/column_session/csv_source.rb
|
|
79
|
+
- lib/csvtool/domain/column_session/extraction_options.rb
|
|
80
|
+
- lib/csvtool/domain/column_session/extraction_value.rb
|
|
81
|
+
- lib/csvtool/domain/column_session/output_destination.rb
|
|
82
|
+
- lib/csvtool/domain/column_session/preview.rb
|
|
83
|
+
- lib/csvtool/domain/column_session/separator.rb
|
|
84
|
+
- lib/csvtool/domain/row_session/row_output_destination.rb
|
|
85
|
+
- lib/csvtool/domain/row_session/row_range.rb
|
|
86
|
+
- lib/csvtool/domain/row_session/row_session.rb
|
|
87
|
+
- lib/csvtool/domain/row_session/row_source.rb
|
|
82
88
|
- lib/csvtool/infrastructure/csv/header_reader.rb
|
|
89
|
+
- lib/csvtool/infrastructure/csv/row_streamer.rb
|
|
83
90
|
- lib/csvtool/infrastructure/csv/value_streamer.rb
|
|
84
91
|
- lib/csvtool/infrastructure/output/console_writer.rb
|
|
85
92
|
- lib/csvtool/infrastructure/output/csv_file_writer.rb
|
|
93
|
+
- lib/csvtool/infrastructure/output/csv_row_console_writer.rb
|
|
94
|
+
- lib/csvtool/infrastructure/output/csv_row_file_writer.rb
|
|
86
95
|
- lib/csvtool/interface/cli/errors/presenter.rb
|
|
87
96
|
- lib/csvtool/interface/cli/menu_loop.rb
|
|
88
97
|
- lib/csvtool/interface/cli/prompts/column_selector_prompt.rb
|
|
@@ -94,20 +103,28 @@ files:
|
|
|
94
103
|
- lib/csvtool/services/preview_builder.rb
|
|
95
104
|
- lib/csvtool/version.rb
|
|
96
105
|
- test/csvtool/application/use_cases/run_extraction_test.rb
|
|
106
|
+
- test/csvtool/application/use_cases/run_row_extraction_test.rb
|
|
97
107
|
- test/csvtool/cli_test.rb
|
|
98
108
|
- test/csvtool/cli_unit_test.rb
|
|
99
|
-
- test/csvtool/domain/
|
|
100
|
-
- test/csvtool/domain/
|
|
101
|
-
- test/csvtool/domain/
|
|
102
|
-
- test/csvtool/domain/
|
|
103
|
-
- test/csvtool/domain/
|
|
104
|
-
- test/csvtool/domain/
|
|
105
|
-
- test/csvtool/domain/
|
|
106
|
-
- test/csvtool/domain/
|
|
109
|
+
- test/csvtool/domain/column_session/column_selection_test.rb
|
|
110
|
+
- test/csvtool/domain/column_session/column_session_test.rb
|
|
111
|
+
- test/csvtool/domain/column_session/csv_source_test.rb
|
|
112
|
+
- test/csvtool/domain/column_session/extraction_options_test.rb
|
|
113
|
+
- test/csvtool/domain/column_session/extraction_value_test.rb
|
|
114
|
+
- test/csvtool/domain/column_session/output_destination_test.rb
|
|
115
|
+
- test/csvtool/domain/column_session/preview_test.rb
|
|
116
|
+
- test/csvtool/domain/column_session/separator_test.rb
|
|
117
|
+
- test/csvtool/domain/row_session/row_output_destination_test.rb
|
|
118
|
+
- test/csvtool/domain/row_session/row_range_test.rb
|
|
119
|
+
- test/csvtool/domain/row_session/row_session_test.rb
|
|
120
|
+
- test/csvtool/domain/row_session/row_source_test.rb
|
|
107
121
|
- test/csvtool/infrastructure/csv/header_reader_test.rb
|
|
122
|
+
- test/csvtool/infrastructure/csv/row_streamer_test.rb
|
|
108
123
|
- test/csvtool/infrastructure/csv/value_streamer_test.rb
|
|
109
124
|
- test/csvtool/infrastructure/output/console_writer_test.rb
|
|
110
125
|
- test/csvtool/infrastructure/output/csv_file_writer_test.rb
|
|
126
|
+
- test/csvtool/infrastructure/output/csv_row_console_writer_test.rb
|
|
127
|
+
- test/csvtool/infrastructure/output/csv_row_file_writer_test.rb
|
|
111
128
|
- test/csvtool/interface/cli/errors/presenter_test.rb
|
|
112
129
|
- test/csvtool/interface/cli/menu_loop_test.rb
|
|
113
130
|
- test/csvtool/interface/cli/prompts/column_selector_prompt_test.rb
|
|
@@ -120,6 +137,7 @@ files:
|
|
|
120
137
|
- test/fixtures/empty.csv
|
|
121
138
|
- test/fixtures/sample_people.csv
|
|
122
139
|
- test/fixtures/sample_people.tsv
|
|
140
|
+
- test/fixtures/sample_people_bad_tail.csv
|
|
123
141
|
- test/fixtures/sample_people_blanks.csv
|
|
124
142
|
- test/fixtures/sample_people_colon.txt
|
|
125
143
|
- test/fixtures/sample_people_many.csv
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../../../test_helper"
|
|
4
|
-
require "csvtool/domain/extraction_session/csv_source"
|
|
5
|
-
require "csvtool/domain/extraction_session/separator"
|
|
6
|
-
|
|
7
|
-
class CsvSourceTest < Minitest::Test
|
|
8
|
-
def test_stores_path_and_separator
|
|
9
|
-
separator = Csvtool::Domain::ExtractionSession::Separator.new(",")
|
|
10
|
-
source = Csvtool::Domain::ExtractionSession::CsvSource.new(path: "/tmp/a.csv", separator: separator)
|
|
11
|
-
assert_equal "/tmp/a.csv", source.path
|
|
12
|
-
assert_equal separator, source.separator
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../../../test_helper"
|
|
4
|
-
require "csvtool/domain/extraction_session/extraction_session"
|
|
5
|
-
require "csvtool/domain/extraction_session/csv_source"
|
|
6
|
-
require "csvtool/domain/extraction_session/separator"
|
|
7
|
-
require "csvtool/domain/extraction_session/column_selection"
|
|
8
|
-
require "csvtool/domain/extraction_session/extraction_options"
|
|
9
|
-
require "csvtool/domain/extraction_session/preview"
|
|
10
|
-
require "csvtool/domain/extraction_session/extraction_value"
|
|
11
|
-
require "csvtool/domain/extraction_session/output_destination"
|
|
12
|
-
|
|
13
|
-
class ExtractionSessionTest < Minitest::Test
|
|
14
|
-
def test_state_transitions
|
|
15
|
-
session = Csvtool::Domain::ExtractionSession::ExtractionSession.start(
|
|
16
|
-
source: Csvtool::Domain::ExtractionSession::CsvSource.new(
|
|
17
|
-
path: "/tmp/in.csv",
|
|
18
|
-
separator: Csvtool::Domain::ExtractionSession::Separator.new(",")
|
|
19
|
-
),
|
|
20
|
-
column_selection: Csvtool::Domain::ExtractionSession::ColumnSelection.new(name: "name"),
|
|
21
|
-
options: Csvtool::Domain::ExtractionSession::ExtractionOptions.new(skip_blanks: true, preview_limit: 10)
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
preview = Csvtool::Domain::ExtractionSession::Preview.new(
|
|
25
|
-
values: [Csvtool::Domain::ExtractionSession::ExtractionValue.new("Alice")]
|
|
26
|
-
)
|
|
27
|
-
session = session.with_preview(preview).confirm!.with_output_destination(
|
|
28
|
-
Csvtool::Domain::ExtractionSession::OutputDestination.console
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
assert_equal true, session.confirmed?
|
|
32
|
-
assert_equal preview, session.preview
|
|
33
|
-
assert_equal true, session.output_destination.console?
|
|
34
|
-
end
|
|
35
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../../../test_helper"
|
|
4
|
-
require "csvtool/domain/extraction_session/preview"
|
|
5
|
-
require "csvtool/domain/extraction_session/extraction_value"
|
|
6
|
-
|
|
7
|
-
class PreviewTest < Minitest::Test
|
|
8
|
-
def test_exposes_size_and_string_values
|
|
9
|
-
values = [
|
|
10
|
-
Csvtool::Domain::ExtractionSession::ExtractionValue.new("Alice"),
|
|
11
|
-
Csvtool::Domain::ExtractionSession::ExtractionValue.new("Bob")
|
|
12
|
-
]
|
|
13
|
-
preview = Csvtool::Domain::ExtractionSession::Preview.new(values: values)
|
|
14
|
-
|
|
15
|
-
assert_equal 2, preview.size
|
|
16
|
-
assert_equal %w[Alice Bob], preview.to_strings
|
|
17
|
-
end
|
|
18
|
-
end
|