Skip to content

Commit

Permalink
Add directive specs for lib objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodywasishere committed Feb 11, 2025
1 parent bd37d31 commit 87af9cb
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions spec/compiler/crystal/tools/doc/directives_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ describe Crystal::Doc::Generator do
a_def.visibility.should eq("private")
end

it "shows documentation for nested objects if a lib is marked with :showdoc:" do
program = top_level_semantic(<<-CRYSTAL, wants_doc: true).program
# :showdoc:
lib Foo
# docs for `foo`
fun foo
end
CRYSTAL

generator = Doc::Generator.new program, [""]

generator.must_include?(program.types["Foo"]).should be_true
generator.type(program.types["Foo"]).lookup_method("foo").should_not be_nil
end

it "does not include documentation for methods within a :nodoc: namespace" do
program = top_level_semantic(<<-CRYSTAL, wants_doc: true).program
# :nodoc:
Expand Down Expand Up @@ -91,6 +106,19 @@ describe Crystal::Doc::Generator do
generator.must_include?(generator.type(program.types["Foo"]).lookup_path("Baz")).should be_false
end

it "does not include documentation for a :showdoc: fun inside a lib not marked with :showdoc:" do
program = top_level_semantic(<<-CRYSTAL, wants_doc: true).program
lib Foo
# :showdoc:
fun foo
end
CRYSTAL

generator = Doc::Generator.new program, [""]

generator.must_include?(program.types["Foo"]).should be_false
end

it "doesn't show a method marked :nodoc: within a :showdoc: namespace" do
program = top_level_semantic(<<-CRYSTAL, wants_doc: true).program
# :showdoc:
Expand All @@ -105,5 +133,22 @@ describe Crystal::Doc::Generator do
generator = Doc::Generator.new program, [""]
generator.type(program.types["Foo"]).lookup_method("foo").should be_nil
end

it "doesn't show a fun marked :nodoc: within a :showdoc: lib" do
program = top_level_semantic(<<-CRYSTAL, wants_doc: true).program
# :showdoc:
lib Foo
# :nodoc:
# Some docs for `foo`
fun foo
fun bar
end
CRYSTAL

generator = Doc::Generator.new program, [""]
generator.type(program.types["Foo"]).lookup_method("foo").should be_nil
generator.type(program.types["Foo"]).lookup_method("bar").should_not be_nil
end
end
end

0 comments on commit 87af9cb

Please sign in to comment.