From 2bf9ae3fa1b5dec1c63176f39db84d697ede3581 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 3 Jul 2024 10:42:56 -0400 Subject: [ruby/prism] Add node ids to nodes https://github.com/ruby/prism/commit/bf16ade7f9 --- test/prism/result/node_id_test.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/prism/result/node_id_test.rb (limited to 'test') diff --git a/test/prism/result/node_id_test.rb b/test/prism/result/node_id_test.rb new file mode 100644 index 0000000000..59b79bc574 --- /dev/null +++ b/test/prism/result/node_id_test.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require_relative "../test_helper" + +module Prism + class NodeIdTest < TestCase + Fixture.each do |fixture| + define_method(fixture.test_name) { assert_node_ids(fixture.read) } + end + + private + + def assert_node_ids(source) + queue = [Prism.parse(source).value] + node_ids = [] + + while (node = queue.shift) + node_ids << node.node_id + queue.concat(node.compact_child_nodes) + end + + node_ids.sort! + refute_includes node_ids, 0 + assert_equal node_ids, node_ids.uniq + end + end +end -- cgit v1.2.3