Skip to content

Commit d632210

Browse files
author
Kevin Paulisse
committed
Add unit tests for added methods
1 parent 8538f5b commit d632210

File tree

1 file changed

+63
-0
lines changed
  • spec/octocatalog-diff/tests/catalog-diff/display

1 file changed

+63
-0
lines changed

spec/octocatalog-diff/tests/catalog-diff/display/text_spec.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,4 +1019,67 @@
10191019
expect(logger_str.string).to eq('')
10201020
end
10211021
end
1022+
1023+
describe '#adjust_position_of_plus_minus' do
1024+
it 'should work with colorized string' do
1025+
input = "\e[31m-file line\e[0m"
1026+
result = described_class.adjust_position_of_plus_minus(input)
1027+
expect(result).to eq("\e[31m- file line\e[0m")
1028+
end
1029+
1030+
it 'should work with non-colorized string' do
1031+
input = '-file line'
1032+
result = described_class.adjust_position_of_plus_minus(input)
1033+
expect(result).to eq('- file line')
1034+
end
1035+
end
1036+
1037+
describe '#make_trailing_whitespace_visible' do
1038+
it 'should work with colorized string' do
1039+
input = "\e[31m- file line \e[0m"
1040+
result = described_class.make_trailing_whitespace_visible(input)
1041+
expect(result).to eq("\e[31m- file line____\e[0m")
1042+
end
1043+
1044+
it 'should work with non-colorized string' do
1045+
input = '- file line '
1046+
result = described_class.make_trailing_whitespace_visible(input)
1047+
expect(result).to eq('- file line____')
1048+
end
1049+
1050+
it 'should work with colorized string with no trailing whitespace' do
1051+
input = "\e[31m- file line\e[0m"
1052+
result = described_class.make_trailing_whitespace_visible(input)
1053+
expect(result).to eq("\e[31m- file line\e[0m")
1054+
end
1055+
1056+
it 'should work with a non-colorized string with no trailing whitespace' do
1057+
input = '- file line'
1058+
result = described_class.make_trailing_whitespace_visible(input)
1059+
expect(result).to eq('- file line')
1060+
end
1061+
1062+
it 'should convert special spaces to character equivalents' do
1063+
input = "test \r\n\t\f"
1064+
result = described_class.make_trailing_whitespace_visible(input)
1065+
expect(result).to eq('test_\\r\\n\\t\\f')
1066+
end
1067+
end
1068+
1069+
describe '#add_trailing_newlines' do
1070+
it 'should add newlines when neither string ends in newline' do
1071+
result = described_class.add_trailing_newlines('one', 'two')
1072+
expect(result).to eq(%W(one\n two\n))
1073+
end
1074+
1075+
it 'should not add newlines when one string ends in newline and the other does not' do
1076+
result = described_class.add_trailing_newlines('one', "two\n")
1077+
expect(result).to eq(%W(one two\n))
1078+
end
1079+
1080+
it 'should not add newlines when both strings end in newline' do
1081+
result = described_class.add_trailing_newlines("one\n", "two\n")
1082+
expect(result).to eq(%W(one\n two\n))
1083+
end
1084+
end
10221085
end

0 commit comments

Comments
 (0)