-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: add doc generate command (#126)
* tools: add doc generate command * fix doc generate command unit test on windows os * more docs and examples of kcl-doc command
- Loading branch information
1 parent
88ec03a
commit be46045
Showing
7 changed files
with
353 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ __pycache__ | |
profile.cov | ||
|
||
.idea/ | ||
docs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package doc | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
kcl "kcl-lang.io/kcl-go" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestDocRender(t *testing.T) { | ||
tcases := [...]struct { | ||
source *kcl.KclType | ||
expect string | ||
}{ | ||
{ | ||
source: &kcl.KclType{ | ||
SchemaName: "Person", | ||
SchemaDoc: "Description of Schema Person", | ||
Properties: map[string]*kcl.KclType{"name": { | ||
Type: "string", | ||
}}, | ||
Required: []string{"name"}, | ||
}, | ||
expect: `## Schema Person | ||
Description of Schema Person | ||
### Attributes | ||
**name** *required* | ||
` + "`" + `string` + "`" + ` | ||
todo: The description of the property | ||
### Examples | ||
todo: The example section | ||
## Source Files | ||
- [Person](todo: filepath) | ||
`, | ||
}, | ||
} | ||
|
||
context := GenContext{ | ||
Format: Markdown, | ||
IgnoreDeprecated: true, | ||
} | ||
|
||
for _, tcase := range tcases { | ||
content, err := context.renderContent(tcase.source) | ||
if err != nil { | ||
t.Errorf("render failed, err: %s", err) | ||
} | ||
expect := tcase.expect | ||
if runtime.GOOS == "windows" { | ||
expect = strings.ReplaceAll(tcase.expect, "\n", "\r\n") | ||
} | ||
assert.Equal(t, expect, string(content), "render content mismatch") | ||
} | ||
} |
Oops, something went wrong.