-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff.go
145 lines (117 loc) · 4.07 KB
/
diff.go
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package indiff
import "fmt"
// Diffs is collection of multiple differences
type Diffs = []Diff
// Diff represents same difference between base and translation file
type Diff interface {
// Base points to base file
Base() *File
// Translation points to file compared with base file
Translation() *File
// Lang is language in which this difference occurs (usually defined by translation file)
Lang() string
}
// DiffTool represent tool for calculating differences
type DiffTool interface {
// Diff calculates differences
Diff(bundle *Bundle) []Diff
}
// Missing says that there is no translation for base file in specified language
type Missing struct {
base *File
lang string
}
// NewMissing creates new missing file difference
func NewMissing(base *File, lang string) *Missing {
return &Missing{base: base, lang: lang}
}
// Base points to base file for which there is no translation
func (m *Missing) Base() *File {
return m.base
}
// Translation returns always nil because it does not exist
func (m *Missing) Translation() *File {
return nil
}
// Lang is language in which there is no transaltion for base file
func (m *Missing) Lang() string {
return m.lang
}
func (m *Missing) String() string {
return fmt.Sprintf("Missing{ base: %s, lang: %s }", m.base, m.lang)
}
// Modification holds modified file changes made to this file
type Modification struct {
file *File
patch string // TODO: use some structured type instead of string to be able to control output
}
// NewModification turns File to Modification (modified file) with changes in given patch
func NewModification(file *File, patch string) *Modification {
return &Modification{file: file, patch: patch}
}
// Modified turns this file to Modification with changes in given patch
func (f *File) Modified(patch string) *Modification {
return NewModification(f, patch)
}
// ModifiedBase says that base file was modified but it's translation was not
type ModifiedBase struct {
base *Modification
translation *File
// TODO: what exactly was added / removed
}
// NewModifiedBase creates new ModifiedBase file difference
func NewModifiedBase(base *Modification, translation *File) *ModifiedBase {
return &ModifiedBase{base: base, translation: translation}
}
// Base points to file in base language which was modified
func (m *ModifiedBase) Base() *File {
return m.base.file
}
// BasePatch returns text representation of changes made to file in base language
func (m *ModifiedBase) BasePatch() string {
return m.base.patch
}
// Translation points to file which equivalent in base language was modified
func (m *ModifiedBase) Translation() *File {
return m.translation
}
// Lang is language in which there was no modification
func (m *ModifiedBase) Lang() string {
return m.translation.Lang
}
func (m *ModifiedBase) String() string {
return fmt.Sprintf("ModifiedBase{ base: %s, translation: %s }", m.base.file, m.translation)
}
// ModifiedBoth says that base file and it's translation was modified
type ModifiedBoth struct {
base *Modification
translation *Modification
// TODO: what exactly was added / removed
}
// NewModifiedBoth creates new ModifiedBoth file difference
func NewModifiedBoth(base *Modification, translation *Modification) *ModifiedBoth {
return &ModifiedBoth{base: base, translation: translation}
}
// Base points to file in base language which was modified
func (m *ModifiedBoth) Base() *File {
return m.base.file
}
// BasePatch returns text representation of changes made to file in base language
func (m *ModifiedBoth) BasePatch() string {
return m.base.patch
}
// TranslationPatch returns text representation of changes made to translation file
func (m *ModifiedBoth) TranslationPatch() string {
return m.translation.patch
}
// Translation points to translation file which was modified
func (m *ModifiedBoth) Translation() *File {
return m.translation.file
}
// Lang is language of translation file
func (m *ModifiedBoth) Lang() string {
return m.translation.file.Lang
}
func (m *ModifiedBoth) String() string {
return fmt.Sprintf("ModifiedBoth{ base: %s, translation: %s }", m.base.file, m.translation.file)
}