format_test.go 786 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package format
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. const (
  7. notFormattedStr = `
  8. type Request struct {
  9. Name string ` + "`" + `path:"name,options=you|me"` + "`" + `
  10. }
  11. type Response struct {
  12. Message string ` + "`" + `json:"message"` + "`" + `
  13. }
  14. service A-api {
  15. @server(
  16. handler: GreetHandler
  17. )
  18. get /greet/from/:name(Request) returns (Response)
  19. }
  20. `
  21. formattedStr = `type Request {
  22. Name string ` + "`" + `path:"name,options=you|me"` + "`" + `
  23. }
  24. type Response {
  25. Message string ` + "`" + `json:"message"` + "`" + `
  26. }
  27. service A-api {
  28. @server(
  29. handler: GreetHandler
  30. )
  31. get /greet/from/:name(Request) returns (Response)
  32. }`
  33. )
  34. func TestFormat(t *testing.T) {
  35. r, err := apiFormat(notFormattedStr)
  36. assert.Nil(t, err)
  37. assert.Equal(t, r, formattedStr)
  38. }