Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make test case stricter #222

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions spec/binary_file_match_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
context 'when input is from stdin' do
let(:input) { content }
let(:args) { '_' }
let(:expect_output) { 'Binary file matches.' }
let(:expect_output) { "Binary file matches.\n" }

it_behaves_like 'a successful exec'
end

context 'when input is from file' do
let(:file) { 'binary_file' }
let(:args) { "_ #{file}" }
let(:expect_output) { 'Binary file matches.' }
let(:expect_output) { "Binary file matches.\n" }

before do
write_file(file, content)
Expand All @@ -24,7 +24,7 @@
describe 'non-binary file' do
let(:input) { "hello\tworld\n" }
let(:args) { '_' }
let(:expect_output) { "hello\tworld" }
let(:expect_output) { "hello\tworld\n" }

it_behaves_like 'a successful exec'
end
Expand Down
65 changes: 46 additions & 19 deletions spec/container/instance_methods_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe 'Container internal methods' do
using RSpec::Parameterized::TableSyntax

where(:method, :expect_output) do
where(:method, :output) do
'gsub' | %w[barbar foofoo].join("\n")
'gsub!' | %w[barbar barbar].join("\n")
'sub' | %w[barfoo foofoo].join("\n")
Expand All @@ -11,23 +11,25 @@
with_them do
let(:input) { 'foofoo' }
let(:args) { %('puts #{method}(/foo/, "bar"); _') }
let(:expect_output) { "#{output}\n" }

it_behaves_like 'a successful exec'
end

where(:method, :expect_output) do
where(:method, :output) do
'tr' | %w[FOOFOO foofoo].join("\n")
'tr!' | %w[FOOFOO FOOFOO].join("\n")
end

with_them do
let(:input) { 'foofoo' }
let(:args) { %('puts #{method}("a-z", "A-Z"); _') }
let(:expect_output) { "#{output}\n" }

it_behaves_like 'a successful exec'
end

where(:command, :expect_output) do
where(:command, :output) do
'grep(/foo/)' | 'foo'
'grep_v(/bar/)' | 'foo baz'
'grep(/foo/){|i| i + "hoge" }' | 'foohoge'
Expand All @@ -37,6 +39,7 @@
with_them do
let(:input) { %w[foo bar baz].join("\n") }
let(:args) { %(-s '#{command}') }
let(:expect_output) { "#{output}\n" }

