-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathbinary_string_spec.rb
More file actions
87 lines (80 loc) · 2.83 KB
/
binary_string_spec.rb
File metadata and controls
87 lines (80 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# frozen_string_literal: true
require 'spec_helper'
require 'super_diff/binary_string'
RSpec.describe 'Integration with binary strings', type: :integration do
context 'when comparing two different binary strings' do
it 'produces the correct failure message' do
as_both_colored_and_uncolored do |color_enabled|
snippet = <<~TEST.strip
require 'super_diff/binary_string'
actual = "Hello".b
expected = "World".b
expect(actual).to eq(expected)
TEST
program =
make_plain_test_program(snippet, color_enabled: color_enabled)
expected_output =
build_expected_output(
color_enabled: color_enabled,
snippet: 'expect(actual).to eq(expected)',
expectation:
proc do
line do
plain 'Expected '
actual '<binary string (5 bytes)>'
plain ' to eq '
expected '<binary string (5 bytes)>'
plain '.'
end
end,
diff:
proc do
expected_line '- 00000000: 576f 726c 64 World'
actual_line '+ 00000000: 4865 6c6c 6f Hello'
end
)
expect(program).to produce_output_when_run(expected_output).in_color(
color_enabled
)
end
end
end
context 'when comparing binary strings spanning multiple lines' do
it 'produces a multi-line hex dump diff' do
as_both_colored_and_uncolored do |color_enabled|
snippet = <<~TEST.strip
require 'super_diff/binary_string'
actual = ("A" * 20).b
expected = ("A" * 16 + "B" * 4).b
expect(actual).to eq(expected)
TEST
program =
make_plain_test_program(snippet, color_enabled: color_enabled)
expected_output =
build_expected_output(
color_enabled: color_enabled,
snippet: 'expect(actual).to eq(expected)',
expectation:
proc do
line do
plain 'Expected '
actual '<binary string (20 bytes)>'
plain ' to eq '
expected '<binary string (20 bytes)>'
plain '.'
end
end,
diff:
proc do
plain_line ' 00000000: 4141 4141 4141 4141 4141 4141 4141 4141 AAAAAAAAAAAAAAAA'
expected_line '- 00000010: 4242 4242 BBBB'
actual_line '+ 00000010: 4141 4141 AAAA'
end
)
expect(program).to produce_output_when_run(expected_output).in_color(
color_enabled
)
end
end
end
end