docdiff 0.6.5 → 0.6.6

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -7
  3. data/Guardfile +4 -4
  4. data/Makefile +1 -1
  5. data/Rakefile +6 -6
  6. data/bin/docdiff +1 -1
  7. data/devutil/Rakefile +12 -5
  8. data/devutil/char_by_charclass.rb +43 -20
  9. data/devutil/charclass_by_char.rb +40 -19
  10. data/devutil/jis0208.rb +263 -231
  11. data/devutil/jis0208_test.rb +196 -0
  12. data/doc/news.md +8 -0
  13. data/docdiff.gemspec +12 -10
  14. data/lib/doc_diff.rb +59 -60
  15. data/lib/docdiff/charstring.rb +225 -241
  16. data/lib/docdiff/cli.rb +285 -250
  17. data/lib/docdiff/diff/contours.rb +1 -1
  18. data/lib/docdiff/diff/editscript.rb +1 -1
  19. data/lib/docdiff/diff/rcsdiff.rb +1 -1
  20. data/lib/docdiff/diff/shortestpath.rb +1 -1
  21. data/lib/docdiff/diff/speculative.rb +1 -1
  22. data/lib/docdiff/diff/subsequence.rb +1 -1
  23. data/lib/docdiff/diff/unidiff.rb +1 -1
  24. data/lib/docdiff/diff.rb +1 -1
  25. data/lib/docdiff/difference.rb +71 -70
  26. data/lib/docdiff/document.rb +129 -109
  27. data/lib/docdiff/encoding/en_ascii.rb +64 -58
  28. data/lib/docdiff/encoding/ja_eucjp.rb +250 -235
  29. data/lib/docdiff/encoding/ja_sjis.rb +240 -226
  30. data/lib/docdiff/encoding/ja_utf8.rb +6952 -6939
  31. data/lib/docdiff/version.rb +1 -1
  32. data/lib/docdiff/view.rb +522 -438
  33. data/lib/docdiff.rb +2 -2
  34. data/test/charstring_test.rb +475 -351
  35. data/test/cli_test.rb +103 -101
  36. data/test/diff_test.rb +15 -16
  37. data/test/difference_test.rb +40 -31
  38. data/test/docdiff_test.rb +162 -136
  39. data/test/document_test.rb +280 -175
  40. data/test/test_helper.rb +2 -1
  41. data/test/view_test.rb +636 -497
  42. metadata +8 -8
  43. data/devutil/testjis0208.rb +0 -38
data/test/cli_test.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/ruby
2
2
  # -*- coding: utf-8; -*-
3
3
 
4
- require 'test/unit'
5
- require 'nkf'
6
- require 'docdiff/cli'
4
+ require "test/unit"
5
+ require "nkf"
6
+ require "docdiff/cli"
7
7
 
8
- class TC_CLI < Test::Unit::TestCase
9
- def test_parse_options!()
8
+ class TestCLI < Test::Unit::TestCase
9
+ def test_parse_options!
10
10
  args = [
11
11
  "--resolution=line",
12
12
  "--char",
@@ -27,49 +27,51 @@ class TC_CLI < Test::Unit::TestCase
27
27
  "file2",
28
28
  ]
29
29
  expected = {
30
- :resolution => "char",
31
- :encoding => "EUC-JP",
32
- :eol => "CRLF",
33
- :format => "wdiff",
34
- :digest => true,
35
- :label => ["old", "new"],
36
- :display => "block",
37
- :pager => "'less --raw-control-chars'",
38
- :no_config_file => true,
39
- :config_file => "./docdiff.conf",
30
+ resolution: "char",
31
+ encoding: "EUC-JP",
32
+ eol: "CRLF",
33
+ format: "wdiff",
34
+ digest: true,
35
+ label: ["old", "new"],
36
+ display: "block",
37
+ pager: "'less --raw-control-chars'",
38
+ no_config_file: true,
39
+ config_file: "./docdiff.conf",
40
40
  }
41
41
  assert_equal(expected, DocDiff::CLI.parse_options!(args, base_options: {}))
42
42
  end
43
43
 
