mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Implement Scope#visibility
This commit is contained in:
parent
85c3db4d74
commit
4c740f394a
4 changed files with 62 additions and 1 deletions
|
@ -2,6 +2,17 @@ require "../../../spec_helper"
|
|||
|
||||
module Ameba::AST
|
||||
describe ScopeVisitor do
|
||||
{% for type in %w[class module enum].map(&.id) %}
|
||||
it "creates a scope for the {{ type }} def" do
|
||||
rule = ScopeRule.new
|
||||
ScopeVisitor.new rule, Source.new <<-CRYSTAL
|
||||
{{ type }} Foo
|
||||
end
|
||||
CRYSTAL
|
||||
rule.scopes.size.should eq 1
|
||||
end
|
||||
{% end %}
|
||||
|
||||
it "creates a scope for the def" do
|
||||
rule = ScopeRule.new
|
||||
ScopeVisitor.new rule, Source.new <<-CRYSTAL
|
||||
|
@ -54,5 +65,31 @@ module Ameba::AST
|
|||
outer_block.outer_scope.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "#visibility" do
|
||||
it "is being properly set" do
|
||||
rule = ScopeRule.new
|
||||
ScopeVisitor.new rule, Source.new <<-CRYSTAL
|
||||
private class Foo
|
||||
end
|
||||
CRYSTAL
|
||||
rule.scopes.size.should eq 1
|
||||
rule.scopes.first.visibility.should eq Crystal::Visibility::Private
|
||||
end
|
||||
|
||||
it "is being inherited from the outer scope(s)" do
|
||||
rule = ScopeRule.new
|
||||
ScopeVisitor.new rule, Source.new <<-CRYSTAL
|
||||
private class Foo
|
||||
class Bar
|
||||
def baz
|
||||
end
|
||||
end
|
||||
end
|
||||
CRYSTAL
|
||||
rule.scopes.size.should eq 3
|
||||
rule.scopes.each &.visibility.should eq Crystal::Visibility::Private
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,6 +43,9 @@ module Ameba
|
|||
description "Internal rule to test scopes"
|
||||
end
|
||||
|
||||
def test(source, node : Crystal::VisibilityModifier, scope : AST::Scope)
|
||||
end
|
||||
|
||||
def test(source, node : Crystal::ASTNode, scope : AST::Scope)
|
||||
@scopes << scope
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue