Takes a different approach

This commit is contained in:
Andy Lindeman
2014-05-21 15:11:06 -04:00
parent 185db0e8d5
commit 09a33f8daa
2 changed files with 39 additions and 3 deletions

View File

@@ -11,6 +11,17 @@ class TestBlob < Test::Unit::TestCase
Lexer = Pygments::Lexer
def setup
# git blobs are normally loaded as ASCII-8BIT since they may contain data
# with arbitrary encoding not known ahead of time
@original_external = Encoding.default_external
Encoding.default_external = Encoding.find("ASCII-8BIT")
end
def teardown
Encoding.default_external = @original_external
end
def samples_path
File.expand_path("../../samples", __FILE__)
end
@@ -67,6 +78,14 @@ class TestBlob < Test::Unit::TestCase
assert_equal 475, blob("Emacs Lisp/ess-julia.el").lines.length
end
def test_lines_maintains_original_encoding
# Even if the file's encoding is detected as something like UTF-16LE,
# earlier versions of the gem made implicit guarantees that the encoding of
# each `line` is in the same encoding as the file was originally read (in
# practice, UTF-8 or ASCII-8BIT)
assert_equal Encoding.default_external, blob("Text/utf16le.txt").lines.first.encoding
end
def test_size
assert_equal 15, blob("Ruby/foo.rb").size
end