44
- def test_parse_config_file_content()
45
- content = ["# comment line\n",
46
- " # comment line with leading space\n",
47
- "foo1 = bar\n",
48
- "foo2 = bar baz \n",
49
- " foo3 = 123 # comment\n",
50
- "foo4 = no \n",
51
- "foo1 = tRue\n",
52
- "\n",
53
- "",
54
- nil].join
55
- expected = {:foo1=>true, :foo2=>"bar baz", :foo3=>123, :foo4=>false}
44
+ def test_parse_config_file_content
45
+ content = [
46
+ "# comment line\n",
47
+ " # comment line with leading space\n",
48
+ "foo1 = bar\n",
49
+ "foo2 = bar baz \n",
50
+ " foo3 = 123 # comment\n",
51
+ "foo4 = no \n",
52
+ "foo1 = tRue\n",
53
+ "\n",
54
+ "",
55
+ nil,
56
+ ].join
57
+ expected = { foo1: true, foo2: "bar baz", foo3: 123, foo4: false }
56
58
  assert_equal(expected, DocDiff::CLI.parse_config_file_content(content))
57
59
  end
58
60
 
59
- def test_read_config_from_file()
61
+ def test_read_config_from_file
60
62
  filename = File.join(File.dirname(__FILE__), "fixture/simple.conf")
61
- expected = {:foo1 => true, :foo2 => "bar baz", :foo3 => 123, :foo4 => false}
63
+ expected = { foo1: true, foo2: "bar baz", foo3: 123, foo4: false }
62
64
  config, _message = DocDiff::CLI.read_config_from_file(filename)
63
65
  assert_equal(expected, config)
64
66
  end
65
67
 
66
- def test_read_config_from_file_raises_exception()
68
+ def test_read_config_from_file_raises_exception
67
69
  assert_raise(Errno::ENOENT) do
68
- config, message = DocDiff::CLI.read_config_from_file("no/such/file")
70
+ _config, _message = DocDiff::CLI.read_config_from_file("no/such/file")
69
71
  end
70
72
  end
71
73
 
72
- def test_cli_resolution_line()
74
+ def test_cli_resolution_line
73
75
  expected = <<~EOS.chomp
74
76
  [-Hello, my name is Watanabe.
75
77
  I am just another Ruby porter.
@@ -77,146 +79,146 @@ class TC_CLI < Test::Unit::TestCase
77
79
  It's me who has created Ruby. I am a Ruby hacker.
78
80
  +}
79
81
  EOS
80
- cmd = "ruby -I lib bin/docdiff --resolution=line --format=wdiff" +
81
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
82
+ cmd = "ruby -I lib bin/docdiff --resolution=line --format=wdiff " \
83
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
82
84
  actual = `#{cmd}`
83
85
  assert_equal(expected, actual)
84
86
  end
85
87
 
86
- def test_cli_resolution_word()
88
+ def test_cli_resolution_word
87
89
  expected = <<~EOS
88
90
  Hello, my name is [-Watanabe.-]{+matz.+}
