package progdoc import ( "strings" "testing" "github.com/stretchr/testify/assert" ) func TestParseGoFile(t *testing.T) { sampleGoFile := `package main /// :meta this is some meta // // This is some content import "fmt" // Ignore me /// :more meta // // :arg stuff // :arg more stuff // :foo bar // // This is some more content // // this is indented // // More content goes here and there func main() { fmt.Println("Hello, World!") }` want := goFileDocs{ Parts: []goFilePart{ { Meta: []goFileMeta{ {Name: "meta", Value: "this is some meta"}, }, Body: "This is some content", }, { Meta: []goFileMeta{ {Name: "more", Value: "meta"}, {Name: "arg", Value: "stuff"}, {Name: "arg", Value: "more stuff"}, {Name: "foo", Value: "bar"}, }, Body: "This is some more content\n\n this is indented\n\nMore content goes here and there", }, }, } got, err := parseGoFileDocs(strings.NewReader(sampleGoFile)) assert.NoError(t, err) assert.Equal(t, want, got) }