Skip to content
This repository has been archived by the owner on Aug 31, 2020. It is now read-only.

Commit

Permalink
Fix word position bug, and Test added.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Apr 22, 2011
1 parent 1bb1385 commit d7d1c68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/htmldiff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def convert_html_to_list_of_words(x, use_brackets = false)
words << current_word unless current_word.empty?
current_word = char
mode = :whitespace
elsif /[\w,\.!@#\$%\^&\*\(\)\[\]{}\-\+=:;\']+/i.match char
elsif /[\w\#@]+/i.match char
current_word << char
else
words << current_word unless current_word.empty?
Expand Down
8 changes: 7 additions & 1 deletion spec/htmldiff_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
require File.dirname(__FILE__) + '/spec_helper'
require 'htmldiff'

Expand Down Expand Up @@ -28,5 +29,10 @@ class TestDiff
diff = TestDiff.diff('a b c', 'a d c')
diff.should == "a <del class=\"diffmod\">b</del><ins class=\"diffmod\">d</ins> c"
end

it "should support Chinese" do
diff = TestDiff.diff('这个是中文内容, Ruby is the bast', '这是中国语内容,Ruby is the best language.')
diff.should == "这<del class=\"diffdel\">个</del>是中<del class=\"diffmod\">文</del><ins class=\"diffmod\">国语</ins>内<del class=\"diffmod\">容, Ruby</del><ins class=\"diffmod\">容,Ruby</ins> is the <del class=\"diffmod\">bast</del><ins class=\"diffmod\">best language.</ins>"
end

end
end

0 comments on commit d7d1c68

Please sign in to comment.