test/parser/test_ruby.rb in gettext-2.3.0 vs test/parser/test_ruby.rb in gettext-2.3.1
- old
+ new
@@ -21,11 +21,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require "gettext/tools/parser/ruby"
-class TestRubyParserXXX < Test::Unit::TestCase
+class TestRubyParser < Test::Unit::TestCase
include GetTextTestUtils
private
def parse(file)
GetText::RubyParser.parse(fixture_path(file))
@@ -60,9 +60,56 @@
end
def normalize_sources(sources)
sources.collect do |source|
source.sub(/\A#{Regexp.escape(fixture_path)}\//, "")
+ end
+ end
+
+ class TestDetectEncoding < self
+ setup :need_encoding
+
+ def test_ascii_and_hyphen
+ assert_equal("euc-jp", detect_encoding("# coding: euc-jp"))
+ end
+
+ def test_number
+ assert_equal("cp932", detect_encoding("#coding: cp932"))
+ end
+
+ def test_under_bar
+ assert_equal("Shift_JIS", detect_encoding("# coding: Shift_JIS"))
+ end
+
+ def test_emacs_style
+ assert_equal("utf-8", detect_encoding("# -*- coding: utf-8 -*-"))
+ end
+
+ def test_encoding
+ assert_equal("utf-8", detect_encoding("# encoding: utf-8"))
+ end
+
+ def test_equal
+ assert_equal("utf-8", detect_encoding("# encoding = utf-8"))
+ end
+
+ private
+ def detect_encoding(content)
+ GetText::RubyParser.detect_encoding(content)
+ end
+
+ class NewLineStyle < self
+ def test_unix
+ assert_equal("utf-8", detect_encoding("# -*- coding: utf-8-unix -*-"))
+ end
+
+ def test_mac
+ assert_equal("utf-8", detect_encoding("# -*- coding: utf-8-mac -*-"))
+ end
+
+ def test_dos
+ assert_equal("utf-8", detect_encoding("# -*- coding: utf-8-dos -*-"))
+ end
end
end
class Test_ < self
def test_one_line