89
91
  {+It's me who has created Ruby. +}I am [-just another -]{+a +}Ruby [-porter.-]{+hacker.+}
90
92
  EOS
91
- cmd = "ruby -I lib bin/docdiff --resolution=word --format=wdiff" +
92
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
93
+ cmd = "ruby -I lib bin/docdiff --resolution=word --format=wdiff " \
94
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
93
95
  actual = `#{cmd}`
94
96
  assert_equal(expected, actual)
95
97
  end
96
98
 
97
- def test_cli_resolution_char()
99
+ def test_cli_resolution_char
98
100
  expected = <<~EOS
99
101
  Hello, my name is [-W-]{+m+}at[-anabe-]{+z+}.
100
102
  {+It's me who has created Ruby. +}I am [-just -]a[-nother-] Ruby [-port-]{+hack+}er.
101
103
  EOS
102
- cmd = "ruby -I lib bin/docdiff --resolution=char --format=wdiff" +
103
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
104
+ cmd = "ruby -I lib bin/docdiff --resolution=char --format=wdiff " \
105
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
104
106
  actual = `#{cmd}`
105
107
  assert_equal(expected, actual)
106
108
  end
107
109
 
108
- def test_cli_encoding_ascii()
110
+ def test_cli_encoding_ascii
109
111
  expected = <<~EOS
110
112
  Hello, my name is [-Watanabe.-]{+matz.+}
111
113
  {+It's me who has created Ruby. +}I am [-just another -]{+a +}Ruby [-porter.-]{+hacker.+}
112
114
  EOS
113
- cmd = "ruby -I lib bin/docdiff --encoding=ASCII --format=wdiff" +
114
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
115
+ cmd = "ruby -I lib bin/docdiff --encoding=ASCII --format=wdiff " \
116
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
115
117
  actual = `#{cmd}`
116
118
  assert_equal(expected, actual)
117
119
  end
118
120
 
119
- def test_cli_encoding_euc_jp()
121
+ def test_cli_encoding_euc_jp
120
122
  expected = NKF.nkf("--ic=UTF-8 --oc=EUC-JP", <<~EOS)
121
123
  [-こんにちは-]{+こんばんは+}、私の[-名前はわたなべです-]{+名前はまつもとです+}。
122
124
  {+Rubyを作ったのは私です。+}私は[-Just Another -]Ruby [-Porter-]{+Hacker+}です。
123
125
  EOS
124
- cmd = "ruby --external-encoding EUC-JP -I lib bin/docdiff --encoding=EUC-JP --format=wdiff" +
125
- " test/fixture/01_ja_eucjp_lf.txt test/fixture/02_ja_eucjp_lf.txt"
126
+ cmd = "ruby --external-encoding EUC-JP -I lib bin/docdiff --encoding=EUC-JP --format=wdiff " \
127
+ "test/fixture/01_ja_eucjp_lf.txt test/fixture/02_ja_eucjp_lf.txt"
126
128
  actual = `#{cmd}`.force_encoding("EUC-JP")
127
129
  assert_equal(expected, actual)
128
130
  end
129
131
 
130
- def test_cli_encoding_shift_jis()
132
+ def test_cli_encoding_shift_jis
131
133
  expected_utf8_cr =
132
- "[-こんにちは-]{+こんばんは+}、私の[-名前はわたなべです-]{+名前はまつもとです+}。\r" +
133
- "{+Rubyを作ったのは私です。+}私は[-Just Another -]Ruby [-Porter-]{+Hacker+}です。\r"
134
+ "[-こんにちは-]{+こんばんは+}、私の[-名前はわたなべです-]{+名前はまつもとです+}。\r" \
135
+ "{+Rubyを作ったのは私です。+}私は[-Just Another -]Ruby [-Porter-]{+Hacker+}です。\r"
134
136
  expected = NKF.nkf("--ic=UTF-8 --oc=Shift_JIS", expected_utf8_cr)
135
- cmd = "ruby --external-encoding Shift_JIS -I lib bin/docdiff --encoding=Shift_JIS --format=wdiff" +
136
- " test/fixture/01_ja_sjis_cr.txt test/fixture/02_ja_sjis_cr.txt"
137
+ cmd = "ruby --external-encoding Shift_JIS -I lib bin/docdiff --encoding=Shift_JIS --format=wdiff " \
138
+ "test/fixture/01_ja_sjis_cr.txt test/fixture/02_ja_sjis_cr.txt"
137
139
  actual = `#{cmd}`.force_encoding("Shift_JIS")
138
140
  assert_equal(expected, actual)
139
141
  end
140
142
 
141
- def test_cli_encoding_utf_8()
143
+ def test_cli_encoding_utf_8
142
144
  expected = <<~EOS
143
145
  [-こんにちは-]{+こんばんは+}、私の[-名前はわたなべです-]{+名前はまつもとです+}。
144
146
  {+Rubyを作ったのは私です。+}私は[-Just Another -]Ruby [-Porter-]{+Hacker+}です。
145
147
  EOS
146
- cmd = "ruby -I lib bin/docdiff --encoding=UTF-8 --format=wdiff" +
147
- " test/fixture/01_ja_utf8_lf.txt test/fixture/02_ja_utf8_lf.txt"
148
+ cmd = "ruby -I lib bin/docdiff --encoding=UTF-8 --format=wdiff " \
149
+ "test/fixture/01_ja_utf8_lf.txt test/fixture/02_ja_utf8_lf.txt"
148
150
  actual = `#{cmd}`.force_encoding("UTF-8")
149
151
  assert_equal(expected, actual)
150
152
  end
151
153
 
152
- def test_cli_eol_cr()
154
+ def test_cli_eol_cr
153
155
  expected =
154
- "Hello, my name is [-Watanabe.-]{+matz.+}\r" +
155
- "{+It's me who has created Ruby. +}I am [-just another -]{+a +}Ruby [-porter.-]{+hacker.+}\r"
156
- cmd = "ruby -I lib bin/docdiff --eol=CR --format=wdiff" +
157
- " test/fixture/01_en_ascii_cr.txt test/fixture/02_en_ascii_cr.txt"
156
+ "Hello, my name is [-Watanabe.-]{+matz.+}\r" \
157
+ "{+It's me who has created Ruby. +}I am [-just another -]{+a +}Ruby [-porter.-]{+hacker.+}\r"
158
+ cmd = "ruby -I lib bin/docdiff --eol=CR --format=wdiff " \
159
+ "test/fixture/01_en_ascii_cr.txt test/fixture/02_en_ascii_cr.txt"
158
160
  actual = `#{cmd}`
159
161
  assert_equal(expected, actual)
160
162
  end
161
163
 
162
- def test_cli_eol_lf()
164
+ def test_cli_eol_lf
163
165
  expected =
164
- "Hello, my name is [-Watanabe.-]{+matz.+}\n" +
165
- "{+It's me who has created Ruby. +}I am [-just another -]{+a +}Ruby [-porter.-]{+hacker.+}\n"
166
- cmd = "ruby -I lib bin/docdiff --eol=LF --format=wdiff" +
167
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
166
+ "Hello, my name is [-Watanabe.-]{+matz.+}\n" \
167
+ "{+It's me who has created Ruby. +}I am [-just another -]{+a +}Ruby [-porter.-]{+hacker.+}\n"
168
+ cmd = "ruby -I lib bin/docdiff --eol=LF --format=wdiff " \
169
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
168
170
  actual = `#{cmd}`
169
171
  assert_equal(expected, actual)
170
172
  end
171
173
 
172
- def test_cli_eol_crlf()
174
+ def test_cli_eol_crlf
173
175
  expected =
174
- "Hello, my name is [-Watanabe.-]{+matz.+}\r\n" +
175
- "{+It's me who has created Ruby. +}I am [-just another -]{+a +}Ruby [-porter.-]{+hacker.+}\r\n"
176
- cmd = "ruby -I lib bin/docdiff --eol=CRLF --format=wdiff" +
177
- " test/fixture/01_en_ascii_crlf.txt test/fixture/02_en_ascii_crlf.txt"
176
+ "Hello, my name is [-Watanabe.-]{+matz.+}\r\n" \
177
+ "{+It's me who has created Ruby. +}I am [-just another -]{+a +}Ruby [-porter.-]{+hacker.+}\r\n"
178
+ cmd = "ruby -I lib bin/docdiff --eol=CRLF --format=wdiff " \
179
+ "test/fixture/01_en_ascii_crlf.txt test/fixture/02_en_ascii_crlf.txt"
178
180
  actual = `#{cmd}`
179
181
  assert_equal(expected, actual)
180
182
  end
181
183
 
182
- def test_cli_format_html()
184
+ def test_cli_format_html
183
185
  expected = <<~EOS
184
186
  <span class="common">Hello, my name is </span>\
185
187
  <span class="before-change"><del>Watanabe.</del></span>\
186
188
  <span class="after-change"><ins>matz.</ins></span>\
187
189
  <span class="common"><br />
188
190
  EOS
189
- cmd = "ruby -I lib bin/docdiff --format=html" +
190
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
191
+ cmd = "ruby -I lib bin/docdiff --format=html " \
192
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
191
193
  actual = `#{cmd}`.scan(/^.*?$\n/m)[-4]
192
194
  assert_equal(expected, actual)
193
195
  end
194
196
 
195
- def test_cli_format_manued()
197
+ def test_cli_format_manued
196
198
  expected = "Hello, my name is [Watanabe./matz.]\n"
197
- cmd = "ruby -I lib bin/docdiff --format=manued" +
198
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
199
+ cmd = "ruby -I lib bin/docdiff --format=manued " \
200
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
199
201
  actual = `#{cmd}`.scan(/^.*?$\n/m)[-2]
200
202
  assert_equal(expected, actual)
201
203
  end
202
204
 
203
- def test_cli_format_tty()
205
+ def test_cli_format_tty
204
206
  expected = "Hello, my name is \e[7;4;33mWatanabe.\e[0m\e[7;1;32mmatz.\e[0m\n"
205
- cmd = "ruby -I lib bin/docdiff --format=tty" +
206
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
207
+ cmd = "ruby -I lib bin/docdiff --format=tty " \
208
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
207
209
  actual = `#{cmd}`.scan(/^.*?$\n/m).first
208
210
  assert_equal(expected, actual)
209
211
  end
210
212
 
211
- def test_cli_format_wdiff()
213
+ def test_cli_format_wdiff
212
214
  expected = "Hello, my name is [-Watanabe.-]{+matz.+}\n"
213
- cmd = "ruby -I lib bin/docdiff --format=wdiff" +
214
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
215
+ cmd = "ruby -I lib bin/docdiff --format=wdiff " \
216
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
215
217
  actual = `#{cmd}`.scan(/^.*?$\n/m).first
216
218
  assert_equal(expected, actual)
217
219
  end
218
220
 
219
- def test_cli_digest()
221
+ def test_cli_digest
220
222
  expected = <<~EOS
221
223
  ----
222
224
  1,1
@@ -225,23 +227,23 @@ class TC_CLI < Test::Unit::TestCase
225
227
  ----
226
228
  (2),2
227
229
 
228
- {+It's me who has created Ruby. +}I am
230
+ {+It's me who has created Ruby. +}I am#{" "}
229
231
  ----
230
232
  2,2
231
- I am [-just another -]{+a +}Ruby
233
+ I am [-just another -]{+a +}Ruby#{" "}
232
234
  ----
233
235
  2,2
234
236
  Ruby [-porter.-]{+hacker.+}
235
237
 
236
238
  ----
237
239
  EOS
238
- cmd = "ruby -I lib bin/docdiff --digest --format=wdiff" +
239
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
240
+ cmd = "ruby -I lib bin/docdiff --digest --format=wdiff " \
241
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
240
242
  actual = `#{cmd}`.force_encoding("UTF-8")
241
243
  assert_equal(expected, actual)
242
244
  end
243
245
 
244
- def test_cli_display_inline()
246
+ def test_cli_display_inline
245
247
  expected = <<~EOS
246
248
  ----
247
249
  1,1
@@ -250,23 +252,23 @@ class TC_CLI < Test::Unit::TestCase
250
252
  ----
251
253
  (2),2
252
254
 
253
- {+It's me who has created Ruby. +}I am
255
+ {+It's me who has created Ruby. +}I am#{" "}
254
256
  ----
255
257
  2,2
256
- I am [-just another -]{+a +}Ruby
258
+ I am [-just another -]{+a +}Ruby#{" "}
257
259
  ----
258
260
  2,2
259
261
  Ruby [-porter.-]{+hacker.+}
260
262
 
261
263
  ----
262
264
  EOS
263
- cmd = "ruby -I lib bin/docdiff --digest --display=inline --format=wdiff" +
264
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
265
+ cmd = "ruby -I lib bin/docdiff --digest --display=inline --format=wdiff " \
266
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
265
267
  actual = `#{cmd}`.force_encoding("UTF-8")
266
268
  assert_equal(expected, actual)
267
269
  end
268
270
 
269
- def test_cli_display_block()
271
+ def test_cli_display_block
270
272
  expected = <<~EOS
271
273
  ----
272
274
  1,1
@@ -277,13 +279,13 @@ class TC_CLI < Test::Unit::TestCase
277
279
  ----
278
280
  (2),2
279
281
 
280
- I am
282
+ I am#{" "}
281
283
 
282
- {+It's me who has created Ruby. +}I am
284
+ {+It's me who has created Ruby. +}I am#{" "}
283
285
  ----
284
286
  2,2
285
- I am [-just another -]Ruby
286
- I am {+a +}Ruby
287
+ I am [-just another -]Ruby#{" "}
288
+ I am {+a +}Ruby#{" "}
287
289
  ----
288
290
  2,2
289
291
  Ruby [-porter.-]
@@ -292,20 +294,20 @@ class TC_CLI < Test::Unit::TestCase
292
294
 
293
295
  ----
294
296
  EOS
295
- cmd = "ruby -I lib bin/docdiff --digest --display=block --format=wdiff" +
296
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
297
+ cmd = "ruby -I lib bin/docdiff --digest --display=block --format=wdiff " \
298
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
297
299
  actual = `#{cmd}`.force_encoding("UTF-8")
298
300
  assert_equal(expected, actual)
299
301
  end
300
302
 
301
- def test_cli_config_file_format_wdiff()
303
+ def test_cli_config_file_format_wdiff
302
304
  config_file_name = File.join(File.dirname(__FILE__), "fixture/format_wdiff.conf")
303
305
  expected = <<~EOS
304
306
  Hello, my name is [-Watanabe.-]{+matz.+}
305
307
  {+It's me who has created Ruby. +}I am [-just another -]{+a +}Ruby [-porter.-]{+hacker.+}
306
308
  EOS
307
- cmd = "ruby -I lib bin/docdiff --config-file=#{config_file_name}" +
308
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
309
+ cmd = "ruby -I lib bin/docdiff --config-file=#{config_file_name} " \
310
+ "test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
309
311
  actual = `#{cmd}`
310
312
  assert_equal(expected, actual)
311
313
  end
data/test/diff_test.rb CHANGED
@@ -1,37 +1,36 @@
1
1
  #!/usr/bin/ruby
2
- require 'test/unit'
2
+ require "test/unit"
3
3
  require "docdiff/diff"
4
4
 
5
- class TC_DocDiff_Diff < Test::Unit::TestCase
5
+ class TestDiff < Test::Unit::TestCase
6
6
  Diff = DocDiff::Diff
7
7
 
8
- def setup()
9
- #
8
+ def setup
10
9
  end
11
10
 
12
- def test_new_ses()
11
+ def test_new_ses
13
12
  a1 = [:a, :b, :c]
14
13
  a2 = [:a, :x, :c]
15
- expected = [[:common_elt_elt, [:a], [:a]],
16
- [:del_elt, [:b], nil],
17
- [:add_elt, nil, [:x]],
18
- [:common_elt_elt, [:c], [:c]]]
14
+ expected = [
15
+ [:common_elt_elt, [:a], [:a]],
16
+ [:del_elt, [:b], nil],
17
+ [:add_elt, nil, [:x]],
18
+ [:common_elt_elt, [:c], [:c]],
19
+ ]
19
20
  actual = []
20
21
  actual_speculative = []
21
22
  actual_shortestpath = []
22
23
  actual_contours = []
23
- Diff.new(a1, a2).ses .each{|e| actual << e}
24
- Diff.new(a1, a2).ses(:speculative ).each{|e| actual_speculative << e}
25
- Diff.new(a1, a2).ses(:shortestpath).each{|e| actual_shortestpath << e}
26
- Diff.new(a1, a2).ses(:contours ).each{|e| actual_contours << e}
24
+ Diff.new(a1, a2).ses.each { |e| actual << e }
25
+ Diff.new(a1, a2).ses(:speculative).each { |e| actual_speculative << e }
26
+ Diff.new(a1, a2).ses(:shortestpath).each { |e| actual_shortestpath << e }
27
+ Diff.new(a1, a2).ses(:contours).each { |e| actual_contours << e }
27
28
  assert_equal(expected, actual)
28
29
  assert_equal(expected, actual_speculative)
29
30
  assert_equal(expected, actual_shortestpath)
30
31
  assert_equal(expected, actual_contours)
31
32
  end
32
33
 
33
- def teardown()
34
- #
34
+ def teardown
35
35
  end
36
-
37
36
  end
@@ -1,65 +1,74 @@
1
1
  #!/usr/bin/ruby
2
- require 'test/unit'
3
- require 'docdiff/difference'
2
+ require "test/unit"
3
+ require "docdiff/difference"
4
4
 
5
- class TC_DocDiff_Difference < Test::Unit::TestCase
5
+ class TestDifference < Test::Unit::TestCase
6
6
  Difference = DocDiff::Difference
7
7
 
8
- def setup()
9
- #
8
+ def setup
10
9
  end
11
10
 
12
- def test_new()
11
+ def test_new
13
12
  array1 = [:a, :b, :c]
14
13
  array2 = [:a, :x, :c]
15
- expected = [[:common_elt_elt, [:a], [:a]],
16
- [:change_elt, [:b], [:x]],
17
- [:common_elt_elt, [:c], [:c]]]
14
+ expected = [
15
+ [:common_elt_elt, [:a], [:a]],
16
+ [:change_elt, [:b], [:x]],
17
+ [:common_elt_elt, [:c], [:c]],
18
+ ]
18
19
  assert_equal(expected, Difference.new(array1, array2))
19
20
  end
20
21
 
21
- def test_raw_list()
22
+ def test_raw_list
22
23
  array1 = [:a, :b, :c]
23
24
  array2 = [:a, :x, :c]
24
- expected = [[:common_elt_elt, [:a], [:a]],
25
- [:del_elt, [:b], nil],
26
- [:add_elt, nil, [:x]],
27
- [:common_elt_elt, [:c], [:c]]]
25
+ expected = [
26
+ [:common_elt_elt, [:a], [:a]],
27
+ [:del_elt, [:b], nil],
28
+ [:add_elt, nil, [:x]],
29
+ [:common_elt_elt, [:c], [:c]],
30
+ ]
28
31
  assert_equal(expected, Difference.new(array1, array2).raw_list)
29
32
  end
30
33
 
31
- def test_former_only()
34
+ def test_former_only
32
35
  array1 = [:a, :b, :c]
33
36
  array2 = [:a, :x, :c]
34
- expected = [[:common_elt_elt, [:a], [:a]],
35
- [:change_elt, [:b], nil],
36
- [:common_elt_elt, [:c], [:c]]]
37
+ expected = [
38
+ [:common_elt_elt, [:a], [:a]],
39
+ [:change_elt, [:b], nil],
40
+ [:common_elt_elt, [:c], [:c]],
41
+ ]
37
42
  assert_equal(expected, Difference.new(array1, array2).former_only)
38
43
  array1 = [:a, :b, :c]
39
44
  array2 = [:a, :c, :d]
40
- expected = [[:common_elt_elt, [:a], [:a]],
41
- [:del_elt, [:b], nil],
42
- [:common_elt_elt, [:c], [:c]]]
45
+ expected = [
46
+ [:common_elt_elt, [:a], [:a]],
47
+ [:del_elt, [:b], nil],
48
+ [:common_elt_elt, [:c], [:c]],
49
+ ]
43
50
  assert_equal(expected, Difference.new(array1, array2).former_only)
44
51
  end
45
52
 
46
- def test_latter_only()
53
+ def test_latter_only
47
54
  array1 = [:a, :b, :c]
48
55
  array2 = [:a, :x, :c]
49
- expected = [[:common_elt_elt, [:a], [:a]],
50
- [:change_elt, nil, [:x]],
51
- [:common_elt_elt, [:c], [:c]]]
56
+ expected = [
57
+ [:common_elt_elt, [:a], [:a]],
58
+ [:change_elt, nil, [:x]],
59
+ [:common_elt_elt, [:c], [:c]],
60
+ ]
52
61
  assert_equal(expected, Difference.new(array1, array2).latter_only)
53
62
  array1 = [:a, :b, :c]
54
63
  array2 = [:a, :c, :d]
55
- expected = [[:common_elt_elt, [:a], [:a]],
56
- [:common_elt_elt, [:c], [:c]],
57
- [:add_elt, nil, [:d]]]
64
+ expected = [
65
+ [:common_elt_elt, [:a], [:a]],
66
+ [:common_elt_elt, [:c], [:c]],
67
+ [:add_elt, nil, [:d]],
68
+ ]
58
69
  assert_equal(expected, Difference.new(array1, array2).latter_only)
59
70
  end
60
71
 
61
- def teardown()
62
- #
72
+ def teardown
63
73
  end
64
-
65
74
  end