Expand test hook to return empty output if line #clear is in input + write spec for test hook.

This commit is contained in:
Sven Weidauer 2022-06-06 10:42:09 +02:00
parent ba54c407cb
commit f4657ba967
2 changed files with 29 additions and 1 deletions

View file

@ -1,6 +1,12 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
output = []
$stdin.readlines.each do |line|
puts line.gsub(/([^\s]*)\s*=\s*(.*)/, '\1 = \2')
exit 0 if line.chomp == '#clear'
output << line.gsub(/([^\s]*)\s*=\s*(.*)/, '\1 = \2')
end
output.each do |line|
puts line
end

22
spec/test_hook_spec.rb Normal file
View file

@ -0,0 +1,22 @@
# frozen_string_literal: true
describe 'Test Hook' do
it 'adds spaces around =' do
out = run 'a=b'
expect(out).to eq('a = b')
end
it 'returns empty output if it as a #clear line' do
out = run "a=b\n#clear\nc = d"
expect(out).to eq ''
end
def run(input)
IO.popen ['ruby', "#{__dir__}/test_hook.rb"], mode: File::RDWR do |io|
io.write input
io.close_write
io.read.chomp
end
end
end