From 958ac8d58680782cd839b657f290fe698c044f20 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sun, 13 Aug 2023 12:44:32 +0200 Subject: [PATCH] [ruby/yarp] Test all methods of the YARP Ruby API https://github.com/ruby/yarp/commit/a723f40baf --- test/ruby_api_test.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/ruby_api_test.rb diff --git a/test/ruby_api_test.rb b/test/ruby_api_test.rb new file mode 100644 index 0000000000..ea18fbb35a --- /dev/null +++ b/test/ruby_api_test.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require "yarp_test_helper" + +class YARPRubyAPITest < Test::Unit::TestCase + def test_ruby_api + filepath = __FILE__ + source = File.read(filepath, binmode: true, external_encoding: Encoding::UTF_8) + + assert_equal YARP.lex(source, filepath).value, YARP.lex_file(filepath).value + + assert_equal YARP.dump(source, filepath), YARP.dump_file(filepath) + + serialized = YARP.dump(source, filepath) + ast1 = YARP.load(source, serialized).value + ast2 = YARP.parse(source, filepath).value + ast3 = YARP.parse_file(filepath).value + + assert_equal_nodes ast1, ast2 + assert_equal_nodes ast2, ast3 + end +end