meta_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package metadata
  2. import "testing"
  3. func TestParseMetadata(t *testing.T) {
  4. for _, query := range []string{
  5. `-- name: CreateFoo, :one`,
  6. `-- name: 9Foo_, :one`,
  7. `-- name: CreateFoo :two`,
  8. `-- name: CreateFoo`,
  9. `-- name: CreateFoo :one something`,
  10. `-- name: `,
  11. `--name: CreateFoo :one`,
  12. `--name CreateFoo :one`,
  13. `--name: CreateFoo :two`,
  14. "-- name:CreateFoo",
  15. `--name:CreateFoo :two`,
  16. } {
  17. if _, _, err := Parse(query, CommentSyntax{Dash: true}); err == nil {
  18. t.Errorf("expected invalid metadata: %q", query)
  19. }
  20. }
  21. for _, query := range []string{
  22. `-- some comment`,
  23. `-- name comment`,
  24. `--name comment`,
  25. } {
  26. if _, _, err := Parse(query, CommentSyntax{Dash: true}); err != nil {
  27. t.Errorf("expected valid comment: %q", query)
  28. }
  29. }
  30. query := `-- name: CreateFoo :one`
  31. queryName, queryType, err := Parse(query, CommentSyntax{Dash: true})
  32. if err != nil {
  33. t.Errorf("expected valid metadata: %q", query)
  34. }
  35. if queryName != "CreateFoo" {
  36. t.Errorf("incorrect queryName parsed: %q", query)
  37. }
  38. if queryType != CmdOne {
  39. t.Errorf("incorrect queryType parsed: %q", query)
  40. }
  41. }