github.com/humans-group/gqlgen@v0.7.2/graphql/string_test.go (about)

     1  package graphql
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestString(t *testing.T) {
    11  	assert.Equal(t, `"hello"`, doStrMarshal("hello"))
    12  	assert.Equal(t, `"he\tllo"`, doStrMarshal("he\tllo"))
    13  	assert.Equal(t, `"he\tllo"`, doStrMarshal("he	llo"))
    14  	assert.Equal(t, `"he\nllo"`, doStrMarshal("he\nllo"))
    15  	assert.Equal(t, `"he\r\nllo"`, doStrMarshal("he\r\nllo"))
    16  	assert.Equal(t, `"he\\llo"`, doStrMarshal(`he\llo`))
    17  	assert.Equal(t, `"quotes\"nested\"in\"quotes\""`, doStrMarshal(`quotes"nested"in"quotes"`))
    18  	assert.Equal(t, `"\u0000"`, doStrMarshal("\u0000"))
    19  	assert.Equal(t, `"\u0000"`, doStrMarshal("\u0000"))
    20  	assert.Equal(t, "\"\U000fe4ed\"", doStrMarshal("\U000fe4ed"))
    21  }
    22  
    23  func doStrMarshal(s string) string {
    24  	var buf bytes.Buffer
    25  	MarshalString(s).MarshalGQL(&buf)
    26  	return buf.String()
    27  }