summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-07-03 10:42:56 -0400
committerKevin Newton <kddnewton@gmail.com>2024-07-11 14:25:54 -0400
commit2bf9ae3fa1b5dec1c63176f39db84d697ede3581 (patch)
treeff1b62681ac40f7cc121bdd55a979f9bb27ed15c /test
parent39dcfe26ee55919c3277a59884592a0ebe0aee6a (diff)
[ruby/prism] Add node ids to nodes
https://github.com/ruby/prism/commit/bf16ade7f9
Diffstat (limited to 'test')
-rw-r--r--test/prism/result/node_id_test.rb27
1 files changed, 27 insertions, 0 deletions
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