test/parse_helper.rb in parser-1.0.1 vs test/parse_helper.rb in parser-1.1.0
- old
+ new
@@ -1,12 +1,19 @@
-require 'parser/all'
-
module ParseHelper
include AST::Sexp
- ALL_VERSIONS = %w(1.8 1.9 2.0)
+ if RUBY_VERSION == '1.8.7'
+ require 'parser/ruby18'
+ ALL_VERSIONS = %w(1.8)
+ else
+ require 'parser/all'
+ require 'parser/ruby21'
+
+ ALL_VERSIONS = %w(1.8 1.9 2.0 2.1)
+ end
+
def setup
@diagnostics = []
super if defined?(super)
end
@@ -14,10 +21,11 @@
def parser_for_ruby_version(version)
case version
when '1.8'; parser = Parser::Ruby18.new
when '1.9'; parser = Parser::Ruby19.new
when '2.0'; parser = Parser::Ruby20.new
+ when '2.1'; parser = Parser::Ruby21.new
else raise "Unrecognized Ruby version #{version}"
end
parser.diagnostics.consumer = lambda do |diagnostic|
@diagnostics << diagnostic
@@ -25,10 +33,10 @@
parser
end
def with_versions(code, versions)
- versions.each do |version|
+ (versions & ALL_VERSIONS).each do |version|
@diagnostics.clear
parser = parser_for_ruby_version(version)
yield version, parser
end