docdiff 0.6.4 → 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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -7
  3. data/Guardfile +4 -4
  4. data/Makefile +6 -7
  5. data/README.md +1 -0
  6. data/README_ja.md +1 -0
  7. data/Rakefile +6 -6
  8. data/bin/docdiff +2 -209
  9. data/devutil/Rakefile +12 -5
  10. data/devutil/char_by_charclass.rb +43 -20
  11. data/devutil/charclass_by_char.rb +40 -19
  12. data/devutil/jis0208.rb +263 -231
  13. data/devutil/jis0208_test.rb +196 -0
  14. data/doc/news.md +17 -0
  15. data/docdiff.gemspec +13 -10
  16. data/lib/doc_diff.rb +63 -98
  17. data/lib/docdiff/charstring.rb +225 -241
  18. data/lib/docdiff/cli.rb +316 -0
  19. data/lib/docdiff/diff/contours.rb +1 -1
  20. data/lib/docdiff/diff/editscript.rb +1 -1
  21. data/lib/docdiff/diff/rcsdiff.rb +1 -1
  22. data/lib/docdiff/diff/shortestpath.rb +1 -1
  23. data/lib/docdiff/diff/speculative.rb +1 -1
  24. data/lib/docdiff/diff/subsequence.rb +1 -1
  25. data/lib/docdiff/diff/unidiff.rb +1 -1
  26. data/lib/docdiff/diff.rb +1 -1
  27. data/lib/docdiff/difference.rb +71 -70
  28. data/lib/docdiff/document.rb +129 -109
  29. data/lib/docdiff/encoding/en_ascii.rb +64 -58
  30. data/lib/docdiff/encoding/ja_eucjp.rb +250 -235
  31. data/lib/docdiff/encoding/ja_sjis.rb +240 -226
  32. data/lib/docdiff/encoding/ja_utf8.rb +6952 -6939
  33. data/lib/docdiff/version.rb +1 -1
  34. data/lib/docdiff/view.rb +523 -427
  35. data/lib/docdiff.rb +2 -2
  36. data/test/charstring_test.rb +475 -351
  37. data/test/cli_test.rb +314 -0
  38. data/test/diff_test.rb +15 -16
  39. data/test/difference_test.rb +40 -31
  40. data/test/docdiff_test.rb +162 -159
  41. data/test/document_test.rb +280 -175
  42. data/test/fixture/format_wdiff.conf +1 -0
  43. data/test/fixture/simple.conf +9 -0
  44. data/test/test_helper.rb +2 -1
  45. data/test/view_test.rb +636 -497
  46. metadata +27 -9
  47. data/devutil/testjis0208.rb +0 -38
data/test/docdiff_test.rb CHANGED
@@ -3,200 +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')
28
- 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))
35
- 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')
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")
39
30
  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))
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))
48
38
  end
49
39
 
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')
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")
53
43
  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}))
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))
75
53
  end
76
54
 
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')
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")
80
58
  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}))
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 }))
90
83
  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')
84
+
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")
94
88
  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}))
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 }))
104
102
  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')
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")
108
107
  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}))
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 }))
118
120
  end
119
121
 
120
- def test_parse_config_file_content()
121
- content = ["# comment line\n",
122
- " # comment line with leading space\n",
123
- "foo1 = bar\n",
124
- "foo2 = bar baz \n",
125
- " foo3 = 123 # comment\n",
126
- "foo4 = no \n",
127
- "foo1 = tRue\n",
128
- "\n",
129
- "",
130
- nil].join
131
- expected = {:foo1=>true, :foo2=>"bar baz", :foo3=>123, :foo4=>false}
132
- assert_equal(expected,
133
- DocDiff.parse_config_file_content(content))
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")
125
+ docdiff = DocDiff.new
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 }))
134
138
  end
135
139
 
136
- def test_run_line_user()
137
- doc1 = Document.new("foo bar\nbaz", 'US-ASCII', 'LF')
138
- doc2 = Document.new("foo beer\nbaz", 'US-ASCII', 'LF')
139
- config = {:tag_common_start => '<=>',
140
- :tag_common_end => '</=>',
141
- :tag_del_start => '<->',
142
- :tag_del_end => '</->',
143
- :tag_add_start => '<+>',
144
- :tag_add_end => '</+>',
145
- :tag_change_before_start => '<!->',
146
- :tag_change_before_end => '</!->',
147
- :tag_change_after_start => '<!+>',
148
- :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
+ }
149
155
  docdiff = DocDiff.new
150
156
  docdiff.config.update(config)
151
157
  expected = "<!->foo bar\n</!-><!+>foo beer\n</!+><=>baz</=>"
152
- 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 }))
153
159
  end
154
- def test_run_word_user()
155
- doc1 = Document.new("foo bar\nbaz", 'US-ASCII', 'LF')
156
- doc2 = Document.new("foo beer\nbaz", 'US-ASCII', 'LF')
157
- config = {:tag_common_start => '<=>',
158
- :tag_common_end => '</=>',
159
- :tag_del_start => '<->',
160
- :tag_del_end => '</->',
161
- :tag_add_start => '<+>',
162
- :tag_add_end => '</+>',
163
- :tag_change_before_start => '<!->',
164
- :tag_change_before_end => '</!->',
165
- :tag_change_after_start => '<!+>',
166
- :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
+ }
167
176
  docdiff = DocDiff.new
168
177
  docdiff.config.update(config)
169
178
  expected = "<=>foo </=><!->bar</!-><!+>beer</!+><=>\n</=><=>baz</=>"
170
- 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 }))
171
180
  end
172
- def test_run_char_user()
173
- doc1 = Document.new("foo bar\nbaz", 'US-ASCII', 'LF')
174
- doc2 = Document.new("foo beer\nbaz", 'US-ASCII', 'LF')
175
- config = {:tag_common_start => '<=>',
176
- :tag_common_end => '</=>',
177
- :tag_del_start => '<->',
178
- :tag_del_end => '</->',
179
- :tag_add_start => '<+>',
180
- :tag_add_end => '</+>',
181
- :tag_change_before_start => '<!->',
182
- :tag_change_before_end => '</!->',
183
- :tag_change_after_start => '<!+>',
184
- :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
+ }
185
197
  docdiff = DocDiff.new
186
198
  docdiff.config.update(config)
187
199
  expected = "<=>foo </=><=>b</=><!->a</!-><!+>ee</!+><=>r</=><=>\n</=><=>baz</=>"
188
- assert_equal(expected, docdiff.run(doc1, doc2, {:resolution => "char", :format => "user", :digest => false}))
189
- end
190
- def test_cli()
191
- expected = "Hello, my name is [-Watanabe.-]{+matz.+}\n"
192
- cmd = "ruby -I lib bin/docdiff --wdiff" +
193
- " test/fixture/01_en_ascii_lf.txt test/fixture/02_en_ascii_lf.txt"
194
- actual = `#{cmd}`.scan(/^.*?$\n/m).first
195
- assert_equal(expected, actual)
200
+ assert_equal(expected, docdiff.run(doc1, doc2, { resolution: "char", format: "user", digest: false }))
196
201
  end
197
202
 
198
- def teardown()
199
- #
203
+ def teardown
200
204
  end
201
-
202
205
  end