Skip to content

Commit a3614b2

Browse files
committed
test: Add tree-sitter query snapshot-based testing
Added a Rust-based integration test harness that runs quries directly through `tree‑sitter` and snapshots the captures using insta, mirroring the Jest snapshot review/accept flow.
1 parent de07509 commit a3614b2

14 files changed

Lines changed: 5552 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 275 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ regex = "1.11.1"
1414
serde_json = "1.0"
1515
serde = {version = "1.0", features = ["derive"]}
1616
zed_extension_api = "0.7.0"
17+
18+
[dev-dependencies]
19+
tree-sitter = "0.25"
20+
tree-sitter-ruby = { git = "https://github.com/tree-sitter/tree-sitter-ruby.git", rev = "71bd32fb7607035768799732addba884a37a6210" }
21+
insta = { version = "1.46", features = ["yaml"] }
22+
streaming-iterator = "0.1"

tests/languages/ruby/debugger.rb

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Debugger fixtures for tree-sitter queries
2+
3+
# Assignments
4+
class Example
5+
def process
6+
user = User.new
7+
email = user.email
8+
result = calculate_sum(1, 2)
9+
@total = result
10+
end
11+
12+
def calculate_sum(a, b)
13+
sum = a + b
14+
sum
15+
end
16+
end
17+
18+
# Method parameters
19+
class Calculator
20+
def add(x, y)
21+
x + y
22+
end
23+
24+
def multiply(a, b, c = 1)
25+
a * b * c
26+
end
27+
28+
def process(*args, **kwargs)
29+
args.sum + kwargs.values.sum
30+
end
31+
end
32+
33+
# Instance variables
34+
class User
35+
def initialize(name)
36+
@name = name
37+
@created_at = Time.now
38+
@active = true
39+
end
40+
41+
def update(email)
42+
@email = email
43+
@updated_at = Time.now
44+
end
45+
end
46+
47+
# Scopes
48+
global_var = "test"
49+
50+
class ScopeExample
51+
def method_scope
52+
local_var = 1
53+
another_var = 2
54+
55+
if local_var > 0
56+
scoped_var = 3
57+
end
58+
end
59+
end
60+
61+
# Complex scenario
62+
class ComplexExample
63+
def process_data(input, options = {})
64+
@input = input
65+
result = transform(input)
66+
output = result.map { |item| item.value }
67+
logger.info(output)
68+
@processed = true
69+
output
70+
end
71+
72+
def transform(data)
73+
temp = data.dup
74+
temp.filter { |x| x > 0 }
75+
end
76+
end
77+
78+
# Call arguments
79+
class ArgumentCalls
80+
def audit(user, value)
81+
log(user.name)
82+
log(fetch())
83+
log(value)
84+
end
85+
86+
def fetch
87+
"ok"
88+
end
89+
90+
def log(message)
91+
message
92+
end
93+
end
94+
95+
# Assignment calls
96+
class AssignmentCalls
97+
def update(user)
98+
user.email = "test@example.com"
99+
user.profile.name = "Tester"
100+
end
101+
end

tests/languages/ruby/injections.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Inline RBS examples
2+
#: (String) -> void
3+
# @rbs (Integer) -> String
4+
# | arg: String
5+
# | (Integer) -> String
6+
7+
def example(name)
8+
name
9+
end
10+
11+
pattern = /[a-z]+/i
12+
13+
sql = <<~SQL
14+
SELECT * FROM users
15+
SQL

