kronk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,410 @@
1
+ require 'test/test_helper'
2
+
3
+ class TestDataSet < Test::Unit::TestCase
4
+
5
+
6
+ def setup
7
+ @data = {
8
+ :key1 => {
9
+ :key1a => [
10
+ "foo",
11
+ "bar",
12
+ "foobar",
13
+ {:findme => "thing"}
14
+ ],
15
+ 'key1b' => "findme"
16
+ },
17
+ 'findme' => [
18
+ 123,
19
+ 456,
20
+ {:findme => 123456}
21
+ ],
22
+ :key2 => "foobar",
23
+ :key3 => {
24
+ :key3a => ["val1", "val2", "val3"]
25
+ }
26
+ }
27
+
28
+ @dataset = Kronk::DataSet.new @data
29
+
30
+ @dataset_mock = Kronk::DataSet.new mock_data
31
+ end
32
+
33
+
34
+ def test_collect_data_points_single
35
+ data = @dataset_mock.collect_data_points "subs/1"
36
+ assert_equal({"subs" => [nil, "b"]}, data)
37
+ end
38
+
39
+
40
+ def test_collect_data_points_single_wildcard
41
+ data = @dataset_mock.collect_data_points "root/*/tests"
42
+ assert_equal({"root"=>[nil, nil, nil, {:tests=>["D3a", "D3b"]}]}, data)
43
+ end
44
+
45
+
46
+ def test_collect_data_points_recursive_wildcard
47
+ data = @dataset_mock.collect_data_points "**/test?"
48
+
49
+ expected = {
50
+ "tests"=>{:foo=>:bar, "test"=>[[1, 2], 2.123]},
51
+ "root"=>[nil, nil, nil, {
52
+ :tests=>["D3a", "D3b"],
53
+ "test"=>[["D1a\nContent goes here", "D1b"], "D2"]}]
54
+ }
55
+
56
+ assert_equal expected, data
57
+ end
58
+
59
+
60
+ def test_collect_data_points_recursive_wildcard_value
61
+ data = @dataset_mock.collect_data_points "**=(A|a)?"
62
+
63
+ expected = {
64
+ "root" => [nil, ["A1", "A2"]],
65
+ "subs" => ["a"]
66
+ }
67
+
68
+ assert_equal expected, data
69
+ end
70
+
71
+
72
+ def test_delete_data_points_single
73
+ data = @dataset_mock.delete_data_points "subs/1"
74
+
75
+ expected = mock_data
76
+ expected['subs'].delete_at 1
77
+
78
+ assert_equal expected, data
79
+ end
80
+
81
+
82
+ def test_delete_data_points_single_wildcard
83
+ data = @dataset_mock.delete_data_points "root/*/tests"
84
+
85
+ expected = mock_data
86
+ expected['root'][3].delete :tests
87
+
88
+ assert_equal expected, data
89
+ end
90
+
91
+
92
+ def test_delete_data_points_single_wildcard_qmark
93
+ data = @dataset_mock.delete_data_points "subs/?"
94
+
95
+ expected = mock_data
96
+ expected['subs'].clear
97
+
98
+ assert_equal expected, data
99
+ end
100
+
101
+
102
+ def test_delete_data_points_recursive_wildcard
103
+ data = @dataset_mock.delete_data_points "**/test?"
104
+
105
+ expected = mock_data
106
+ expected['root'][3].delete :tests
107
+ expected['root'][3].delete 'test'
108
+ expected.delete "tests"
109
+
110
+ assert_equal expected, data
111
+ end
112
+
113
+
114
+ def test_delete_data_points_recursive_wildcard_value
115
+ data = @dataset_mock.delete_data_points "**=A?|a?"
116
+
117
+ expected = mock_data
118
+ expected['root'][1].clear
119
+ expected['subs'] = ["b"]
120
+
121
+ assert_equal expected, data
122
+ end
123
+
124
+
125
+ def test_find_data_index
126
+ keys = []
127
+ data_points = []
128
+
129
+ @dataset.find_data "*/*/0|1" do |data, key, path|
130
+ keys << key
131
+ data_points << data
132
+ end
133
+
134
+ assert_equal [0,1,0,1], keys
135
+ assert_equal 2, data_points.count(@data[:key1][:key1a])
136
+ assert_equal 2, data_points.count(@data[:key3][:key3a])
137
+ end
138
+
139
+
140
+ def test_find_data_recursive_wildcard_value
141
+ keys = []
142
+ paths = []
143
+ data_points = []
144
+
145
+ @dataset.find_data "**=foo*" do |data, key, path|
146
+ keys << key
147
+ data_points << data
148
+ paths << path
149
+ end
150
+
151
+ expected_paths = [[:key1,:key1a,0], [:key1,:key1a,2], [:key2]]
152
+
153
+ assert_equal [0,2,:key2], ([0,2,:key2] | keys)
154
+ assert_equal expected_paths, (expected_paths | paths)
155
+ end
156
+
157
+
158
+ def test_find_data_recursive
159
+ keys = []
160
+ paths = []
161
+ data_points = []
162
+
163
+ @dataset.find_data "**/findme" do |data, key, path|
164
+ keys << key.to_s
165
+ data_points << data
166
+ paths << path
167
+ end
168
+
169
+ expected_paths =
170
+ [[:key1,:key1a,3,:findme], ["findme"], ["findme",2,:findme]]
171
+
172
+ assert_equal 3, keys.length
173
+ assert_equal 1, keys.uniq.length
174
+ assert_equal "findme", keys.first
175
+
176
+ assert data_points.include?(@data)
177
+ assert data_points.include?(@data[:key1][:key1a].last)
178
+ assert data_points.include?(@data['findme'].last)
179
+
180
+ assert_equal expected_paths, (expected_paths | paths)
181
+ end
182
+
183
+
184
+ def test_find_data_wildcard
185
+ keys = []
186
+ data_points = []
187
+
188
+ @dataset.find_data "*/key1?" do |data, key, path|
189
+ keys << key.to_s
190
+ data_points << data
191
+ end
192
+
193
+ assert_equal ['key1a', 'key1b'], keys.sort
194
+ assert_equal [@data[:key1], @data[:key1]], data_points
195
+ end
196
+
197
+
198
+ def test_parse_data_path
199
+ data_path = "key1/key\\/2=value/key*=*value/**=value2/key\\=thing"
200
+ key, value, rec, data_path = Kronk::DataSet.parse_data_path data_path
201
+
202
+ assert_equal "key1", key
203
+ assert_nil value
204
+ assert !rec, "Should not return recursive = true"
205
+ assert_equal "key\\/2=value/key*=*value/**=value2/key\\=thing", data_path
206
+ end
207
+
208
+
209
+ def test_parse_data_path_escaped_slash
210
+ key, value, rec, data_path =
211
+ Kronk::DataSet.parse_data_path \
212
+ "key\\/2=value/key*=*value/**=value2/key\\=thing"
213
+
214
+ assert_equal "key/2", key
215
+ assert_equal "value", value
216
+ assert !rec, "Should not return recursive = true"
217
+ assert_equal "key*=*value/**=value2/key\\=thing", data_path
218
+ end
219
+
220
+
221
+ def test_parse_data_path_wildcard
222
+ key, value, rec, data_path = Kronk::DataSet.parse_data_path "*/key1?"
223
+
224
+ assert_equal(/^(.*)$/, key)
225
+ assert_nil value
226
+ assert !rec, "Should not return recursive = true"
227
+ assert_equal "key1?", data_path
228
+ end
229
+
230
+
231
+ def test_parse_data_path_recursive_value
232
+ key, value, rec, data_path =
233
+ Kronk::DataSet.parse_data_path "**=value2/key\\=thing"
234
+
235
+ assert_equal(/.*/, key)
236
+ assert_equal "value2", value
237
+ assert rec, "Should return recursive = true"
238
+ assert_equal "key\\=thing", data_path
239
+ end
240
+
241
+
242
+ def test_parse_data_path_recursive
243
+ data_path = "**"
244
+ key, value, rec, data_path = Kronk::DataSet.parse_data_path "**"
245
+
246
+ assert_equal(/.*/, key)
247
+ assert_nil value
248
+ assert rec, "Should return recursive = true"
249
+ assert_nil data_path
250
+ end
251
+
252
+
253
+ def test_parse_data_path_recursive_key
254
+ data_path = "**"
255
+ key, value, rec, data_path = Kronk::DataSet.parse_data_path "**/key"
256
+
257
+ assert_equal "key", key
258
+ assert_nil value
259
+ assert rec, "Should return recursive = true"
260
+ assert_nil data_path
261
+ end
262
+
263
+
264
+ def test_parse_data_path_escaped_equal
265
+ key, value, rec, data_path = Kronk::DataSet.parse_data_path "key\\=thing"
266
+
267
+ assert_equal "key=thing", key
268
+ assert_nil value
269
+ assert !rec, "Should not return recursive = true"
270
+ assert_equal nil, data_path
271
+ end
272
+
273
+
274
+ def test_parse_data_path_last
275
+ key, value, rec, data_path = Kronk::DataSet.parse_data_path "key*"
276
+
277
+ assert_equal(/^(key.*)$/, key)
278
+ assert_nil value
279
+ assert !rec, "Should not return recursive = true"
280
+ assert_equal nil, data_path
281
+ end
282
+
283
+
284
+ def test_parse_data_path_empty
285
+ key, value, rec, data_path = Kronk::DataSet.parse_data_path ""
286
+
287
+ assert_equal nil, key
288
+ assert_nil value
289
+ assert !rec, "Should not return recursive = true"
290
+ assert_equal nil, data_path
291
+ end
292
+
293
+
294
+ def test_parse_path_item
295
+ assert_equal "foo", Kronk::DataSet.parse_path_item("foo")
296
+
297
+ assert_equal(/^(foo.*bar)$/, Kronk::DataSet.parse_path_item("foo*bar"))
298
+ assert_equal(/^(foo|bar)$/, Kronk::DataSet.parse_path_item("foo|bar"))
299
+ assert_equal(/^(foo.?bar)$/, Kronk::DataSet.parse_path_item("foo?bar"))
300
+
301
+ assert_equal(/^(foo.?\?bar)$/, Kronk::DataSet.parse_path_item("foo?\\?bar"))
302
+ assert_equal(/^(key.*)$/, Kronk::DataSet.parse_path_item("key*"))
303
+
304
+ assert_equal "foo*bar", Kronk::DataSet.parse_path_item("foo\\*bar")
305
+ assert_equal "foo|bar", Kronk::DataSet.parse_path_item("foo\\|bar")
306
+ assert_equal "foo?bar", Kronk::DataSet.parse_path_item("foo\\?bar")
307
+ end
308
+
309
+
310
+ def test_yield_data_points
311
+ keys = []
312
+
313
+ Kronk::DataSet.yield_data_points @data, /key/ do |data, key|
314
+ keys << key.to_s
315
+ assert_equal @data, data
316
+ end
317
+
318
+ assert_equal ['key1', 'key2', 'key3'], keys.sort
319
+ end
320
+
321
+
322
+ def test_yield_data_points_recursive
323
+ keys = []
324
+ data_points = []
325
+
326
+ Kronk::DataSet.yield_data_points @data, :findme, nil, true do |data, key|
327
+ keys << key.to_s
328
+ data_points << data
329
+ end
330
+
331
+ assert_equal 3, keys.length
332
+ assert_equal 1, keys.uniq.length
333
+ assert_equal "findme", keys.first
334
+
335
+ assert_equal 3, data_points.length
336
+ assert data_points.include?(@data)
337
+ assert data_points.include?({:findme => "thing"})
338
+ assert data_points.include?({:findme => 123456})
339
+ end
340
+
341
+
342
+ def test_yield_data_points_value
343
+ keys = []
344
+ data_points = []
345
+
346
+ Kronk::DataSet.yield_data_points @data, nil, "findme" do |data, key|
347
+ keys << key.to_s
348
+ data_points << data
349
+ end
350
+
351
+ assert keys.empty?
352
+ assert data_points.empty?
353
+
354
+ Kronk::DataSet.yield_data_points @data, nil, "findme", true do |data, key|
355
+ keys << key.to_s
356
+ data_points << data
357
+ end
358
+
359
+ assert_equal ['key1b'], keys
360
+ assert_equal [@data[:key1]], data_points
361
+ end
362
+
363
+
364
+ def test_match_data_item
365
+ assert Kronk::DataSet.match_data_item(:key, "key")
366
+ assert Kronk::DataSet.match_data_item("key", :key)
367
+
368
+ assert Kronk::DataSet.match_data_item(/key/, "foo_key")
369
+ assert !Kronk::DataSet.match_data_item("foo_key", /key/)
370
+
371
+ assert Kronk::DataSet.match_data_item(nil, "foo_key")
372
+ assert !Kronk::DataSet.match_data_item("foo_key", nil)
373
+ end
374
+
375
+
376
+ def test_hash_each_data_item
377
+ hash = {
378
+ :a => 1,
379
+ :b => 2,
380
+ :c => 3
381
+ }
382
+
383
+ keys = []
384
+ values = []
385
+
386
+ Kronk::DataSet.each_data_item hash do |key, val|
387
+ keys << key
388
+ values << val
389
+ end
390
+
391
+ assert_equal keys, (keys | hash.keys)
392
+ assert_equal values, (values | hash.values)
393
+ end
394
+
395
+
396
+ def test_array_each_data_item
397
+ ary = [:a, :b, :c]
398
+
399
+ keys = []
400
+ values = []
401
+
402
+ Kronk::DataSet.each_data_item ary do |key, val|
403
+ keys << key
404
+ values << val
405
+ end
406
+
407
+ assert_equal [0,1,2], keys
408
+ assert_equal ary, values
409
+ end
410
+ end
data/test/test_diff.rb ADDED
@@ -0,0 +1,427 @@
1
+ require 'test/test_helper'
2
+
3
+ class TestDiff < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @diff = Kronk::Diff.new mock_302_response, mock_301_response
7
+ end
8
+
9
+
10
+ def test_new_from_data
11
+ other_data = {:foo => :bar}
12
+
13
+ diff = Kronk::Diff.new_from_data mock_data, other_data
14
+
15
+ assert_equal Kronk::Diff.ordered_data_string(mock_data), diff.str1
16
+ assert_equal Kronk::Diff.ordered_data_string(other_data), diff.str2
17
+ end
18
+
19
+
20
+ def test_ordered_data_string
21
+ expected = <<STR
22
+ {
23
+ "acks" => [
24
+ [
25
+ 56,
26
+ 78
27
+ ],
28
+ [
29
+ "12",
30
+ "34"
31
+ ]
32
+ ],
33
+ "root" => [
34
+ [
35
+ "B1",
36
+ "B2"
37
+ ],
38
+ [
39
+ "A1",
40
+ "A2"
41
+ ],
42
+ [
43
+ "C1",
44
+ "C2",
45
+ [
46
+ "C3a",
47
+ "C3b"
48
+ ]
49
+ ],
50
+ {
51
+ "test" => [
52
+ [
53
+ "D1a\\nContent goes here",
54
+ "D1b"
55
+ ],
56
+ "D2"
57
+ ],
58
+ :tests => [
59
+ "D3a",
60
+ "D3b"
61
+ ]
62
+ }
63
+ ],
64
+ "subs" => [
65
+ "a",
66
+ "b"
67
+ ],
68
+ "tests" => {
69
+ "test" => [
70
+ [
71
+ 1,
72
+ 2
73
+ ],
74
+ 2.123
75
+ ],
76
+ :foo => :bar
77
+ }
78
+ }
79
+ STR
80
+
81
+ assert_equal expected.strip, Kronk::Diff.ordered_data_string(mock_data)
82
+ end
83
+
84
+
85
+ def test_ordered_data_string_struct
86
+ expected = <<STR
87
+ {
88
+ "acks" => [
89
+ [
90
+ Fixnum,
91
+ Fixnum
92
+ ],
93
+ [
94
+ String,
95
+ String
96
+ ]
97
+ ],
98
+ "root" => [
99
+ [
100
+ String,
101
+ String
102
+ ],
103
+ [
104
+ String,
105
+ String
106
+ ],
107
+ [
108
+ String,
109
+ String,
110
+ [
111
+ String,
112
+ String
113
+ ]
114
+ ],
115
+ {
116
+ "test" => [
117
+ [
118
+ String,
119
+ String
120
+ ],
121
+ String
122
+ ],
123
+ :tests => [
124
+ String,
125
+ String
126
+ ]
127
+ }
128
+ ],
129
+ "subs" => [
130
+ String,
131
+ String
132
+ ],
133
+ "tests" => {
134
+ "test" => [
135
+ [
136
+ Fixnum,
137
+ Fixnum
138
+ ],
139
+ Float
140
+ ],
141
+ :foo => Symbol
142
+ }
143
+ }
144
+ STR
145
+
146
+ assert_equal expected.strip,
147
+ Kronk::Diff.ordered_data_string(mock_data, true)
148
+ end
149
+
150
+
151
+ def test_create_diff_inverted
152
+ @diff = Kronk::Diff.new mock_301_response, mock_302_response
153
+ assert_equal diff_301_302, @diff.create_diff
154
+ end
155
+
156
+
157
+ def test_create_diff
158
+ assert_equal diff_302_301, @diff.create_diff
159
+ assert_equal @diff.to_a, @diff.create_diff
160
+ assert_equal @diff.to_a, @diff.diff_array
161
+ end
162
+
163
+
164
+ def test_create_diff_no_match
165
+ str1 = "this is str1\nthat shouldn't\nmatch\nany of\nthe\nlines"
166
+ str2 = "this is str2\nwhich should\nalso not match\nany\nof the\nstr1 lines"
167
+
168
+ diff = Kronk::Diff.new str1, str2
169
+ assert_equal [[str1.split("\n"), str2.split("\n")]], diff.create_diff
170
+ end
171
+
172
+
173
+ def test_create_diff_all_match
174
+ str1 = "this is str\nthat should\nmatch\nall of\nthe\nlines"
175
+ str2 = "this is str\nthat should\nmatch\nall of\nthe\nlines"
176
+
177
+ diff = Kronk::Diff.new str1, str2
178
+ assert_equal str1.split("\n"), diff.create_diff
179
+ end
180
+
181
+
182
+ def test_create_diff_all_added
183
+ str1 = "this is str\nthat should\nmatch\nall of\nthe\nlines"
184
+ str2 = "this is str\nmore stuff\nthat should\nmatch\nall of\nthe\nold lines"
185
+
186
+ expected = [
187
+ "this is str",
188
+ [[], ["more stuff"]],
189
+ "that should",
190
+ "match",
191
+ "all of",
192
+ "the",
193
+ [["lines"], ["old lines"]]
194
+ ]
195
+
196
+ diff = Kronk::Diff.new str1, str2
197
+ assert_equal expected, diff.create_diff
198
+ end
199
+
200
+
201
+ def test_create_diff_all_removed
202
+ str1 = "this is str\nmore stuff\nthat should\nmatch\nall of\nthe\nold lines"
203
+ str2 = "this is str\nthat should\nmatch\nall of\nthe\nlines"
204
+
205
+ expected = [
206
+ "this is str",
207
+ [["more stuff"], []],
208
+ "that should",
209
+ "match",
210
+ "all of",
211
+ "the",
212
+ [["old lines"], ["lines"]]
213
+ ]
214
+
215
+ diff = Kronk::Diff.new str1, str2
216
+ assert_equal expected, diff.create_diff
217
+ end
218
+
219
+
220
+ def test_create_diff_multi_removed
221
+ str1 = "this str\nmore stuff\nagain\nshould\nmatch\nall of\nthe\nold lines"
222
+ str2 = "this str\nthat should\nmatch\nall of\nthe\nlines"
223
+
224
+ expected = [
225
+ "this str",
226
+ [["more stuff", "again", "should"], ["that should"]],
227
+ "match",
228
+ "all of",
229
+ "the",
230
+ [["old lines"], ["lines"]]
231
+ ]
232
+
233
+ diff = Kronk::Diff.new str1, str2
234
+ assert_equal expected, diff.create_diff
235
+ end
236
+
237
+
238
+ def test_create_diff_long_end_diff
239
+ str1 = "this str\nis done"
240
+ str2 = "this str\nthat should\nmatch\nall of\nthe\nlines"
241
+
242
+ expected = [
243
+ "this str",
244
+ [["is done"], ["that should", "match", "all of", "the", "lines"]],
245
+ ]
246
+
247
+ diff = Kronk::Diff.new str1, str2
248
+ assert_equal expected, diff.create_diff
249
+ end
250
+
251
+
252
+ def test_create_diff_long_end_diff_inverted
253
+ str1 = "this str\nthat should\nmatch\nall of\nthe\nlines"
254
+ str2 = "this str\nis done"
255
+
256
+ expected = [
257
+ "this str",
258
+ [["that should", "match", "all of", "the", "lines"], ["is done"]],
259
+ ]
260
+
261
+ diff = Kronk::Diff.new str1, str2
262
+ assert_equal expected, diff.create_diff
263
+ end
264
+
265
+
266
+ def test_create_diff_long
267
+ str1 = "this str"
268
+ str2 = "this str\nthat should\nmatch\nall of\nthe\nlines"
269
+
270
+ expected = [
271
+ "this str",
272
+ [[], ["that should", "match", "all of", "the", "lines"]],
273
+ ]
274
+
275
+ diff = Kronk::Diff.new str1, str2
276
+ assert_equal expected, diff.create_diff
277
+ end
278
+
279
+
280
+ def test_create_diff_long_inverted
281
+ str1 = "this str\nthat should\nmatch\nall of\nthe\nlines"
282
+ str2 = "this str"
283
+
284
+ expected = [
285
+ "this str",
286
+ [["that should", "match", "all of", "the", "lines"], []],
287
+ ]
288
+
289
+ diff = Kronk::Diff.new str1, str2
290
+ assert_equal expected, diff.create_diff
291
+ end
292
+
293
+
294
+ def test_formatted
295
+ assert_equal diff_302_301_str, @diff.formatted
296
+ end
297
+
298
+
299
+ def test_formatted_color
300
+ assert_equal diff_302_301_color, @diff.formatted(:color_diff)
301
+
302
+ @diff.format = :color_diff
303
+ assert_equal diff_302_301_color, @diff.formatted
304
+ end
305
+
306
+
307
+ def test_formatted_join_char
308
+ expected = diff_302_301_str.gsub(/\n/, "\r\n")
309
+ assert_equal expected, @diff.formatted(:ascii_diff, "\r\n")
310
+ end
311
+
312
+
313
+ def test_formatted_block
314
+ str_diff = @diff.formatted do |item|
315
+ if Array === item
316
+ item[0].map!{|str| "<<<302<<< #{str}"}
317
+ item[1].map!{|str| ">>>301>>> #{str}"}
318
+ item
319
+ else
320
+ item.to_s
321
+ end
322
+ end
323
+
324
+ expected = diff_302_301_str.gsub(/^\+/, ">>>301>>>")
325
+ expected = expected.gsub(/^\-/, "<<<302<<<")
326
+ expected = expected.gsub(/^\s\s/, "")
327
+
328
+ assert_equal expected, str_diff
329
+ end
330
+
331
+ private
332
+
333
+ def diff_302_301
334
+ [[["HTTP/1.1 302 Found", "Location: http://igoogle.com/"],
335
+ ["HTTP/1.1 301 Moved Permanently", "Location: http://www.google.com/"]],
336
+ "Content-Type: text/html; charset=UTF-8",
337
+ "Date: Fri, 26 Nov 2010 16:14:45 GMT",
338
+ "Expires: Sun, 26 Dec 2010 16:14:45 GMT",
339
+ "Cache-Control: public, max-age=2592000",
340
+ "Server: gws",
341
+ [["Content-Length: 260"], ["Content-Length: 219"]],
342
+ "X-XSS-Protection: 1; mode=block",
343
+ "",
344
+ "<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">",
345
+ [["<TITLE>302 Found</TITLE></HEAD><BODY>", "<H1>302 Found</H1>"],
346
+ ["<TITLE>301 Moved</TITLE></HEAD><BODY>", "<H1>301 Moved</H1>"]],
347
+ "The document has moved", "<A HREF=\"http://www.google.com/\">here</A>.",
348
+ [["<A HREF=\"http://igoogle.com/\">here</A>."], []],
349
+ "</BODY></HTML>"]
350
+ end
351
+
352
+ def diff_301_302
353
+ [[["HTTP/1.1 301 Moved Permanently", "Location: http://www.google.com/"],
354
+ ["HTTP/1.1 302 Found", "Location: http://igoogle.com/"]],
355
+ "Content-Type: text/html; charset=UTF-8",
356
+ "Date: Fri, 26 Nov 2010 16:14:45 GMT",
357
+ "Expires: Sun, 26 Dec 2010 16:14:45 GMT",
358
+ "Cache-Control: public, max-age=2592000",
359
+ "Server: gws",
360
+ [["Content-Length: 219"], ["Content-Length: 260"]],
361
+ "X-XSS-Protection: 1; mode=block",
362
+ "",
363
+ "<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">",
364
+ [["<TITLE>301 Moved</TITLE></HEAD><BODY>", "<H1>301 Moved</H1>"],
365
+ ["<TITLE>302 Found</TITLE></HEAD><BODY>", "<H1>302 Found</H1>"]],
366
+ "The document has moved", "<A HREF=\"http://www.google.com/\">here</A>.",
367
+ [[], ["<A HREF=\"http://igoogle.com/\">here</A>."]],
368
+ "</BODY></HTML>"]
369
+ end
370
+
371
+
372
+ def diff_302_301_str
373
+ str = <<STR
374
+ - HTTP/1.1 302 Found
375
+ - Location: http://igoogle.com/
376
+ + HTTP/1.1 301 Moved Permanently
377
+ + Location: http://www.google.com/
378
+ Content-Type: text/html; charset=UTF-8
379
+ Date: Fri, 26 Nov 2010 16:14:45 GMT
380
+ Expires: Sun, 26 Dec 2010 16:14:45 GMT
381
+ Cache-Control: public, max-age=2592000
382
+ Server: gws
383
+ - Content-Length: 260
384
+ + Content-Length: 219
385
+ X-XSS-Protection: 1; mode=block
386
+
387
+ <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
388
+ - <TITLE>302 Found</TITLE></HEAD><BODY>
389
+ - <H1>302 Found</H1>
390
+ + <TITLE>301 Moved</TITLE></HEAD><BODY>
391
+ + <H1>301 Moved</H1>
392
+ The document has moved
393
+ <A HREF="http://www.google.com/">here</A>.
394
+ - <A HREF="http://igoogle.com/">here</A>.
395
+ </BODY></HTML>
396
+ STR
397
+ str.strip
398
+ end
399
+
400
+ def diff_302_301_color
401
+ str = <<STR
402
+ \033[31mHTTP/1.1 302 Found\033[0m
403
+ \033[31mLocation: http://igoogle.com/\033[0m
404
+ \033[32mHTTP/1.1 301 Moved Permanently\033[0m
405
+ \033[32mLocation: http://www.google.com/\033[0m
406
+ Content-Type: text/html; charset=UTF-8
407
+ Date: Fri, 26 Nov 2010 16:14:45 GMT
408
+ Expires: Sun, 26 Dec 2010 16:14:45 GMT
409
+ Cache-Control: public, max-age=2592000
410
+ Server: gws
411
+ \033[31mContent-Length: 260\033[0m
412
+ \033[32mContent-Length: 219\033[0m
413
+ X-XSS-Protection: 1; mode=block
414
+
415
+ <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
416
+ \033[31m<TITLE>302 Found</TITLE></HEAD><BODY>\033[0m
417
+ \033[31m<H1>302 Found</H1>\033[0m
418
+ \033[32m<TITLE>301 Moved</TITLE></HEAD><BODY>\033[0m
419
+ \033[32m<H1>301 Moved</H1>\033[0m
420
+ The document has moved
421
+ <A HREF="http://www.google.com/">here</A>.
422
+ \033[31m<A HREF="http://igoogle.com/">here</A>.\033[0m
423
+ </BODY></HTML>
424
+ STR
425
+ str.strip
426
+ end
427
+ end