format_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. Students []Student ` + "`" + `json:"students"` + "`" + `
  14. }
  15. service A-api {
  16. @server(
  17. handler: GreetHandler
  18. )
  19. get /greet/from/:name(Request) returns (Response)
  20. }
  21. `
  22. formattedStr = `type Request {
  23. Name string ` + "`" + `path:"name,options=you|me"` + "`" + `
  24. }
  25. type Response {
  26. Message string ` + "`" + `json:"message"` + "`" + `
  27. Students []Student ` + "`" + `json:"students"` + "`" + `
  28. }
  29. service A-api {
  30. @server(
  31. handler: GreetHandler
  32. )
  33. get /greet/from/:name(Request) returns (Response)
  34. }`
  35. )
  36. func TestFormat(t *testing.T) {
  37. r, err := apiFormat(notFormattedStr, true)
  38. assert.Nil(t, err)
  39. assert.Equal(t, formattedStr, r)
  40. _, err = apiFormat(notFormattedStr, false)
  41. assert.Errorf(t, err, " line 7:13 can not found declaration 'Student' in context")
  42. }