tests/languages/ruby/outline.rb

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
# Outline fixtures for classes, modules, methods, tasks, and tests
2+
3+
API_VERSION = "v1"
4+
5+
class User
6+
VERSION = "1.0"
7+
8+
include Comparable
9+
include Foo::Bar
10+
include Baz
11+
attr_reader :name, :email
12+
alias_method "login", "sign_in"
13+
14+
private
15+
self.private
16+
17+
def initialize(name)
18+
@name = name
19+
end
20+
21+
private def secret
22+
# hidden
23+
end
24+
25+
def public_method
26+
# visible
27+
end
28+
29+
def self.build
30+
new("default")
31+
end
32+
33+
private_class_method def self.build_private
34+
new("private")
35+
end
36+
37+
class << self
38+
def singleton_block_method
39+
# singleton class method
40+
end
41+
end
42+
end
43+
44+
module Billing
45+
include Payments
46+
include Payments::Gateway
47+
alias_method :charge, :bill
48+
49+
private
50+
self.private
51+
end
52+
53+
private def root_private
54+
# root private
55+
end
56+
57+
def root_public
58+
# root public
59+
end
60+
61+
def self.root_singleton
62+
# root singleton
63+
end
64+
65+
# Root test methods
66+
67+
describe "root describe" do
68+
end
69+
70+
context "root context" do
71+
end
72+
73+
test "root test" do
74+
end
75+
76+
it "root it" do
77+
end
78+
79+
its "root its" do
80+
end
81+
82+
specify "root specify" do
83+
end
84+
85+
example "root example" do
86+
end
87+
88+
feature "root feature" do
89+
end
90+
91+
scenario "root scenario" do
92+
end
93+
94+
shared_examples "root shared_examples" do
95+
end
96+
97+
fdescribe "root fdescribe" do
98+
end
99+
100+
fcontext "root fcontext" do
101+
end
102+
103+
fit "root fit" do
104+
end
105+
106+
fexample "root fexample" do
107+
end
108+
109+
focus "root focus" do
110+
end
111+
112+
xdescribe "root xdescribe" do
113+
end
114+
115+
xcontext "root xcontext" do
116+
end
117+
118+
xit "root xit" do
119+
end
120+
121+
xexample "root xexample" do
122+
end
123+
124+
xspecify "root xspecify" do
125+
end
126+
127+
skip "root skip" do
128+
end
129+
130+
pending "root pending" do
131+
end
132+
133+
it_behaves_like "root it_behaves_like"
134+
135+
it_should_behave_like "root it_should_behave_like"
136+
137+
include_context "root include_context"
138+
139+
include_examples "root include_examples"
140+
141+
# Nested test methods and one-liners
142+
143+
describe "outer" do
144+
context "inner" do
145+
it "nested it" do
146+
end
147+
148+
specify "nested specify" do
149+
end
150+
151+
example "nested example" do
152+
end
153+
154+
feature "nested feature" do
155+
end
156+
157+
scenario "nested scenario" do
158+
end
159+
160+
shared_examples "nested shared_examples" do
161+
end
162+
163+
fdescribe "nested fdescribe" do
164+
end
165+
166+
fcontext "nested fcontext" do
167+
end
168+
169+
fit "nested fit" do
170+
end
171+
172+
fexample "nested fexample" do
173+
end
174+
175+
focus "nested focus" do
176+
end
177+
178+
xdescribe "nested xdescribe" do
179+
end
180+
181+
xcontext "nested xcontext" do
182+
end
183+
184+
xit "nested xit" do
185+
end
186+
187+
xexample "nested xexample" do
188+
end
189+
190+
xspecify "nested xspecify" do
191+
end
192+
193+
skip "nested skip" do
194+
end
195+
196+
pending "nested pending" do
197+
end
198+
199+
it_behaves_like "nested it_behaves_like"
200+
201+
it_should_behave_like "nested it_should_behave_like"
202+
203+
include_context "nested include_context"
204+
205+
include_examples "nested include_examples"
206+
207+
it { is_expected.to be_truthy }
208+
it { is_expected.not_to be_nil }
209+
its { is_expected.to be_empty }
210+
specify { is_expected.to be_truthy }
211+
example { is_expected.to be_truthy }
212+
fit { is_expected.to be_truthy }
213+
fexample { is_expected.to be_truthy }
214+
focus { is_expected.to be_truthy }
215+
xit { is_expected.to be_truthy }
216+
xexample { is_expected.to be_truthy }
217+
xspecify { is_expected.to be_truthy }
218+
skip { is_expected.to be_truthy }
219+
pending { is_expected.to be_truthy }
220+
end
221+
end
222+
223+
# Rake namespaces and tasks
224+
225+
namespace :db do
226+
namespace :migrate do
227+
task :up do
228+
# migrate
229+
end
230+
end
231+
end
232+
233+
task :version do
234+
# version
235+
end
236+
237+
task default: :test do
238+
# default
239+
end
240+
241+
# Schema.rb style
242+
243+
ActiveRecord::Schema.define(version: 2024_01_01) do
244+
create_table "users"
245+
create_enum "status"
246+
create_schema "audit"
247+
create_virtual_table "search"
248+
enable_extension "pgcrypto"
249+
add_foreign_key "orders", "users"
250+
end

0 commit comments

Comments
 (0)