github.com/CiscoM31/godata@v1.0.10/search_parser_test.go (about)

     1  package godata
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  )
     7  
     8  func TestSearchQuery(t *testing.T) {
     9  	ctx := context.Background()
    10  	tokenizer := SearchTokenizer()
    11  	input := "mountain OR (\"red bikes\" AND avocados)"
    12  
    13  	expect := []*Token{
    14  		{Value: "mountain", Type: SearchTokenLiteral},
    15  		{Value: "OR", Type: SearchTokenOp},
    16  		{Value: "(", Type: SearchTokenOpenParen},
    17  		{Value: "\"red bikes\"", Type: SearchTokenLiteral},
    18  		{Value: "AND", Type: SearchTokenOp},
    19  		{Value: "avocados", Type: SearchTokenLiteral},
    20  		{Value: ")", Type: SearchTokenCloseParen},
    21  	}
    22  	output, err := tokenizer.Tokenize(ctx, input)
    23  	if err != nil {
    24  		t.Error(err)
    25  	}
    26  
    27  	result, err := CompareTokens(expect, output)
    28  	if !result {
    29  		t.Error(err)
    30  	}
    31  }