-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_tags.rb
executable file
·234 lines (195 loc) · 8.28 KB
/
test_tags.rb
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env ruby
# encoding: UTF-8
require './change_bot'
require './user'
require './changeset'
require './db'
require './actions'
require './util.rb'
require 'minitest/unit'
class TestTags < MiniTest::Unit::TestCase
def setup
@db = DB.new(:changesets => {
1 => Changeset[User[true]],
2 => Changeset[User[true]],
3 => Changeset[User[false]]
})
end
# --------------------------------------------------------------------------
# Tests concerned with the keeping and removing of tags.
# --------------------------------------------------------------------------
# This tests the following scenario:
# * agreer creates object
# * decliner adds a name tag
# * agreer makes a trivial change to that tag
# * therefore the decliner retains "ownership" and the tag must be
# removed.
def test_trivial_name_change_by_agreer
trivialchanges = {
"Oxford St" => "Oxford Street",
"Johnann Wolfgang von Goethe Allee" => "Johann-Wolfgang-von-Goethe-Allee",
"Mulberry Hiway" => "Mulberry Highway",
"old fen way" => "Old Fen Way",
"Lodnon" => "London",
"strasse" => "Straße",
"Supercalifragilisticexpialidocious Stret" => "Supercalifragilisticexpialidocious Street"
}
trivialchanges.each do | old, new |
assert_equal(false, Tags.significant_tag?(old, new), "#{old.inspect} -> #{new.inspect} not considered trivial.")
history = [OSM::Node[[0,0], :id => 1, :changeset => 1, :version => 1],
OSM::Node[[0,0], :id => 1, :changeset => 3, :version => 2,
"name" => old],
OSM::Node[[0,0], :id => 1, :changeset => 2, :version => 3,
"name" => new]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Node[[0,0], :id => 1, :changeset => -1, :version => 3]],
Redact[OSM::Node, 1, 2, :hidden],
Redact[OSM::Node, 1, 3, :visible],
], actions)
end
end
# This is the reverse of trivial_name_change_by_agreer:
# * agreer creates object
# * agreer adds a name tag
# * decliner makes a trivial change to that tag
# * therefore the agreer retains "ownership" and the tag can be retained.
# (the assumption here is that the trvial change is not deserving
# of copyright or any other protection - that it could be done by
# an automated process)
def test_trivial_name_change_by_decliner
trivial_changes = {
"Oxford St" => "Oxford Street",
"Johnann Wolfgang von Goethe Allee" => "Johann-Wolfgang-von-Goethe-Allee",
"Mulberry Hiway" => "Mulberry Highway",
"old fen way" => "Old Fen Way",
"Lodnon" => "London",
"strasse" => "Straße",
"Supercalifragilisticexpialidocious Stret" => "Supercalifragilisticexpialidocious Street"
}
trivial_changes.each do |old, new|
assert_equal(false, Tags.significant_tag?(old, new), "#{old.inspect} -> #{new.inspect} not considered trivial.")
expect_redaction([], # expect no redactions here...
[[true, {}],
[true, {"name" => old}],
[false, {"name" => new}]
])
end
end
# Scenario:
# * agreer creates object
# * agreer adds a tag
# * decliner makes a trivial change to the key, keeping the value the same
# as before, the trivial change is not deserving of protection, so the
# change will be kept.
def test_trivial_key_change_by_decliner
trivial_changes = {
"nmae" => "name",
"addr:hosenumber" => "addr:housenumber",
"addr_housenumber" => "addr:housenumber",
"addr:housenummer" => "addr:housenumber"
}
trivial_changes.each do |old, new|
assert_equal(false, Tags.significant_tag?(old, new), "#{old.inspect} -> #{new.inspect} not considered trivial.")
expect_redaction([],
[[true, {}],
[true, {old => "some value here"}],
[false, {new => "some value here"}]
])
end
end
# This tests the following scenario:
# * agreer creates object
# * decliner adds a name tag
# * agreer makes a significant change to that tag
# * therefore the decliner's change must be rolled back.
def test_significant_name_change_by_decliner
significant_changes = {
"Oxford St" => "Bedford St",
"Johnann Wolfgang von Goethe Allee" => "Johann-Sebastian-Bach-Allee",
"Mulberry Hiway" => "Blueberry Valley Drive",
"улица Интернацион" => "улица Бешенковичи",
}
significant_changes.each do |old, new|
# check that the method considers them actually significant first...
assert_equal(true, Tags.significant_tag?(old, new), "#{old.inspect} -> #{new.inspect} not considered significant.")
expect_redaction([[2, :hidden]],
[[true, {}],
[false, {"name" => old}],
[true, {"name" => new}]
])
end
end
# This tests the following scenario:
# * agreer creates object
# * agreer adds a name tag
# * decliner makes a significant change to that tag
# * therefore the tag must be rolled back to before the significant change
def test_significant_name_change_by_agreer
significantchanges = {
"Oxford St" => "Bedford St",
"Johnann Wolfgang von Goethe Allee" => "Johann-Sebastian-Bach-Allee",
"Mulberry Hiway" => "Blueberry Valley Drive",
"Wellington Avenue" => "Wellington Way",
}
significantchanges.each do | old, new |
assert_equal(true, Tags.significant_tag?(old, new), "#{old.inspect} -> #{new.inspect} not considered significant.")
history = [OSM::Node[[0,0], :id => 1, :changeset => 1, :version => 1],
OSM::Node[[0,0], :id => 1, :changeset => 2, :version => 2,
"name" => old],
OSM::Node[[0,0], :id => 1, :changeset => 3, :version => 3,
"name" => new]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
# decliner's version hidden but no change to object
assert_equal([Edit[OSM::Node[[0,0], :id => 1, :changeset => -1, :version => 3, "name" => old]],
Redact[OSM::Node, 1, 3, :hidden]
], actions)
end
end
# This tests the following scenario:
# * agreer creates object
# * decliner adds a ref tag
# * agreer makes a trivial change to that tag
# * therefore the decliner retains "ownership" and the tag must be
# removed.
def test_trivial_ref_change_by_agreer
trivialchanges = {
"E16" => "E 16",
"1;R5" => "R1;R5", # This fails, probably because 1 char is a high % of a short string
"1;R5;R6" => "R1;R5;R6", # This passes
"Rv7" => "RV7"
}
trivialchanges.each do | old, new |
assert_equal(false, Tags.significant_tag?(old, new), "#{old.inspect} -> #{new.inspect} not considered trivial.")
history = [OSM::Node[[0,0], :id => 1, :changeset => 1, :version => 1],
OSM::Node[[0,0], :id => 1, :changeset => 3, :version => 2,
"ref" => old],
OSM::Node[[0,0], :id => 1, :changeset => 2, :version => 3,
"ref" => new]]
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal([Edit[OSM::Node[[0,0], :id => 1, :changeset => -1, :version => 3]],
Redact[OSM::Node, 1, 2, :hidden],
Redact[OSM::Node, 1, 3, :visible],
], actions)
end
end
private
def expect_redaction(redacts, tags)
history = Array.new
tags.each_with_index do |e, version|
agreer_edit, t = e
hash = { :id => 1, :changeset => (agreer_edit ? 1 : 3), :version => (version + 1) }
hash.merge!(t)
history << OSM::Node[[0, 0], hash]
end
bot = ChangeBot.new(@db)
actions = bot.action_for(history)
assert_equal(redacts.map {|v,h| Redact[OSM::Node, 1, v, h]}, actions,
"Note: with tag pattern #{tags}")
end
end
if __FILE__ == $0
MiniTest::Unit.new.run(ARGV)
end