github.com/Finschia/finschia-sdk@v0.48.1/testutil/encoding.go (about)

     1  package testutil
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  )
     7  
     8  func MustJSONMarshal(v any) []byte {
     9  	b, err := json.Marshal(v)
    10  	if err != nil {
    11  		panic(err)
    12  	}
    13  
    14  	return b
    15  }
    16  
    17  // W wraps input with double quotes if it is a string or fmt.Stringer.
    18  func W(input any) []byte {
    19  	switch input.(type) {
    20  	case string, fmt.Stringer:
    21  		return []byte(fmt.Sprintf("\"%s\"", input))
    22  	default:
    23  		panic("unsupported type")
    24  	}
    25  }