|
2 | 2 | let (:helper) { Fastlane::Helper::PatchHelper } |
3 | 3 |
|
4 | 4 | describe 'apply_patch' do |
5 | | - it 'inserts text after a pattern in :append mode' do |
6 | | - original = 'alpha beta gamma' |
7 | | - modified = helper.apply_patch original, /beta/, ' beta and a half', false, :append, 0 |
8 | | - expect(modified).to eq 'alpha beta beta and a half gamma' |
9 | | - end |
| 5 | + describe 'modes' do |
| 6 | + it 'inserts text after a pattern in :append mode' do |
| 7 | + original = 'alpha beta gamma' |
| 8 | + modified = helper.apply_patch original, /beta/, ' beta and a half', false, :append, 0 |
| 9 | + expect(modified).to eq 'alpha beta beta and a half gamma' |
| 10 | + end |
10 | 11 |
|
11 | | - it 'inserts text before a pattern in :prepend mode' do |
12 | | - original = 'alpha beta gamma' |
13 | | - modified = helper.apply_patch original, /beta/, 'alpha and a half ', false, :prepend, 0 |
14 | | - expect(modified).to eq 'alpha alpha and a half beta gamma' |
15 | | - end |
| 12 | + it 'inserts text before a pattern in :prepend mode' do |
| 13 | + original = 'alpha beta gamma' |
| 14 | + modified = helper.apply_patch original, /beta/, 'alpha and a half ', false, :prepend, 0 |
| 15 | + expect(modified).to eq 'alpha alpha and a half beta gamma' |
| 16 | + end |
16 | 17 |
|
17 | | - it 'replaces a pattern with text in :replace mode' do |
18 | | - original = 'alpha beta gamma' |
19 | | - modified = helper.apply_patch original, /beta/, 'two', false, :replace, 0 |
20 | | - expect(modified).to eq 'alpha two gamma' |
| 18 | + it 'replaces a pattern with text in :replace mode' do |
| 19 | + original = 'alpha beta gamma' |
| 20 | + modified = helper.apply_patch original, /beta/, 'two', false, :replace, 0 |
| 21 | + expect(modified).to eq 'alpha two gamma' |
| 22 | + end |
| 23 | + |
| 24 | + it 'raises for any other mode' do |
| 25 | + original = 'alpha beta gamma' |
| 26 | + expect do |
| 27 | + helper.apply_patch original, /beta/, ' beta and a half', false, :add_somewhere_i_dont_know_where, 0 |
| 28 | + end.to raise_error ArgumentError |
| 29 | + end |
21 | 30 | end |
22 | 31 |
|
23 | | - it 'raises for any other mode' do |
24 | | - original = 'alpha beta gamma' |
25 | | - expect do |
26 | | - helper.apply_patch original, /beta/, ' beta and a half', false, :add_somewhere_i_dont_know_where, 0 |
27 | | - end.to raise_error ArgumentError |
| 32 | + describe 'line endings' do |
| 33 | + it 'handles things at the end of a line' do |
| 34 | + original = "alpha\nbeta\ngamma\n" |
| 35 | + modified = helper.apply_patch original, /beta$/, "\nbeta and a half", false, :append, 0 |
| 36 | + expect(modified).to eq "alpha\nbeta\nbeta and a half\ngamma\n" |
| 37 | + end |
| 38 | + |
| 39 | + it 'handles things at the beginning of a line' do |
| 40 | + original = "alpha\nbeta\ngamma\n" |
| 41 | + modified = helper.apply_patch original, /^beta/, "alpha and a half\n", false, :prepend, 0 |
| 42 | + expect(modified).to eq "alpha\nalpha and a half\nbeta\ngamma\n" |
| 43 | + end |
28 | 44 | end |
29 | 45 | end |
30 | 46 |
|
31 | 47 | describe 'revert_patch' do |
32 | | - it 'removes a patch applied in :append mode' do |
33 | | - original = 'alpha beta beta and a half gamma' |
34 | | - modified = helper.revert_patch original, /beta/, ' beta and a half', false, :append, 0 |
35 | | - expect(modified).to eq 'alpha beta gamma' |
36 | | - end |
| 48 | + describe 'modes' do |
| 49 | + it 'removes a patch applied in :append mode' do |
| 50 | + original = 'alpha beta beta and a half gamma' |
| 51 | + modified = helper.revert_patch original, /beta/, ' beta and a half', false, :append, 0 |
| 52 | + expect(modified).to eq 'alpha beta gamma' |
| 53 | + end |
| 54 | + |
| 55 | + it 'reverts a patch applied in :prepend mode' do |
| 56 | + original = 'alpha alpha and a half beta gamma' |
| 57 | + modified = helper.revert_patch original, /beta/, 'alpha and a half ', false, :prepend, 0 |
| 58 | + expect(modified).to eq 'alpha beta gamma' |
| 59 | + end |
37 | 60 |
|
38 | | - it 'reverts a patch applied in :prepend mode' do |
39 | | - original = 'alpha alpha and a half beta gamma' |
40 | | - modified = helper.revert_patch original, /beta/, 'alpha and a half ', false, :prepend, 0 |
41 | | - expect(modified).to eq 'alpha beta gamma' |
| 61 | + it 'raises if :replace mode specified' do |
| 62 | + original = 'alpha two gamma' |
| 63 | + expect do |
| 64 | + helper.revert_patch original, /beta/, 'two', false, :replace, 0 |
| 65 | + end.to raise_error ArgumentError |
| 66 | + end |
42 | 67 | end |
43 | 68 |
|
44 | | - it 'raises if :replace mode specified' do |
45 | | - original = 'alpha two gamma' |
46 | | - expect do |
47 | | - helper.revert_patch original, /beta/, 'two', false, :replace, 0 |
48 | | - end.to raise_error ArgumentError |
| 69 | + describe 'line endings' do |
| 70 | + it 'handles things at the end of a line' do |
| 71 | + original = "alpha\nbeta\nbeta and a half\ngamma\n" |
| 72 | + modified = helper.revert_patch original, /beta$/, "\nbeta and a half", false, :append, 0 |
| 73 | + expect(modified).to eq "alpha\nbeta\ngamma\n" |
| 74 | + end |
| 75 | + |
| 76 | + it 'handles things at the beginning of a line' do |
| 77 | + original = "alpha\nalpha and a half\nbeta\ngamma\n" |
| 78 | + modified = helper.revert_patch original, /^beta/, "alpha and a half\n", false, :prepend, 0 |
| 79 | + expect(modified).to eq "alpha\nbeta\ngamma\n" |
| 80 | + end |
49 | 81 | end |
50 | 82 | end |
51 | 83 | end |
0 commit comments