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/docdiff_test.rb CHANGED
@@ -3,177 +3,203 @@
3
3
 
4
4
  # frozen_string_literal: false
5
5
 
6
- require 'test/unit'
7
- require 'docdiff'
8
- require 'nkf'
6
+ require "test/unit"
7
+ require "docdiff"
8
+ require "nkf"
9
9
 
10
- class TC_DocDiff < Test::Unit::TestCase
10
+ class TestDocDiff < Test::Unit::TestCase
11
11
  Document = DocDiff::Document
12
12
 
13
- def setup()
14
- #
13
+ def setup
15
14
  end
16
15
 
17
- def test_compare_by_line()
18
- doc1 = Document.new("Foo bar.\nBaz quux.", 'US-ASCII', 'LF')
19
- doc2 = Document.new("Foo.\nBaz quux.", 'US-ASCII', 'LF')
16
+ def test_compare_by_line
17
+ doc1 = Document.new("Foo bar.\nBaz quux.", "US-ASCII", "LF")
18
+ doc2 = Document.new("Foo.\nBaz quux.", "US-ASCII", "LF")
20
19
  docdiff = DocDiff.new
21
- expected = [[:change_elt, ["Foo bar.\n"], ["Foo.\n"]],
22
- [:common_elt_elt, ['Baz quux.'], ['Baz quux.']]]
20
+ expected = [
21
+ [:change_elt, ["Foo bar.\n"], ["Foo.\n"]],
22
+ [:common_elt_elt, ["Baz quux."], ["Baz quux."]],
23
+ ]
23
24
  assert_equal(expected, docdiff.compare_by_line(doc1, doc2))
24
25
  end
25
- def test_compare_by_line_word()
26
- doc1 = Document.new("a b c d\ne f", 'US-ASCII', 'LF')
27
- doc2 = Document.new("a x c d\ne f", 'US-ASCII', 'LF')
26
+
27
+ def test_compare_by_line_word
28
+ doc1 = Document.new("a b c d\ne f", "US-ASCII", "LF")
29
+ doc2 = Document.new("a x c d\ne f", "US-ASCII", "LF")
28
30
  docdiff = DocDiff.new
29
- expected = [[:common_elt_elt, ["a "], ["a "]],
30
- [:change_elt, ["b "], ["x "]],
31
- [:common_elt_elt, ["c ", "d", "\n"], ["c ", "d", "\n"]],
32
- [:common_elt_elt, ["e f"], ["e f"]]]
33
- assert_equal(expected,
34
- docdiff.compare_by_line_word(doc1, doc2))
31
+ expected = [
32
+ [:common_elt_elt, ["a "], ["a "]],
33
+ [:change_elt, ["b "], ["x "]],
34
+ [:common_elt_elt, ["c ", "d", "\n"], ["c ", "d", "\n"]],
35
+ [:common_elt_elt, ["e f"], ["e f"]],
36
+ ]
37
+ assert_equal(expected, docdiff.compare_by_line_word(doc1, doc2))
35
38
  end
36
- def test_compare_by_line_word_char()
37
- doc1 = Document.new("foo bar\nbaz", 'US-ASCII', 'LF')
38
- doc2 = Document.new("foo beer\nbaz", 'US-ASCII', 'LF')
39
+
40
+ def test_compare_by_line_word_char
41
+ doc1 = Document.new("foo bar\nbaz", "US-ASCII", "LF")
42
+ doc2 = Document.new("foo beer\nbaz", "US-ASCII", "LF")
39
43
  docdiff = DocDiff.new
40
- expected = [[:common_elt_elt, ['foo '], ['foo ']],
41
- [:common_elt_elt, ['b'], ['b']],
42
- [:change_elt, ['a'], ['e', 'e']],
43
- [:common_elt_elt, ['r'], ['r']],
44
- [:common_elt_elt, ["\n"], ["\n"]],
45
- [:common_elt_elt, ['baz'], ['baz']]]
46
- assert_equal(expected,
47
- docdiff.compare_by_line_word_char(doc1, doc2))
44
+ expected = [
45
+ [:common_elt_elt, ["foo "], ["foo "]],
46
+ [:common_elt_elt, ["b"], ["b"]],
47
+ [:change_elt, ["a"], ["e", "e"]],
48
+ [:common_elt_elt, ["r"], ["r"]],
49
+ [:common_elt_elt, ["\n"], ["\n"]],
50
+ [:common_elt_elt, ["baz"], ["baz"]],
51
+ ]
52
+ assert_equal(expected, docdiff.compare_by_line_word_char(doc1, doc2))
48
53
  end
49
54
 
50
- def test_run_line_html()
51
- doc1 = Document.new("foo bar\nbaz", 'US-ASCII', 'LF')
52
- doc2 = Document.new("foo beer\nbaz", 'US-ASCII', 'LF')
55
+ def test_run_line_html
56
+ doc1 = Document.new("foo bar\nbaz", "US-ASCII", "LF")
57
+ doc2 = Document.new("foo beer\nbaz", "US-ASCII", "LF")
53
58
  docdiff = DocDiff.new
54
- expected = '<?xml version="1.0" encoding="US-ASCII"?>' + "\n" +
55
- '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"' + "\n" +
56
- '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' + "\n" +
57
- '<html><head>' + "\n" +
58
- '<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII" />' + "\n" +
59
- '<title>Difference</title>' + "\n" +
60
- '<style type="text/css">' + "\n" +
61
- ' body {font-family: monospace;}' + "\n" +
62
- ' span.del {background: hotpink; border: thin inset;}' + "\n" +
63
- ' span.add {background: deepskyblue; font-weight: bolder; border: thin outset;}' + "\n" +
64
- ' span.before-change {background: yellow; border: thin inset;}' + "\n" +
65
- ' span.after-change {background: lime; font-weight: bolder; border: thin outset;}' + "\n" +
66
- " li.entry .position {font-weight: bolder; margin-top: 0em; margin-bottom: 0em; padding-top: 0.5em; padding-bottom: 0em;}\n" +
67
- " li.entry .body {margin-top: 0em; margin-bottom: 0em; padding-top: 0em; padding-bottom: 0.5em;}\n" +
68
- " li.entry {border-top: thin solid gray;}\n" +
69
- '</style>' + "\n" +
70
- '</head><body><div>' + "\n" +
71
- '<span class="before-change"><del>foo bar<br />' + "\n" + '</del></span>' +
72
- '<span class="after-change"><ins>foo beer<br />' + "\n" + '</ins></span>' +
73
- '<span class="common">baz' + "</span>" + "\n</div></body></html>" + "\n"
74
- assert_equal(expected, docdiff.run(doc1, doc2, {:resolution => "line", :format => "html", :digest => false}))
59
+ expected = <<~EOS
60
+ <?xml version="1.0" encoding="US-ASCII"?>
61
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
62
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
63
+ <html><head>
64
+ <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII" />
65
+ <title>Difference</title>
66
+ <style type="text/css">
67
+ body {font-family: monospace;}
68
+ span.del {background: hotpink; border: thin inset;}
69
+ span.add {background: deepskyblue; font-weight: bolder; border: thin outset;}
70
+ span.before-change {background: yellow; border: thin inset;}
71
+ span.after-change {background: lime; font-weight: bolder; border: thin outset;}
72
+ li.entry .position {font-weight: bolder; margin-top: 0em; margin-bottom: 0em; padding-top: 0.5em; padding-bottom: 0em;}
73
+ li.entry .body {margin-top: 0em; margin-bottom: 0em; padding-top: 0em; padding-bottom: 0.5em;}
74
+ li.entry {border-top: thin solid gray;}
75
+ </style>
76
+ </head><body><div>
77
+ <span class="before-change"><del>foo bar<br />
78
+ </del></span><span class="after-change"><ins>foo beer<br />
79
+ </ins></span><span class="common">baz</span>
80
+ </div></body></html>
81
+ EOS
82
+ assert_equal(expected, docdiff.run(doc1, doc2, { resolution: "line", format: "html", digest: false }))
75
83
  end
76
84
 
77
- def test_run_line_manued()
78
- doc1 = Document.new("foo bar\nbaz", 'US-ASCII', 'LF')
79
- doc2 = Document.new("foo beer\nbaz", 'US-ASCII', 'LF')
85
+ def test_run_line_manued
86
+ doc1 = Document.new("foo bar\nbaz", "US-ASCII", "LF")
87
+ doc2 = Document.new("foo beer\nbaz", "US-ASCII", "LF")
80
88
  docdiff = DocDiff.new
