Skip to content

Commit

Permalink
Add example test and update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdk committed Dec 7, 2017
1 parent 88b6d46 commit 47a258f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -890,19 +890,24 @@ fmt.Printf("%#v", f)
// func init() {}
```

### PackageComment
### Comments
HeaderComment adds a comment to the top of the file, above any package
comments. A blank line is rendered below the header comments, ensuring
header comments are not included in the package doc.

PackageComment adds a comment to the top of the file, above the package
keyword.

```go
f := NewFile("c")
f.PackageComment("a")
f.PackageComment("b")
f.HeaderComment("Code generated by...")
f.PackageComment("Package c implements...")
f.Func().Id("init").Params().Block()
fmt.Printf("%#v", f)
// Output:
// // a
// // b
// // Code generated by...
//
// // Package c implements...
// package c
//
// func init() {}
Expand Down
6 changes: 4 additions & 2 deletions README.md.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,12 @@ avoid this, use Clone. {{ "Statement.Clone" | doc }}

{{ "ExampleFile_Anon" | example }}

### PackageComment
### Comments
{{ "File.HeaderComment" | doc }}

{{ "File.PackageComment" | doc }}

{{ "ExampleFile_PackageComment" | example }}
{{ "ExampleFile_HeaderAndPackageComments" | example }}

### PackagePrefix
{{ "File.PackagePrefix" | doc }}
Expand Down
11 changes: 6 additions & 5 deletions jen/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,15 +1218,16 @@ func ExampleNewFilePathName() {
// }
}

func ExampleFile_PackageComment() {
func ExampleFile_HeaderAndPackageComments() {
f := NewFile("c")
f.PackageComment("a")
f.PackageComment("b")
f.HeaderComment("Code generated by...")
f.PackageComment("Package c implements...")
f.Func().Id("init").Params().Block()
fmt.Printf("%#v", f)
// Output:
// // a
// // b
// // Code generated by...
//
// // Package c implements...
// package c
//
// func init() {}
Expand Down

0 comments on commit 47a258f

Please sign in to comment.