Skip to content

Commit 0e106a7

Browse files
committed
Create token types
1 parent c14f800 commit 0e106a7

4 files changed

Lines changed: 48 additions & 1 deletion

File tree

lexer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package stringutils
2+

stringutils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func IsAlphabet(r rune) bool {
179179
}
180180

181181
// WordSplit splits a string into words. Returns a slice of words.
182-
// If there is no word in a string, return nil.
182+
// If there is no word in a string, returns an empty string.
183183
//
184184
// Word is defined as a locale dependent string containing alphabetic characters,
185185
// which may also contain but not start with `'` and `-` characters.

token.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package stringutils
2+
3+
type Token struct {
4+
Type string // verb, keyword, separator, etc
5+
Position int // position of the word in string
6+
Text string // text
7+
}
8+
9+
type TokenType struct {
10+
Type string // verb, keyword, separator, etc
11+
Words []string // words to be considered as a given token type
12+
CaseSensitive bool // whether or not this token type is case sensitive
13+
}

token_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package stringutils
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
)
7+
8+
func TestTokenType(t *testing.T) {
9+
assertions := assert.New(t)
10+
11+
result := TokenType{
12+
Type: "keyword",
13+
Words: []string{"for", "if"},
14+
CaseSensitive: true,
15+
}
16+
assertions.Equal(true, result.CaseSensitive)
17+
assertions.Equal([]string{"for", "if"}, result.Words)
18+
assertions.Equal("keyword", result.Type)
19+
}
20+
21+
func TestToken(t *testing.T) {
22+
assertions := assert.New(t)
23+
24+
result := Token{
25+
Type: "keyword",
26+
Position: 1,
27+
Text: "if",
28+
}
29+
assertions.Equal("keyword", result.Type)
30+
assertions.Equal("if", result.Text)
31+
assertions.Equal(1, result.Position)
32+
}

0 commit comments

Comments
 (0)