Skip to content

Commit

Permalink
Update enum helper method docs / specs
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodywasishere committed Jan 27, 2025
1 parent 0c06683 commit 4d1dc48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions spec/compiler/semantic/enum_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ describe "Semantic: enum" do
CRYSTAL

a_defs = result.program.types["Foo"].lookup_defs("bar?")
a_defs.first.doc.should_not be_nil
a_defs.first.doc.should eq("Returns `true` if this enum value equals `Bar`")
end

it "marks helper methods with `:nodoc:` if the member is `:nodoc:`" do
Expand All @@ -635,6 +635,6 @@ describe "Semantic: enum" do
CRYSTAL

a_defs = result.program.types["Foo"].lookup_defs("bar?")
a_defs.first.doc.try &.starts_with?(":nodoc:").should be_true
a_defs.first.doc.should eq(":nodoc:")
end
end
11 changes: 7 additions & 4 deletions src/compiler/crystal/semantic/top_level_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,13 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor
method_name = is_flags ? "includes?" : "=="
body = Call.new(Var.new("self").at(member), method_name, Path.new(member.name).at(member)).at(member)
a_def = Def.new("#{member.name.underscore}?", body: body).at(member)
a_def.doc = <<-DOC
#{":nodoc:" if member.doc.try &.starts_with?(":nodoc:")}
Returns `true` if this enum value #{is_flags ? "contains" : "equals"} `#{member.name}`
DOC

a_def.doc = if member.doc.try &.starts_with?(":nodoc:")
":nodoc:"
else
"Returns `true` if this enum value #{is_flags ? "contains" : "equals"} `#{member.name}`"
end

enum_type.add_def a_def
end

Expand Down

0 comments on commit 4d1dc48

Please sign in to comment.