81
- expected = "defparentheses [ ]\n" +
82
- "defdelete /\n" +
83
- "defswap |\n" +
84
- "defcomment ;\n" +
85
- "defescape ~\n" +
86
- "deforder newer-last\n" +
87
- "defversion 0.9.5\n" +
88
- "[foo bar\n/foo beer\n]baz"
89
- assert_equal(expected, docdiff.run(doc1, doc2, {:resolution => "line", :format => "manued", :digest => false}))
89
+ expected = <<~EOS.chomp
90
+ defparentheses [ ]
91
+ defdelete /
92
+ defswap |
93
+ defcomment ;
94
+ defescape ~
95
+ deforder newer-last
96
+ defversion 0.9.5
97
+ [foo bar
98
+ /foo beer
99
+ ]baz
100
+ EOS
101
+ assert_equal(expected, docdiff.run(doc1, doc2, { resolution: "line", format: "manued", digest: false }))
90
102
  end
91
- def test_run_word_manued()
92
- doc1 = Document.new("foo bar\nbaz", 'US-ASCII', 'LF')
93
- doc2 = Document.new("foo beer\nbaz", 'US-ASCII', 'LF')
103
+
104
+ def test_run_word_manued
105
+ doc1 = Document.new("foo bar\nbaz", "US-ASCII", "LF")
106
+ doc2 = Document.new("foo beer\nbaz", "US-ASCII", "LF")
94
107
  docdiff = DocDiff.new
95
- expected = "defparentheses [ ]\n" +
96
- "defdelete /\n" +
97
- "defswap |\n" +
98
- "defcomment ;\n" +
99
- "defescape ~\n" +
100
- "deforder newer-last\n" +
101
- "defversion 0.9.5\n" +
102
- "foo [bar/beer]\nbaz"
103
- assert_equal(expected, docdiff.run(doc1, doc2, {:resolution => "word", :format => "manued", :digest => false}))
108
+ expected = <<~EOS.chomp
109
+ defparentheses [ ]
110
+ defdelete /
111
+ defswap |
112
+ defcomment ;
113
+ defescape ~
114
+ deforder newer-last
115
+ defversion 0.9.5
116
+ foo [bar/beer]
117
+ baz
118
+ EOS
119
+ assert_equal(expected, docdiff.run(doc1, doc2, { resolution: "word", format: "manued", digest: false }))
104
120
  end
105
- def test_run_char_manued()
106
- doc1 = Document.new("foo bar\nbaz", 'US-ASCII', 'LF')
107
- doc2 = Document.new("foo beer\nbaz", 'US-ASCII', 'LF')
121
+
122
+ def test_run_char_manued
123
+ doc1 = Document.new("foo bar\nbaz", "US-ASCII", "LF")
124
+ doc2 = Document.new("foo beer\nbaz", "US-ASCII", "LF")
108
125
  docdiff = DocDiff.new
109
- expected = "defparentheses [ ]\n" +
110
- "defdelete /\n" +
111
- "defswap |\n" +
112
- "defcomment ;\n" +
113
- "defescape ~\n" +
114
- "deforder newer-last\n" +
115
- "defversion 0.9.5\n" +
116
- "foo b[a/ee]r\nbaz"
117
- assert_equal(expected, docdiff.run(doc1, doc2, {:resolution => "char", :format => "manued", :digest => false}))
126
+ expected = <<~EOS.chomp
127
+ defparentheses [ ]
128
+ defdelete /
129
+ defswap |
130
+ defcomment ;
131
+ defescape ~
132
+ deforder newer-last
133
+ defversion 0.9.5
134
+ foo b[a/ee]r
135
+ baz
136
+ EOS
137
+ assert_equal(expected, docdiff.run(doc1, doc2, { resolution: "char", format: "manued", digest: false }))
118
138
  end
119
139
 
120
- def test_run_line_user()
121
- doc1 = Document.new("foo bar\nbaz", 'US-ASCII', 'LF')
122
- doc2 = Document.new("foo beer\nbaz", 'US-ASCII', 'LF')
123
- config = {:tag_common_start => '<=>',
124
- :tag_common_end => '</=>',
125
- :tag_del_start => '<->',
126
- :tag_del_end => '</->',
127
- :tag_add_start => '<+>',
128
- :tag_add_end => '</+>',
129
- :tag_change_before_start => '<!->',
130
- :tag_change_before_end => '</!->',
131
- :tag_change_after_start => '<!+>',
132
- :tag_change_after_end => '</!+>'}
140
+ def test_run_line_user
141
+ doc1 = Document.new("foo bar\nbaz", "US-ASCII", "LF")
142
+ doc2 = Document.new("foo beer\nbaz", "US-ASCII", "LF")
143
+ config = {
144
+ tag_common_start: "<=>",
145
+ tag_common_end: "</=>",
146
+ tag_del_start: "<->",
147
+ tag_del_end: "</->",
148
+ tag_add_start: "<+>",
149
+ tag_add_end: "</+>",
150
+ tag_change_before_start: "<!->",
151
+ tag_change_before_end: "</!->",
152
+ tag_change_after_start: "<!+>",
153
+ tag_change_after_end: "</!+>",
154
+ }
133
155
  docdiff = DocDiff.new
134
156
  docdiff.config.update(config)
135
157
  expected = "<!->foo bar\n</!-><!+>foo beer\n</!+><=>baz</=>"
136
- assert_equal(expected, docdiff.run(doc1, doc2, {:resolution => "line", :format => "user", :digest => false}))
158
+ assert_equal(expected, docdiff.run(doc1, doc2, { resolution: "line", format: "user", digest: false }))
137
159
  end
138
- def test_run_word_user()
139
- doc1 = Document.new("foo bar\nbaz", 'US-ASCII', 'LF')
140
- doc2 = Document.new("foo beer\nbaz", 'US-ASCII', 'LF')
141
- config = {:tag_common_start => '<=>',
142
- :tag_common_end => '</=>',
143
- :tag_del_start => '<->',
144
- :tag_del_end => '</->',
145
- :tag_add_start => '<+>',
146
- :tag_add_end => '</+>',
147
- :tag_change_before_start => '<!->',
148
- :tag_change_before_end => '</!->',
149
- :tag_change_after_start => '<!+>',
150
- :tag_change_after_end => '</!+>'}
160
+
161
+ def test_run_word_user
162
+ doc1 = Document.new("foo bar\nbaz", "US-ASCII", "LF")
163
+ doc2 = Document.new("foo beer\nbaz", "US-ASCII", "LF")
164
+ config = {
165
+ tag_common_start: "<=>",
166
+ tag_common_end: "</=>",
167
+ tag_del_start: "<->",
168
+ tag_del_end: "</->",
169
+ tag_add_start: "<+>",
170
+ tag_add_end: "</+>",
171
+ tag_change_before_start: "<!->",
172
+ tag_change_before_end: "</!->",
173
+ tag_change_after_start: "<!+>",
174
+ tag_change_after_end: "</!+>",
175
+ }
151
176
  docdiff = DocDiff.new
152
177
  docdiff.config.update(config)
153
178
  expected = "<=>foo </=><!->bar</!-><!+>beer</!+><=>\n</=><=>baz</=>"
154
- assert_equal(expected, docdiff.run(doc1, doc2, {:resolution => "word", :format => "user", :digest => false}))
179
+ assert_equal(expected, docdiff.run(doc1, doc2, { resolution: "word", format: "user", digest: false }))
155
180
  end
156
- def test_run_char_user()
157
- doc1 = Document.new("foo bar\nbaz", 'US-ASCII', 'LF')
158
- doc2 = Document.new("foo beer\nbaz", 'US-ASCII', 'LF')
159
- config = {:tag_common_start => '<=>',
160
- :tag_common_end => '</=>',
161
- :tag_del_start => '<->',
162
- :tag_del_end => '</->',
163
- :tag_add_start => '<+>',
164
- :tag_add_end => '</+>',
165
- :tag_change_before_start => '<!->',
166
- :tag_change_before_end => '</!->',
167
- :tag_change_after_start => '<!+>',
168
- :tag_change_after_end => '</!+>'}
181
+
182
+ def test_run_char_user
183
+ doc1 = Document.new("foo bar\nbaz", "US-ASCII", "LF")
184
+ doc2 = Document.new("foo beer\nbaz", "US-ASCII", "LF")
185
+ config = {
186
+ tag_common_start: "<=>",
187
+ tag_common_end: "</=>",
188
+ tag_del_start: "<->",
189
+ tag_del_end: "</->",
190
+ tag_add_start: "<+>",
191
+ tag_add_end: "</+>",
192
+ tag_change_before_start: "<!->",
193
+ tag_change_before_end: "</!->",
194
+ tag_change_after_start: "<!+>",
195
+ tag_change_after_end: "</!+>",
196
+ }
169
197
  docdiff = DocDiff.new
170
198
  docdiff.config.update(config)
171
199
  expected = "<=>foo </=><=>b</=><!->a</!-><!+>ee</!+><=>r</=><=>\n</=><=>baz</=>"
172
- assert_equal(expected, docdiff.run(doc1, doc2, {:resolution => "char", :format => "user", :digest => false}))
200
+ assert_equal(expected, docdiff.run(doc1, doc2, { resolution: "char", format: "user", digest: false }))
173
201
  end
174
202
 
175
- def teardown()
176
- #
203
+ def teardown
177
204
  end
178
-
179
205
  end