...

Source file src/github.com/vektah/gqlparser/v2/lexer/lexer_test.go

Documentation: github.com/vektah/gqlparser/v2/lexer

     1  package lexer
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/vektah/gqlparser/v2/gqlerror"
     7  
     8  	"github.com/vektah/gqlparser/v2/ast"
     9  	"github.com/vektah/gqlparser/v2/parser/testrunner"
    10  )
    11  
    12  func TestLexer(t *testing.T) {
    13  	testrunner.Test(t, "lexer_test.yml", func(t *testing.T, input string) testrunner.Spec {
    14  		l := New(&ast.Source{Input: input, Name: "spec"})
    15  
    16  		ret := testrunner.Spec{}
    17  		for {
    18  			tok, err := l.ReadToken()
    19  
    20  			if err != nil {
    21  				ret.Error = err.(*gqlerror.Error)
    22  				break
    23  			}
    24  
    25  			if tok.Kind == EOF {
    26  				break
    27  			}
    28  
    29  			ret.Tokens = append(ret.Tokens, testrunner.Token{
    30  				Kind:   tok.Kind.Name(),
    31  				Value:  tok.Value,
    32  				Line:   tok.Pos.Line,
    33  				Column: tok.Pos.Column,
    34  				Start:  tok.Pos.Start,
    35  				End:    tok.Pos.End,
    36  				Src:    tok.Pos.Src.Name,
    37  			})
    38  		}
    39  
    40  		return ret
    41  	})
    42  }
    43  

View as plain text