1// Copyright (C) 2020 Storj Labs, Inc. 2// See LICENSE for copying information. 3 4package useragent 5 6import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10) 11 12func TestParseToken(t *testing.T) { 13 type test struct { 14 in string 15 token string 16 next int 17 ok bool 18 } 19 20 tests := []test{ 21 {``, ``, 0, false}, 22 {` `, ``, 0, false}, 23 {`(`, ``, 0, false}, 24 {`)`, ``, 0, false}, 25 {`a`, `a`, 1, true}, 26 {`a `, `a`, 1, true}, 27 {`a b`, `a`, 1, true}, 28 {`a/x b`, `a`, 1, true}, 29 } 30 31 for _, test := range tests { 32 token, next, ok := parseToken([]byte(test.in), 0) 33 assert.Equal(t, test.token, token, test.in) 34 assert.Equal(t, test.next, next, test.in) 35 assert.Equal(t, test.ok, ok, test.in) 36 } 37} 38