Permalink
Browse files

- Parser::Base, ruby18.y: don't try to lookup Encoding on 1.8 (fixes #…

  • Loading branch information...
1 parent 0311bfd commit 314e8c278f6f99901a389823ca4244694f7affe6 @whitequark committed Feb 24, 2014
Showing with 22 additions and 2 deletions.
  1. +3 −1 lib/parser/base.rb
  2. +1 −1 lib/parser/ruby18.y
  3. +18 −0 test/test_base.rb
View
@@ -93,7 +93,9 @@ def self.default_parser
end
def self.setup_source_buffer(file, line, string, encoding)
- string = string.dup.force_encoding(encoding)
+ if string.respond_to? :force_encoding
+ string = string.dup.force_encoding(encoding)
+ end
source_buffer = Source::Buffer.new(file, line)
View
@@ -1913,5 +1913,5 @@ require 'parser'
end
def default_encoding
- Encoding::BINARY
+ Encoding::BINARY if defined? Encoding
end
View
@@ -0,0 +1,18 @@
+require 'helper'
+require 'parser/current'
+
+class TestBase < Minitest::Test
+ include AST::Sexp
+
+ def test_parse
+ ast = Parser::CurrentRuby.parse('1')
+ assert_equal s(:int, 1), ast
+ end
+
+ def test_parse_with_comments
+ ast, comments = Parser::CurrentRuby.parse_with_comments('1 # foo')
+ assert_equal s(:int, 1), ast
+ assert_equal 1, comments.size
+ assert_equal '# foo', comments.first.text
+ end
+end

0 comments on commit 314e8c2

Please sign in to comment.