Permalink
Browse files

Fix word position bug, and Test added.

  • Loading branch information...
1 parent 1bb1385 commit d7d1c68897c8a42bc4e6897540d0da2ed0c12afd @huacnlee huacnlee committed Apr 22, 2011
Showing with 8 additions and 2 deletions.
  1. +1 −1 lib/htmldiff.rb
  2. +7 −1 spec/htmldiff_spec.rb
View
2 lib/htmldiff.rb
@@ -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?
View
8 spec/htmldiff_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
require File.dirname(__FILE__) + '/spec_helper'
require 'htmldiff'
@@ -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.