Skip to content
Snippets Groups Projects
Commit 8c653b51 authored by Jakob Rath's avatar Jakob Rath Committed by Dan Hirsch
Browse files

Add tests about token encoding (failing for now).

parent b16eab8f
No related branches found
No related tags found
No related merge requests found
......@@ -39,8 +39,11 @@ module Hammer
:len, :size_t
def token
# TODO: Encoding? Should probably be the same encoding as the string the token was created with.
return self[:token].read_string(self[:len]) #.force_encoding('UTF-8')
# TODO: Encoding?
# Should be the same encoding as the string the token was created with.
# But how do we get to this knowledge at this point?
# Cheap solution: Just ask the user (additional parameter with default value of UTF-8).
return self[:token].read_string(self[:len]).force_encoding('UTF-8')
end
end
......
......@@ -80,4 +80,14 @@ class ParserTest < Minitest::Test
refute_nil parser.parse('今日a')
end
def test_token_encoding(encoding='UTF-8')
string = '今日'.encode(encoding)
parser = Hammer::Parser.token(string)
assert_equal string, parser.parse(string)[:ast][:data][:bytes].token
end
def test_token_encoding_2
test_token_encoding('EUC-JP')
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment