...

Source file src/github.com/vektah/gqlparser/lexer/blockstring_test.go

Documentation: github.com/vektah/gqlparser/lexer

     1  package lexer
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestBlockStringValue(t *testing.T) {
    10  	t.Run("removes uniform indentation from a string", func(t *testing.T) {
    11  		result := blockStringValue(`
    12      Hello,
    13        World!
    14  
    15      Yours,
    16        GraphQL.`)
    17  
    18  		require.Equal(t, "Hello,\n  World!\n\nYours,\n  GraphQL.", result)
    19  	})
    20  
    21  	t.Run("removes empty leading and trailing lines", func(t *testing.T) {
    22  		result := blockStringValue(`
    23  
    24  
    25      Hello,
    26        World!
    27  
    28      Yours,
    29        GraphQL.
    30  
    31  `)
    32  
    33  		require.Equal(t, "Hello,\n  World!\n\nYours,\n  GraphQL.", result)
    34  	})
    35  
    36  	t.Run("removes blank and trailing newlines", func(t *testing.T) {
    37  		result := blockStringValue(`
    38  
    39         
    40      Hello,
    41        World!
    42  
    43      Yours,
    44        GraphQL.
    45           
    46  
    47  `)
    48  
    49  		require.Equal(t, "Hello,\n  World!\n\nYours,\n  GraphQL.", result)
    50  	})
    51  
    52  	t.Run("does not alter trailing spaces", func(t *testing.T) {
    53  		result := blockStringValue(`
    54  
    55                  
    56      Hello,      
    57        World!    
    58                  
    59      Yours,      
    60        GraphQL.  
    61                  
    62  
    63  `)
    64  
    65  		require.Equal(t, "Hello,      \n  World!    \n            \nYours,      \n  GraphQL.  ", result)
    66  	})
    67  }
    68  

View as plain text