it_behaves_like 'a successful exec'
end
Expand All @@ -48,8 +51,8 @@
'String' => {
condition: '"2 foo baz"',
output: {
without_block: '2 foo baz',
with_block: '2'
without_block: "2 foo baz\n",
with_block: "2\n"
}
},
'Regexp' => {
Expand All @@ -60,14 +63,14 @@
2 foo baz
3 foo qux
OUTPUT
with_block: %w[1 2 3].join("\n")
with_block: "1\n2\n3\n"
}
},
'TrueClass' => {
condition: '_1 == "3"',
output: {
without_block: '3 foo qux',
with_block: '3'
without_block: "3 foo qux\n",
with_block: "3\n"
}
},
'FalseClass' => {
Expand All @@ -85,7 +88,7 @@
2 foo baz
3 foo qux
OUTPUT
with_block: %w[1 2 3].join("\n")
with_block: "1\n2\n3\n"
}
},
'NilClass' => {
Expand Down Expand Up @@ -131,9 +134,13 @@
'String' => {
condition: '"2 foo baz"',
output: {
without_block: '2 foo baz',
with_block: '2 foo baz',
return_value: %w[false true false].join("\n")
without_block: "2 foo baz\n",
with_block: "2 foo baz\n",
return_value: <<~VALUE
false
true
false
VALUE
}
},
'Regexp' => {
Expand All @@ -149,23 +156,35 @@
2 foo baz
3 foo qux
OUTPUT
return_value: %w[true true true].join("\n")
return_value: <<~VALUE
true
true
true
VALUE
}
},
'TrueClass' => {
condition: '_1 == "3"',
output: {
without_block: '3 foo qux',
with_block: '3 foo qux',
return_value: %w[false false true].join("\n")
without_block: "3 foo qux\n",
with_block: "3 foo qux\n",
return_value: <<~VALUE
false
false
true
VALUE
}
},
'FalseClass' => {
condition: '_1 == "4"',
output: {
without_block: '',
with_block: '',
return_value: %w[false false false].join("\n")
return_value: <<~VALUE
false
false
false
VALUE
}
},
'Integer' => {
Expand All @@ -181,15 +200,23 @@
2 foo baz
3 foo qux
OUTPUT
return_value: %w[true true true].join("\n")
return_value: <<~VALUE
true
true
true
VALUE
}
},
'NilClass' => {
condition: '_2 =~ /hoge/',
output: {
without_block: '',
with_block: '',
return_value: %w[false false false].join("\n")
return_value: <<~VALUE
false
false
false
VALUE
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion spec/container/special_variables_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
with_them do
let(:input) { 'foo' }
let(:args) { "-q 'puts #{name}'" }
let(:expect_output) { input }
let(:expect_output) { "#{input}\n" }

it_behaves_like 'a successful exec'
end
Expand Down
5 changes: 3 additions & 2 deletions spec/error_message_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe 'Show error message' do
using RSpec::Parameterized::TableSyntax

where(:args, :expect_output) do
where(:args, :output) do
'--invalid-option' | 'Error: invalid option: --invalid-option'
'-t test' | 'Error: "test" is invalid type. possible values: text,json,yaml'
'-t' | 'Error: missing argument: -t'
Expand All @@ -17,13 +17,14 @@

with_them do
let(:input) { "test\n" }
let(:expect_output) { "#{output}\n" }
it_behaves_like 'a failed exec'
end

context 'when permission denied' do
let(:file) { 'permission_denied_file' }
let(:args) { "_ #{file}" }
let(:expect_output) { "Error: #{file}: permission denied" }
let(:expect_output) { "Error: #{file}: permission denied\n" }

before do
touch(file)
Expand Down
2 changes: 1 addition & 1 deletion spec/feature/array_size_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
end

let(:args) { '-s _.size' }
let(:expect_output) { '140000' }
let(:expect_output) { "140000\n" }

it_behaves_like 'a successful exec'
end
4 changes: 2 additions & 2 deletions spec/feature/hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
{
'key is exist' => {
args: '-j _.foo',
expect_output: 'bar'
expect_output: "\"bar\"\n"
},
'key is not exist' => {
args: '-j _.piyo.class.to_s',
expect_output: 'NilClass'
expect_output: "\"NilClass\"\n"
}
}
end
Expand Down
4 changes: 2 additions & 2 deletions spec/feature/integaer_float_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[
"##{mark} with String argument",
%('#{statement}'),
answer.to_s
"#{answer}\n"
]
end
end
Expand All @@ -30,7 +30,7 @@
[
"##{mark} with String argument",
%(-q 'p #{statement}'),
answer.to_s
"#{answer}\n"
]
end
end
Expand Down
14 changes: 9 additions & 5 deletions spec/feature/nil_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

describe '#+' do
where(:input, :expect_output) do
%w[1 2 3].join("\n") | '6'
%w[1.1 2.2 3.3].join("\n") | '6.6'
%w[foo bar baz].join("\n") | 'foobarbaz'
%w[1 2 3].join("\n") | "6\n"
%w[1.1 2.2 3.3].join("\n") | "6.6\n"
%w[foo bar baz].join("\n") | "foobarbaz\n"
end

with_them do
Expand All @@ -20,9 +20,13 @@
describe '#<<' do
let(:input) { %w[foo bar baz].join("\n") }
let(:args) do
%w[-q 's<<=_1; at_exit { puts s }']
%w[-q 's<<=_1; at_exit { p s }']
end
let(:expect_output) do
<<~OUTPUT
["foo", "bar", "baz"]
OUTPUT
end
let(:expect_output) { '["foo", "bar", "baz"]' }

it_behaves_like 'a successful exec'
end
Expand Down
2 changes: 1 addition & 1 deletion spec/feature/string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[
"##{mark} with #{klass} argument",
%(-q 'p #{statement}'),
answer.to_s
"#{answer}\n"
]
end
end
Expand Down
5 changes: 3 additions & 2 deletions spec/filter/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
let(:input) { '"foobar"' }
let(:args) { '-j -H --no-color true testfile' }
let(:expect_output) do
input.split("\n").map { |line| "testfile:#{line}" }.join("\n")
out = input.split("\n").map { |line| "testfile:#{line}" }.join("\n")
"#{out}\n"
end

before do
Expand Down Expand Up @@ -288,7 +289,7 @@

let(:args) { '-j _' }
let(:expect_output) do
'Error: failed to parse JSON: unexpected end of data position: 14'
"Error: failed to parse JSON: unexpected end of data position: 14\n"
end

it_behaves_like 'a failed exec'
Expand Down
6 changes: 4 additions & 2 deletions spec/filter/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
context 'when use -H option' do
let(:args) { '-H --no-color true testfile' }
let(:expect_output) do
input.split("\n").map { |line| "testfile:#{line}" }.join("\n")
out = input.split("\n").map { |line| "testfile:#{line}" }.join("\n")
"#{out}\n"
end

before do
Expand Down Expand Up @@ -84,10 +85,11 @@
context 'when multiple files' do
let(:args) { '--no-color true testfile1 testfile2' }
let(:expect_output) do
[
out = [
input.split("\n").map { |line| "testfile1:#{line}" }.join("\n"),
input.split("\n").map { |line| "testfile2:#{line}" }.join("\n")
].join("\n")
"#{out}\n"
end

before do
Expand Down
13 changes: 7 additions & 6 deletions spec/filter/yaml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
describe 'Output UTF-8 string' do
let(:input) { 'あいうえお🍣' }
let(:args) { '-y _' }
let(:expect_output) { 'あいうえお🍣' }
let(:expect_output) { "あいうえお🍣\n" }

it_behaves_like 'a successful exec'
end
Expand Down Expand Up @@ -247,19 +247,19 @@
{
'TrueClass' => {
command: 'true',
expect_output: 'true'
expect_output: "true\n"
},
'FalseClass' => {
command: 'false',
expect_output: 'false'
expect_output: "false\n"
},
'NilClass' => {
command: 'nil',
expect_output: 'null'
expect_output: "null\n"
},
'Hash with null value' => {
command: '{foo: nil}',
expect_output: ':foo: null'
expect_output: ":foo: null\n"
}
}
end
Expand All @@ -275,7 +275,8 @@
let(:input) { 'foobar' }
let(:args) { '-y -H --no-color true testfile' }
let(:expect_output) do
input.split("\n").map { |line| "testfile:#{line}" }.join("\n")
out = input.split("\n").map { |line| "testfile:#{line}" }.join("\n")
"#{out}\n"
end

before do
Expand Down
Loading