1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package metadata
- import "testing"
- func TestParseMetadata(t *testing.T) {
- for _, query := range []string{
- `-- name: CreateFoo, :one`,
- `-- name: 9Foo_, :one`,
- `-- name: CreateFoo :two`,
- `-- name: CreateFoo`,
- `-- name: CreateFoo :one something`,
- `-- name: `,
- `--name: CreateFoo :one`,
- `--name CreateFoo :one`,
- `--name: CreateFoo :two`,
- "-- name:CreateFoo",
- `--name:CreateFoo :two`,
- } {
- if _, _, err := Parse(query, CommentSyntax{Dash: true}); err == nil {
- t.Errorf("expected invalid metadata: %q", query)
- }
- }
- for _, query := range []string{
- `-- some comment`,
- `-- name comment`,
- `--name comment`,
- } {
- if _, _, err := Parse(query, CommentSyntax{Dash: true}); err != nil {
- t.Errorf("expected valid comment: %q", query)
- }
- }
- query := `-- name: CreateFoo :one`
- queryName, queryType, err := Parse(query, CommentSyntax{Dash: true})
- if err != nil {
- t.Errorf("expected valid metadata: %q", query)
- }
- if queryName != "CreateFoo" {
- t.Errorf("incorrect queryName parsed: %q", query)
- }
- if queryType != CmdOne {
- t.Errorf("incorrect queryType parsed: %q", query)
- }
- }
|