Skip to content

test: Add tests for blocks, lambdas and procs. #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scip_indexer/SCIPIndexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ struct OwnedLocal {
string toString(const core::GlobalState &gs, core::FileRef file) {
// 32-bits => if there are 10k methods in a single file, the chance of at least one
// colliding pair is about 1.1%, assuming even distribution. That seems OK.
return fmt::format("local {:x}~#{}", counter, ::fnv1a_32(owner.name(gs).show(gs)));
return fmt::format("local {}~#{}", counter, ::fnv1a_32(owner.name(gs).show(gs)));
}
};

Expand Down
51 changes: 51 additions & 0 deletions test/scip/testdata/blocks_lambdas_procs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# typed: true

def blk
y = 0
[].each { |x|
y += x
}
[].each do |x|
y += x
end
end

def lam
y = 0
l1 = ->(x) {
y += x
}
l2 = lambda { |x|
y += x
}
l3 = ->(x:) {
y += x
}
l4 = lambda { |x:|
y += x
}
l1.call(1)
l2.call(2)
l3.call(x: 3)
l4.call(x: 4)
end

def prc
y = 0
p1 = Proc.new { |x|
y += x
}
p2 = proc { |x|
y += x
}
p3 = Proc.new { |x:|
y += x
}
p4 = proc { |x:|
y += x
}
p1.call(1)
p2.call(2)
p3.call(x: 3)
p4.call(x: 4)
end
137 changes: 137 additions & 0 deletions test/scip/testdata/blocks_lambdas_procs.snapshot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# typed: true

def blk
# ^^^ definition [..] Object#blk().
y = 0
# ^ definition local 1~#1472469056
[].each { |x|
# ^ definition local 2~#1472469056
y += x
# ^ reference local 1~#1472469056
# ^ reference (write) local 1~#1472469056
# ^^^^^^ reference local 1~#1472469056
# ^ reference local 2~#1472469056
}
[].each do |x|
# ^ definition local 3~#1472469056
y += x
# ^ reference local 1~#1472469056
# ^ reference (write) local 1~#1472469056
# ^^^^^^ reference local 1~#1472469056
# ^ reference local 3~#1472469056
end
end

def lam
# ^^^ definition [..] Object#lam().
y = 0
# ^ definition local 1~#1499497673
l1 = ->(x) {
# ^^ definition local 4~#1499497673
# ^^ reference [..] Kernel#
# ^ definition local 3~#1499497673
y += x
# ^ reference local 1~#1499497673
# ^ reference (write) local 1~#1499497673
# ^^^^^^ reference local 1~#1499497673
# ^ reference local 3~#1499497673
}
l2 = lambda { |x|
# ^^ definition local 6~#1499497673
# ^ definition local 5~#1499497673
y += x
# ^ reference (write) local 1~#1499497673
# ^ reference local 1~#1499497673
# ^^^^^^ reference local 1~#1499497673
# ^ reference local 5~#1499497673
}
l3 = ->(x:) {
# ^^ definition local 9~#1499497673
# ^^ reference [..] Kernel#
# ^^ definition local 8~#1499497673
y += x
# ^ reference local 1~#1499497673
# ^ reference (write) local 1~#1499497673
# ^^^^^^ reference local 1~#1499497673
# ^ reference local 8~#1499497673
}
l4 = lambda { |x:|
# ^^ definition local 11~#1499497673
# ^^ definition local 10~#1499497673
y += x
# ^ reference local 1~#1499497673
# ^ reference (write) local 1~#1499497673
# ^^^^^^ reference local 1~#1499497673
# ^ reference local 10~#1499497673
}
l1.call(1)
# ^^ reference local 4~#1499497673
# ^^^^ reference [..] Proc1#call().
l2.call(2)
# ^^ reference local 6~#1499497673
# ^^^^ reference [..] Proc1#call().
l3.call(x: 3)
# ^^ reference local 9~#1499497673
# ^^^^ reference [..] Proc#call().
l4.call(x: 4)
# ^^ reference local 11~#1499497673
# ^^^^ reference [..] Proc#call().
end

def prc
# ^^^ definition [..] Object#prc().
y = 0
# ^ definition local 1~#1283111692
p1 = Proc.new { |x|
# ^^ definition local 4~#1283111692
# ^^^^ reference [..] Proc#
# ^^^ reference [..] `<Class:Proc>`#new().
# ^ definition local 3~#1283111692
y += x
# ^ reference local 1~#1283111692
# ^ reference (write) local 1~#1283111692
# ^^^^^^ reference local 1~#1283111692
# ^ reference local 3~#1283111692
}
p2 = proc { |x|
# ^^ definition local 6~#1283111692
# ^ definition local 5~#1283111692
y += x
# ^ reference local 1~#1283111692
# ^ reference (write) local 1~#1283111692
# ^^^^^^ reference local 1~#1283111692
# ^ reference local 5~#1283111692
}
p3 = Proc.new { |x:|
# ^^ definition local 9~#1283111692
# ^^^^ reference [..] Proc#
# ^^^ reference [..] `<Class:Proc>`#new().
# ^^ definition local 8~#1283111692
y += x
# ^ reference local 1~#1283111692
# ^ reference (write) local 1~#1283111692
# ^^^^^^ reference local 1~#1283111692
# ^ reference local 8~#1283111692
}
p4 = proc { |x:|
# ^^ definition local 11~#1283111692
# ^^ definition local 10~#1283111692
y += x
# ^ reference local 1~#1283111692
# ^ reference (write) local 1~#1283111692
# ^^^^^^ reference local 1~#1283111692
# ^ reference local 10~#1283111692
}
p1.call(1)
# ^^ reference local 4~#1283111692
# ^^^^ reference [..] Proc#call().
p2.call(2)
# ^^ reference local 6~#1283111692
# ^^^^ reference [..] Proc1#call().
p3.call(x: 3)
# ^^ reference local 9~#1283111692
# ^^^^ reference [..] Proc#call().
p4.call(x: 4)
# ^^ reference local 11~#1283111692
# ^^^^ reference [..] Proc#call().
end