test-unit/lib/test/unit/diff.rb in rroonga-1.0.5 vs test-unit/lib/test/unit/diff.rb in rroonga-1.0.7

- old
+ new

@@ -1,6 +1,13 @@ # port of Python's difflib. +# +# Copyright (c) 2001-2008 Python Software Foundation; All Rights Reserved +# Copyright (c) 2008-2010 Kouhei Sutou; All Rights Reserved +# +# It is free software, and is distributed under the Ruby +# license and/or the PSF license. See the COPYING file and +# PSFL file. module Test module Unit module Diff class SequenceMatcher @@ -715,10 +722,19 @@ diff(UnifiedDiffer, from, to, options) end def diff(differ_class, from, to, options={}) differ = differ_class.new(from.split(/\r?\n/), to.split(/\r?\n/)) - differ.diff(options).join("\n") + lines = differ.diff(options) + if Object.const_defined?(:EncodingError) + begin + lines.join("\n") + rescue EncodingError + lines.collect {|line| line.force_encoding("ASCII-8BIT")}.join("\n") + end + else + lines.join("\n") + end end end end end