-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathDiffBuilderTest.class.st
106 lines (87 loc) · 2.18 KB
/
DiffBuilderTest.class.st
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
Class {
#name : 'DiffBuilderTest',
#superclass : 'TestCase',
#category : 'Spec2-Code-Diff-Tests',
#package : 'Spec2-Code-Diff-Tests'
}
{ #category : 'tests' }
DiffBuilderTest >> testDiffFromTo [
| fileA fileB patch |
fileA := 'ABCABBA'.
fileB := 'CBABAC'.
patch := DiffBuilder new
diffFrom: fileA
to: fileB.
self assert: patch size equals: 5.
self
assert: (patch collect: #class as: Array)
equals: { DiffDelete. DiffInsert . DiffDelete. DiffDelete. DiffInsert }.
self
assert: (patch collect: #oldPosition as: Array)
equals: {1. 2. 3. 6. 8}.
self assert: (patch at: 2) newPosition equals: 1.
self assert: (patch at: 5) newPosition equals: 6
]
{ #category : 'tests' }
DiffBuilderTest >> testDiffIRecordsLastLineWhenMatching [
| patch fileA fileB |
fileA := 'newSourceView
^ GtkSourceView new
beWrapWord;
showLineNumbers: true;
autoIndent: true;
yourself'.
fileB := 'newSourceView
^ GtkSourceView new
beWrapWord;
monospace: true;
showLineNumbers: "self presenter hasLineNumbers" false;
showLineMarks: true;
autoIndent: true;
indentOnTab: true;
tabWidth: 4;
yourself'.
patch := DiffBuilder
buildPatchFrom: fileA lines
to: fileB lines.
self assert: patch elements last element equals: ' yourself'
]
{ #category : 'tests' }
DiffBuilderTest >> testDiffWithLines [
| fileA fileB patch |
fileA := 'test
with lines
that will change'.
fileB := 'test
with LINES
that will change
'.
patch := DiffBuilder new
diffFrom: fileA lines
to: fileB lines.
self assert: patch size equals: 2.
self
assert: (patch collect: #class)
equals: { DiffDelete. DiffInsert }.
self assert: (patch collect: #oldPosition as: Array) equals: #(2 3).
self assert: (patch at: 2) newPosition equals: 2
]
{ #category : 'tests' }
DiffBuilderTest >> testDiffWithLinesRecordsDelete [
| fileA fileB patch |
fileA := 'a
b
c'.
fileB := 'a
b
d'.
patch := DiffBuilder new
diffFrom: fileA lines
to: fileB lines.
self assert: patch size equals: 2.
self
assert: (patch collect: #class)
equals: { DiffDelete. DiffInsert }.
self assert: (patch collect: #oldPosition as: Array) equals: #(3 4).
self assert: (patch at: 2) newPosition equals: 3
]