tty 0.0.11 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +16 -7
- data/CHANGELOG.md +6 -0
- data/Gemfile +18 -1
- data/README.md +55 -28
- data/Rakefile +5 -9
- data/images/tty.png +0 -0
- data/lib/tty.rb +7 -1
- data/lib/tty/coercer/boolean.rb +6 -9
- data/lib/tty/coercer/float.rb +14 -17
- data/lib/tty/coercer/integer.rb +14 -17
- data/lib/tty/coercer/range.rb +6 -7
- data/lib/tty/logger.rb +23 -9
- data/lib/tty/plugins.rb +3 -6
- data/lib/tty/plugins/plugin.rb +4 -7
- data/lib/tty/shell.rb +20 -12
- data/lib/tty/shell/question.rb +41 -48
- data/lib/tty/shell/question/modifier.rb +5 -8
- data/lib/tty/shell/question/validation.rb +8 -7
- data/lib/tty/shell/reader.rb +28 -19
- data/lib/tty/shell/response.rb +26 -22
- data/lib/tty/shell/statement.rb +13 -9
- data/lib/tty/shell/suggestion.rb +17 -13
- data/lib/tty/support/coercion.rb +5 -6
- data/lib/tty/support/conversion.rb +7 -6
- data/lib/tty/support/delegatable.rb +5 -5
- data/lib/tty/support/unicode.rb +3 -4
- data/lib/tty/support/utils.rb +1 -2
- data/lib/tty/system.rb +13 -6
- data/lib/tty/system/editor.rb +21 -18
- data/lib/tty/system/which.rb +3 -5
- data/lib/tty/table.rb +18 -22
- data/lib/tty/table/border.rb +2 -4
- data/lib/tty/table/border/ascii.rb +3 -2
- data/lib/tty/table/border/null.rb +1 -3
- data/lib/tty/table/border/row_line.rb +1 -4
- data/lib/tty/table/border/unicode.rb +3 -2
- data/lib/tty/table/border_dsl.rb +21 -17
- data/lib/tty/table/border_options.rb +6 -5
- data/lib/tty/table/column_set.rb +11 -7
- data/lib/tty/table/columns.rb +19 -16
- data/lib/tty/table/error.rb +1 -3
- data/lib/tty/table/field.rb +30 -12
- data/lib/tty/table/header.rb +18 -9
- data/lib/tty/table/indentation.rb +1 -3
- data/lib/tty/table/operation/alignment.rb +8 -9
- data/lib/tty/table/operation/alignment_set.rb +6 -5
- data/lib/tty/table/operation/escape.rb +3 -3
- data/lib/tty/table/operation/filter.rb +3 -4
- data/lib/tty/table/operation/truncation.rb +3 -3
- data/lib/tty/table/operation/wrapped.rb +3 -4
- data/lib/tty/table/operations.rb +19 -22
- data/lib/tty/table/orientation.rb +5 -5
- data/lib/tty/table/orientation/horizontal.rb +9 -6
- data/lib/tty/table/orientation/vertical.rb +10 -7
- data/lib/tty/table/padder.rb +46 -8
- data/lib/tty/table/renderer.rb +21 -14
- data/lib/tty/table/renderer/ascii.rb +6 -5
- data/lib/tty/table/renderer/basic.rb +18 -19
- data/lib/tty/table/renderer/unicode.rb +11 -5
- data/lib/tty/table/row.rb +36 -20
- data/lib/tty/table/transformation.rb +6 -5
- data/lib/tty/table/validatable.rb +32 -17
- data/lib/tty/terminal.rb +26 -42
- data/lib/tty/terminal/color.rb +10 -12
- data/lib/tty/terminal/echo.rb +4 -7
- data/lib/tty/terminal/home.rb +3 -10
- data/lib/tty/terminal/pager.rb +11 -10
- data/lib/tty/terminal/pager/basic.rb +3 -6
- data/lib/tty/terminal/pager/system.rb +2 -5
- data/lib/tty/text.rb +7 -10
- data/lib/tty/text/distance.rb +2 -4
- data/lib/tty/text/truncation.rb +1 -3
- data/lib/tty/text/wrapping.rb +1 -3
- data/lib/tty/vector.rb +3 -5
- data/lib/tty/version.rb +2 -2
- data/spec/spec_helper.rb +4 -11
- data/spec/tty/coercer/boolean/coerce_spec.rb +19 -16
- data/spec/tty/coercer/float/coerce_spec.rb +6 -4
- data/spec/tty/coercer/integer/coerce_spec.rb +5 -4
- data/spec/tty/coercer/range/coerce_spec.rb +12 -11
- data/spec/tty/logger/log_spec.rb +23 -0
- data/spec/tty/logger/new_spec.rb +14 -14
- data/spec/tty/logger/valid_level_spec.rb +6 -6
- data/spec/tty/plugins/find_spec.rb +4 -4
- data/spec/tty/plugins/load_spec.rb +4 -5
- data/spec/tty/plugins/plugin/load_spec.rb +10 -8
- data/spec/tty/plugins/plugin/new_spec.rb +7 -7
- data/spec/tty/shell/ask_spec.rb +6 -7
- data/spec/tty/shell/error_spec.rb +1 -2
- data/spec/tty/shell/print_table_spec.rb +1 -2
- data/spec/tty/shell/question/argument_spec.rb +1 -1
- data/spec/tty/shell/question/character_spec.rb +11 -3
- data/spec/tty/shell/question/default_spec.rb +3 -3
- data/spec/tty/shell/question/in_spec.rb +1 -1
- data/spec/tty/shell/question/initialize_spec.rb +8 -11
- data/spec/tty/shell/question/modifier/apply_to_spec.rb +8 -4
- data/spec/tty/shell/question/modifier/letter_case_spec.rb +4 -4
- data/spec/tty/shell/question/modifier/whitespace_spec.rb +5 -5
- data/spec/tty/shell/question/modify_spec.rb +1 -1
- data/spec/tty/shell/question/valid_spec.rb +4 -4
- data/spec/tty/shell/question/validate_spec.rb +4 -4
- data/spec/tty/shell/question/validation/coerce_spec.rb +2 -3
- data/spec/tty/shell/question/validation/valid_value_spec.rb +3 -3
- data/spec/tty/shell/reader/getc_spec.rb +16 -14
- data/spec/tty/shell/response/read_bool_spec.rb +1 -1
- data/spec/tty/shell/response/read_char_spec.rb +1 -2
- data/spec/tty/shell/response/read_date_spec.rb +1 -1
- data/spec/tty/shell/response/read_email_spec.rb +1 -1
- data/spec/tty/shell/response/read_multiple_spec.rb +3 -4
- data/spec/tty/shell/response/read_number_spec.rb +1 -2
- data/spec/tty/shell/response/read_range_spec.rb +2 -2
- data/spec/tty/shell/response/read_spec.rb +7 -7
- data/spec/tty/shell/response/read_string_spec.rb +2 -2
- data/spec/tty/shell/say_spec.rb +1 -1
- data/spec/tty/shell/statement/initialize_spec.rb +3 -3
- data/spec/tty/shell/suggest_spec.rb +1 -1
- data/spec/tty/shell/warn_spec.rb +1 -2
- data/spec/tty/support/coercion_spec.rb +10 -10
- data/spec/tty/support/conversion_spec.rb +9 -9
- data/spec/tty/support/delegatable_spec.rb +7 -5
- data/spec/tty/support/equatable_spec.rb +32 -34
- data/spec/tty/support/fixtures/classes.rb +4 -2
- data/spec/tty/system/editor/available_spec.rb +12 -12
- data/spec/tty/system/editor/build_spec.rb +8 -16
- data/spec/tty/system/editor/command_spec.rb +3 -2
- data/spec/tty/system/editor/executables_spec.rb +3 -3
- data/spec/tty/system/editor/invoke_spec.rb +10 -14
- data/spec/tty/system/editor/open_spec.rb +9 -7
- data/spec/tty/system/platform_spec.rb +32 -13
- data/spec/tty/system/which/which_spec.rb +9 -9
- data/spec/tty/system/which_spec.rb +4 -4
- data/spec/tty/table/access_spec.rb +24 -21
- data/spec/tty/table/add_row_spec.rb +2 -2
- data/spec/tty/table/border/ascii/rendering_spec.rb +13 -13
- data/spec/tty/table/border/new_spec.rb +5 -4
- data/spec/tty/table/border/null/rendering_spec.rb +12 -12
- data/spec/tty/table/border/options/from_spec.rb +2 -3
- data/spec/tty/table/border/options/new_spec.rb +4 -5
- data/spec/tty/table/border/unicode/rendering_spec.rb +10 -10
- data/spec/tty/table/border_options/new_spec.rb +20 -0
- data/spec/tty/table/border_options/update_spec.rb +18 -0
- data/spec/tty/table/column_set/extract_widths_spec.rb +1 -1
- data/spec/tty/table/column_set/total_width_spec.rb +2 -2
- data/spec/tty/table/column_set/widths_from_spec.rb +1 -2
- data/spec/tty/table/columns/enforce_spec.rb +2 -2
- data/spec/tty/table/columns/widths_spec.rb +2 -0
- data/spec/tty/table/data_spec.rb +3 -3
- data/spec/tty/table/each_spec.rb +9 -11
- data/spec/tty/table/each_with_index_spec.rb +8 -9
- data/spec/tty/table/empty_spec.rb +3 -3
- data/spec/tty/table/eql_spec.rb +6 -6
- data/spec/tty/table/field/equality_spec.rb +11 -11
- data/spec/tty/table/field/length_spec.rb +4 -4
- data/spec/tty/table/field/lines_spec.rb +3 -3
- data/spec/tty/table/field/new_spec.rb +7 -7
- data/spec/tty/table/field/width_spec.rb +6 -4
- data/spec/tty/table/filter_spec.rb +3 -3
- data/spec/tty/table/header/call_spec.rb +3 -3
- data/spec/tty/table/header/height_spec.rb +1 -1
- data/spec/tty/table/header/new_spec.rb +5 -5
- data/spec/tty/table/header/set_spec.rb +9 -4
- data/spec/tty/table/header/to_ary_spec.rb +4 -4
- data/spec/tty/table/header_spec.rb +3 -4
- data/spec/tty/table/indentation/insert_indent_spec.rb +1 -1
- data/spec/tty/table/initialize_spec.rb +13 -13
- data/spec/tty/table/operation/alignment/format_spec.rb +5 -5
- data/spec/tty/table/operation/alignment/new_spec.rb +4 -4
- data/spec/tty/table/operation/alignment_set/call_spec.rb +11 -11
- data/spec/tty/table/operation/alignment_set/each_spec.rb +3 -3
- data/spec/tty/table/operation/alignment_set/new_spec.rb +6 -6
- data/spec/tty/table/operation/alignment_set/to_ary_spec.rb +4 -4
- data/spec/tty/table/operation/escape/call_spec.rb +1 -1
- data/spec/tty/table/operation/filter/call_spec.rb +1 -1
- data/spec/tty/table/operation/truncation/call_spec.rb +1 -1
- data/spec/tty/table/operation/truncation/truncate_spec.rb +4 -4
- data/spec/tty/table/operation/wrapped/call_spec.rb +1 -1
- data/spec/tty/table/operation/wrapped/wrap_spec.rb +3 -3
- data/spec/tty/table/operations/new_spec.rb +1 -1
- data/spec/tty/table/options_spec.rb +8 -8
- data/spec/tty/table/orientation_spec.rb +15 -13
- data/spec/tty/table/padder/parse_spec.rb +1 -1
- data/spec/tty/table/padder/to_s_spec.rb +14 -0
- data/spec/tty/table/padding_spec.rb +1 -1
- data/spec/tty/table/properties_spec.rb +9 -8
- data/spec/tty/table/render_spec.rb +8 -5
- data/spec/tty/table/render_with_spec.rb +5 -4
- data/spec/tty/table/renderer/ascii/indentation_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/render_spec.rb +7 -7
- data/spec/tty/table/renderer/ascii/resizing_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/separator_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/alignment_spec.rb +5 -5
- data/spec/tty/table/renderer/basic/coloring_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/extract_column_widths_spec.rb +6 -6
- data/spec/tty/table/renderer/basic/filter_spec.rb +4 -4
- data/spec/tty/table/renderer/basic/indentation_spec.rb +5 -3
- data/spec/tty/table/renderer/basic/multiline_content_spec.rb +10 -10
- data/spec/tty/table/renderer/basic/new_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/options_spec.rb +9 -9
- data/spec/tty/table/renderer/basic/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/render_spec.rb +8 -8
- data/spec/tty/table/renderer/basic/resizing_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/separator_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/truncation_spec.rb +4 -4
- data/spec/tty/table/renderer/basic/wrapping_spec.rb +4 -4
- data/spec/tty/table/renderer/border_spec.rb +21 -21
- data/spec/tty/table/renderer/render_spec.rb +7 -7
- data/spec/tty/table/renderer/select_spec.rb +4 -4
- data/spec/tty/table/renderer/style_spec.rb +19 -19
- data/spec/tty/table/renderer/unicode/indentation_spec.rb +1 -1
- data/spec/tty/table/renderer/unicode/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/unicode/render_spec.rb +6 -6
- data/spec/tty/table/renderer/unicode/separator_spec.rb +2 -2
- data/spec/tty/table/renderer_spec.rb +1 -1
- data/spec/tty/table/rotate_spec.rb +27 -27
- data/spec/tty/table/row/access_spec.rb +3 -3
- data/spec/tty/table/row/call_spec.rb +4 -4
- data/spec/tty/table/row/data_spec.rb +5 -5
- data/spec/tty/table/row/each_spec.rb +1 -1
- data/spec/tty/table/row/equality_spec.rb +16 -16
- data/spec/tty/table/row/height_spec.rb +1 -1
- data/spec/tty/table/row/new_spec.rb +11 -11
- data/spec/tty/table/row/to_ary_spec.rb +3 -3
- data/spec/tty/table/to_s_spec.rb +8 -8
- data/spec/tty/table/validatable/validate_options_spec.rb +5 -5
- data/spec/tty/table/validatable_spec.rb +14 -1
- data/spec/tty/terminal/color/code_spec.rb +3 -3
- data/spec/tty/terminal/color/remove_spec.rb +8 -9
- data/spec/tty/terminal/color/set_spec.rb +5 -6
- data/spec/tty/terminal/color_spec.rb +3 -5
- data/spec/tty/terminal/echo_spec.rb +3 -4
- data/spec/tty/terminal/home_spec.rb +12 -14
- data/spec/tty/terminal/page_spec.rb +5 -4
- data/spec/tty/terminal/pager/available_spec.rb +11 -11
- data/spec/tty/terminal/pager/basic/page_spec.rb +8 -8
- data/spec/tty/terminal/pager/command_spec.rb +2 -2
- data/spec/tty/terminal/pager/executables_spec.rb +3 -3
- data/spec/tty/terminal/pager/page_spec.rb +8 -10
- data/spec/tty/terminal/pager/system/page_spec.rb +8 -8
- data/spec/tty/terminal/size_spec.rb +39 -36
- data/spec/tty/text/distance/distance_spec.rb +13 -13
- data/spec/tty/text/distance/initialize_spec.rb +4 -4
- data/spec/tty/text/distance_spec.rb +2 -2
- data/spec/tty/text/truncate_spec.rb +2 -3
- data/spec/tty/text/truncation/initialize_spec.rb +9 -9
- data/spec/tty/text/truncation/truncate_spec.rb +14 -14
- data/spec/tty/text/wrap_spec.rb +2 -3
- data/spec/tty/text/wrapping/initialize_spec.rb +7 -7
- data/spec/tty/text/wrapping/wrap_spec.rb +11 -11
- data/spec/tty/tty_spec.rb +22 -0
- data/spec/tty/vector/new_spec.rb +7 -7
- data/tasks/console.rake +10 -0
- data/tasks/coverage.rake +11 -0
- data/tasks/metrics/cane.rake +2 -0
- data/tasks/metrics/flog.rake +2 -0
- data/tasks/metrics/heckle.rake +15 -0
- data/tasks/metrics/reek.rake +2 -0
- data/tasks/spec.rake +29 -0
- data/tty.gemspec +5 -12
- metadata +34 -91
- data/.rvmrc +0 -34
@@ -6,89 +6,92 @@ describe TTY::Terminal, '#size' do
|
|
6
6
|
let(:default_width) { 80 }
|
7
7
|
let(:default_height) { 24 }
|
8
8
|
|
9
|
-
it {
|
9
|
+
it { is_expected.to be_instance_of(described_class) }
|
10
10
|
|
11
|
-
it {
|
11
|
+
it { is_expected.to respond_to(:width) }
|
12
12
|
|
13
|
-
it {
|
13
|
+
it { is_expected.to respond_to(:height) }
|
14
14
|
|
15
|
-
its(:default_width) { should == default_width }
|
16
15
|
|
17
|
-
|
16
|
+
subject(:terminal) { described_class.new }
|
17
|
+
|
18
|
+
it { expect(terminal.default_width).to eq(default_width) }
|
19
|
+
|
20
|
+
it { expect(subject.default_height).to eq(default_height) }
|
18
21
|
|
19
22
|
context '#width' do
|
20
|
-
it '
|
21
|
-
ENV.
|
22
|
-
subject.width.
|
23
|
+
it 'reads the env variable' do
|
24
|
+
allow(ENV).to receive(:[]).with('TTY_COLUMNS').and_return('100')
|
25
|
+
expect(subject.width).to eq(100)
|
23
26
|
end
|
24
27
|
|
25
28
|
it 'is not unix system' do
|
26
|
-
TTY::System.
|
27
|
-
subject.
|
29
|
+
allow(TTY::System).to receive(:unix?) { false }
|
30
|
+
expect(subject).to receive(:default_width)
|
28
31
|
subject.width
|
29
32
|
end
|
30
33
|
|
31
34
|
it 'is unix system' do
|
32
|
-
TTY::System.
|
33
|
-
subject.
|
34
|
-
subject.width
|
35
|
+
allow(TTY::System).to receive(:unix?) { true }
|
36
|
+
expect(subject).to receive(:dynamic_width) { default_width }
|
37
|
+
expect(subject.width).to eq(80)
|
35
38
|
end
|
36
39
|
|
37
40
|
it 'cannot determine width' do
|
38
|
-
ENV.
|
39
|
-
|
40
|
-
|
41
|
+
allow(ENV).to receive(:[]) { raise }
|
42
|
+
expect(terminal).to receive(:default_width) { default_width }
|
43
|
+
expect(terminal.width).to eq(default_width)
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
44
47
|
context '#height' do
|
45
48
|
it 'sets the env variable' do
|
46
|
-
ENV.
|
47
|
-
subject.height.
|
49
|
+
allow(ENV).to receive(:[]).with('TTY_LINES').and_return('50')
|
50
|
+
expect(subject.height).to eq(50)
|
48
51
|
end
|
49
52
|
|
50
53
|
it 'is not unix system' do
|
51
|
-
TTY::System.
|
52
|
-
subject.
|
53
|
-
subject.height
|
54
|
+
allow(TTY::System).to receive(:unix?) { false }
|
55
|
+
expect(subject).to receive(:default_height) { default_height }
|
56
|
+
expect(subject.height).to eq(default_height)
|
54
57
|
end
|
55
58
|
|
56
59
|
it 'is unix system' do
|
57
|
-
TTY::System.
|
58
|
-
subject.
|
59
|
-
subject.height
|
60
|
+
allow(TTY::System).to receive(:unix?) { true }
|
61
|
+
expect(subject).to receive(:dynamic_height) { default_height }
|
62
|
+
expect(subject.height).to eq(default_height)
|
60
63
|
end
|
61
64
|
|
62
65
|
it 'cannot determine width' do
|
63
|
-
ENV.
|
64
|
-
subject.
|
66
|
+
allow(ENV).to receive(:[]) { raise }
|
67
|
+
expect(subject).to receive(:default_height)
|
65
68
|
subject.height
|
66
69
|
end
|
67
70
|
end
|
68
71
|
|
69
72
|
context '#dynamic_width' do
|
70
73
|
it 'uses stty' do
|
71
|
-
subject.
|
72
|
-
subject.dynamic_width
|
74
|
+
expect(subject).to receive(:dynamic_width_stty) { 100 }
|
75
|
+
expect(subject.dynamic_width).to eq(100)
|
73
76
|
end
|
74
77
|
|
75
78
|
it 'uses tput' do
|
76
|
-
subject.
|
77
|
-
subject.
|
78
|
-
subject.dynamic_width
|
79
|
+
allow(subject).to receive(:dynamic_width_stty).and_return(0)
|
80
|
+
expect(subject).to receive(:dynamic_width_tput) { 100 }
|
81
|
+
expect(subject.dynamic_width).to eq(100)
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
82
85
|
context '#dynamic_height' do
|
83
86
|
it 'uses stty' do
|
84
|
-
subject.
|
85
|
-
subject.dynamic_height
|
87
|
+
allow(subject).to receive(:dynamic_height_stty) { 100 }
|
88
|
+
expect(subject.dynamic_height).to eq(100)
|
86
89
|
end
|
87
90
|
|
88
91
|
it 'uses tput' do
|
89
|
-
subject.
|
90
|
-
subject.
|
91
|
-
subject.dynamic_height
|
92
|
+
allow(subject).to receive(:dynamic_height_stty).and_return(0)
|
93
|
+
expect(subject).to receive(:dynamic_height_tput) { 100 }
|
94
|
+
expect(subject.dynamic_height).to eq(100)
|
92
95
|
end
|
93
96
|
end
|
94
97
|
end
|
@@ -1,75 +1,75 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Text::Distance, '#distance' do
|
6
6
|
let(:object) { described_class.new(*strings) }
|
7
7
|
|
8
|
-
subject { object.distance }
|
8
|
+
subject(:distance) { object.distance }
|
9
9
|
|
10
10
|
context 'when nil' do
|
11
11
|
let(:strings) { [nil, nil] }
|
12
12
|
|
13
|
-
it {
|
13
|
+
it { is_expected.to eql(0) }
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'when empty' do
|
17
17
|
let(:strings) { ['', ''] }
|
18
18
|
|
19
|
-
it {
|
19
|
+
it { is_expected.to eql(0) }
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'with one non empty' do
|
23
23
|
let(:strings) { ['abc', ''] }
|
24
24
|
|
25
|
-
it {
|
25
|
+
it { is_expected.to eql(3) }
|
26
26
|
end
|
27
27
|
|
28
28
|
context 'when single char' do
|
29
29
|
let(:strings) { ['a', 'abc'] }
|
30
30
|
|
31
|
-
it {
|
31
|
+
it { is_expected.to eql(2) }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'when similar' do
|
35
35
|
let(:strings) { ['abc', 'abc'] }
|
36
36
|
|
37
|
-
it {
|
37
|
+
it { is_expected.to eql(0) }
|
38
38
|
end
|
39
39
|
|
40
40
|
context 'when similar' do
|
41
41
|
let(:strings) { ['abc', 'acb'] }
|
42
42
|
|
43
|
-
it {
|
43
|
+
it { is_expected.to eql(1) }
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'when end similar' do
|
47
47
|
let(:strings) { ['saturday', 'sunday'] }
|
48
48
|
|
49
|
-
it {
|
49
|
+
it { is_expected.to eql(3) }
|
50
50
|
end
|
51
51
|
|
52
52
|
context 'when contain similar' do
|
53
53
|
let(:strings) { ['which', 'witch'] }
|
54
54
|
|
55
|
-
it {
|
55
|
+
it { is_expected.to eql(2) }
|
56
56
|
end
|
57
57
|
|
58
58
|
context 'when prefix' do
|
59
59
|
let(:strings) { ['sta', 'status'] }
|
60
60
|
|
61
|
-
it {
|
61
|
+
it { is_expected.to eql(3) }
|
62
62
|
end
|
63
63
|
|
64
64
|
context 'when similar' do
|
65
65
|
let(:strings) { ['smellyfish','jellyfish'] }
|
66
66
|
|
67
|
-
it {
|
67
|
+
it { is_expected.to eql(2) }
|
68
68
|
end
|
69
69
|
|
70
70
|
context 'when unicode' do
|
71
71
|
let(:strings) { ['マラソン五輪代表', 'ララソン五輪代表'] }
|
72
72
|
|
73
|
-
it {
|
73
|
+
it { is_expected.to eql(1) }
|
74
74
|
end
|
75
75
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Text::Distance, '#initialize' do
|
6
6
|
let(:strings) { ['abc', 'acb'] }
|
7
7
|
|
8
|
-
subject { described_class.new(*strings) }
|
8
|
+
subject(:distance) { described_class.new(*strings) }
|
9
9
|
|
10
|
-
|
10
|
+
it { expect(distance.first).to eq(strings.first) }
|
11
11
|
|
12
|
-
|
12
|
+
it { expect(distance.second).to eq(strings.last) }
|
13
13
|
|
14
14
|
end # initialize
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -8,6 +8,5 @@ describe TTY::Text, '#truncate' do
|
|
8
8
|
|
9
9
|
subject { described_class.truncate(text, :length => length) }
|
10
10
|
|
11
|
-
it {
|
12
|
-
|
11
|
+
it { is_expected.to eq("ラドクリフ、マラソン五…") }
|
13
12
|
end # truncate
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -9,21 +9,21 @@ describe TTY::Text::Truncation, '#initialize' do
|
|
9
9
|
|
10
10
|
subject { described_class.new text, *args }
|
11
11
|
|
12
|
-
|
12
|
+
it { expect(subject.text).to eq(text) }
|
13
13
|
|
14
|
-
|
14
|
+
it { expect(subject.length).to eq(30) }
|
15
15
|
|
16
|
-
|
16
|
+
it { expect(subject.separator).to be_nil }
|
17
17
|
|
18
|
-
|
18
|
+
it { expect(subject.trailing).to eq('…') }
|
19
19
|
|
20
20
|
context 'custom values' do
|
21
|
-
let(:args) { [45, { :
|
21
|
+
let(:args) { [45, { separator: ' ', trailing: '...' }] }
|
22
22
|
|
23
|
-
|
23
|
+
it { expect(subject.length).to eq(45) }
|
24
24
|
|
25
|
-
|
25
|
+
it { expect(subject.separator).to eq(' ') }
|
26
26
|
|
27
|
-
|
27
|
+
it { expect(subject.trailing).to eq('...') }
|
28
28
|
end
|
29
29
|
end # initialize
|
@@ -1,53 +1,53 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Text::Truncation, '#truncate' do
|
6
6
|
let(:separator) { nil }
|
7
|
-
let(:options)
|
8
|
-
let(:trailing)
|
9
|
-
let(:object)
|
7
|
+
let(:options) { { length: length, separator: separator, trailing: trailing } }
|
8
|
+
let(:trailing) { '…' }
|
9
|
+
let(:object) { described_class.new(text, options) }
|
10
10
|
|
11
11
|
subject { object.truncate }
|
12
12
|
|
13
13
|
context 'unicode support' do
|
14
|
-
let(:text)
|
14
|
+
let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' }
|
15
15
|
|
16
16
|
context 'with zero length' do
|
17
17
|
let(:length) { 0 }
|
18
18
|
|
19
|
-
it {
|
19
|
+
it { is_expected.to eq(text) }
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'with nil length' do
|
23
23
|
let(:length) { nil }
|
24
24
|
|
25
|
-
it {
|
25
|
+
it { is_expected.to eq(text) }
|
26
26
|
end
|
27
27
|
|
28
28
|
context 'with equal length' do
|
29
29
|
let(:length) { text.length }
|
30
30
|
|
31
|
-
it {
|
31
|
+
it { is_expected.to eq(text) }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'with truncation' do
|
35
35
|
let(:length) { 12 }
|
36
36
|
|
37
|
-
it {
|
37
|
+
it { is_expected.to eq("ラドクリフ、マラソン五#{trailing}") }
|
38
38
|
end
|
39
39
|
|
40
40
|
context 'without truncation' do
|
41
41
|
let(:length) { 100 }
|
42
42
|
|
43
|
-
it {
|
43
|
+
it { is_expected.to eq(text) }
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'with separator' do
|
47
47
|
let(:length) { 12 }
|
48
48
|
let(:separator) { ' ' }
|
49
49
|
|
50
|
-
it {
|
50
|
+
it { is_expected.to eq("ラドクリフ、マラソン五#{trailing}") }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -56,7 +56,7 @@ describe TTY::Text::Truncation, '#truncate' do
|
|
56
56
|
let(:length) { 20 }
|
57
57
|
let(:trailing) { '... (see more)' }
|
58
58
|
|
59
|
-
it {
|
59
|
+
it { is_expected.to eq("ラドクリフ、#{trailing}") }
|
60
60
|
end
|
61
61
|
|
62
62
|
context 'with separator' do
|
@@ -66,13 +66,13 @@ describe TTY::Text::Truncation, '#truncate' do
|
|
66
66
|
context 'blank' do
|
67
67
|
let(:separator) { '' }
|
68
68
|
|
69
|
-
it {
|
69
|
+
it { is_expected.to eq("Immense as whales, the m#{trailing}") }
|
70
70
|
end
|
71
71
|
|
72
72
|
context 'space' do
|
73
73
|
let(:separator) { ' ' }
|
74
74
|
|
75
|
-
it {
|
75
|
+
it { is_expected.to eq("Immense as whales, the…") }
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
data/spec/tty/text/wrap_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -9,6 +9,5 @@ describe TTY::Text, '#wrap' do
|
|
9
9
|
|
10
10
|
subject { described_class.wrap(text, :length => length, :indent => indent) }
|
11
11
|
|
12
|
-
it {
|
13
|
-
|
12
|
+
it { is_expected.to eq(" ラドクリフ、マラ\n ソン五輪代表に1\n 万m出場にも含み") }
|
14
13
|
end # wrap
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -7,19 +7,19 @@ describe TTY::Text::Wrapping, '#initialize' do
|
|
7
7
|
|
8
8
|
let(:args) { [] }
|
9
9
|
|
10
|
-
subject { described_class.new text, *args }
|
10
|
+
subject(:wrapping) { described_class.new text, *args }
|
11
11
|
|
12
|
-
|
12
|
+
it { expect(wrapping.text).to eq(text) }
|
13
13
|
|
14
|
-
|
14
|
+
it { expect(wrapping.length).to eq(80) }
|
15
15
|
|
16
|
-
|
16
|
+
it { expect(wrapping.indent).to eq(0) }
|
17
17
|
|
18
18
|
context 'custom values' do
|
19
19
|
let(:args) { [45, { :indent => 5 }]}
|
20
20
|
|
21
|
-
|
21
|
+
it { expect(wrapping.length).to eq(45) }
|
22
22
|
|
23
|
-
|
23
|
+
it { expect(wrapping.indent).to eq(5) }
|
24
24
|
end
|
25
25
|
end # initialize
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -8,7 +8,7 @@ describe TTY::Text::Wrapping, '#wrap' do
|
|
8
8
|
let(:padding) { [] }
|
9
9
|
let(:options) { {length: length, indent: indent, padding: padding} }
|
10
10
|
|
11
|
-
subject { object.wrap }
|
11
|
+
subject(:wrapping) { object.wrap }
|
12
12
|
|
13
13
|
context 'unicode support' do
|
14
14
|
let(:text) { 'ラドクリフ、マラソン五輪代表に1万m出場にも含み' }
|
@@ -16,25 +16,25 @@ describe TTY::Text::Wrapping, '#wrap' do
|
|
16
16
|
context 'with zero length' do
|
17
17
|
let(:length) { 0 }
|
18
18
|
|
19
|
-
it {
|
19
|
+
it { is_expected.to eq(text) }
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'with nil length' do
|
23
23
|
let(:length) { nil }
|
24
24
|
|
25
|
-
it {
|
25
|
+
it { is_expected.to eq(text) }
|
26
26
|
end
|
27
27
|
|
28
28
|
context 'without wrapping' do
|
29
29
|
let(:length) { 8 }
|
30
30
|
|
31
|
-
it {
|
31
|
+
it { is_expected.to eq("ラドクリフ、マラ\nソン五輪代表に1\n万m出場にも含み") }
|
32
32
|
end
|
33
33
|
|
34
34
|
context 'with wrapping' do
|
35
35
|
let(:length) { 100 }
|
36
36
|
|
37
|
-
it {
|
37
|
+
it { is_expected.to eq(text) }
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -50,7 +50,7 @@ describe TTY::Text::Wrapping, '#wrap' do
|
|
50
50
|
satisfaction of knowing that it is all right;
|
51
51
|
" }
|
52
52
|
|
53
|
-
it {
|
53
|
+
it { is_expected.to eq <<-EOS.normalize
|
54
54
|
What of it, if some old hunks of a\n sea-captain orders me to get a broom
|
55
55
|
and sweep down the decks? What does that\n indignity amount to, weighed,
|
56
56
|
I mean, in the scales of the New Testament?\n Do you think the archangel
|
@@ -68,14 +68,14 @@ describe TTY::Text::Wrapping, '#wrap' do
|
|
68
68
|
let(:length) { 8 }
|
69
69
|
let(:indent) { 4 }
|
70
70
|
|
71
|
-
it {
|
71
|
+
it { is_expected.to eq " ラドクリフ、マラ\n ソン五輪代表に1\n 万m出場にも含み" }
|
72
72
|
end
|
73
73
|
|
74
74
|
context 'with ansi colors' do
|
75
75
|
let(:text) { "\[\033[01;32m\]Hey have\[\033[01;34m\]some cake\[\033[00m\]" }
|
76
76
|
let(:length) { 6 }
|
77
77
|
|
78
|
-
it {
|
78
|
+
it { is_expected.to eq "\[\033[01;32m\]Hey have\[\033[01;34m\]some\ncake\[\033[00m\]" }
|
79
79
|
end
|
80
80
|
|
81
81
|
context 'with newlines' do
|
@@ -83,7 +83,7 @@ describe TTY::Text::Wrapping, '#wrap' do
|
|
83
83
|
let(:text) { "\n\nラドクリフ、マラソン五輪代表に1万m出場にも含み\n\n\n" }
|
84
84
|
let(:length) { 10 }
|
85
85
|
|
86
|
-
it {
|
86
|
+
it { is_expected.to eq "\n\nラドクリフ、マラソン\n五輪代表に1万m出場\nにも含み\n\n\n" }
|
87
87
|
end
|
88
88
|
|
89
89
|
context 'with padding' do
|
@@ -91,7 +91,7 @@ describe TTY::Text::Wrapping, '#wrap' do
|
|
91
91
|
let(:length) { 10 }
|
92
92
|
let(:padding) { [1,2,3,4] }
|
93
93
|
|
94
|
-
it {
|
94
|
+
it { is_expected.to eq "\n\n ラドクリフ、マラソン \n 五輪代表に1万m出場 \n にも含み \n\n" }
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end # wrap
|