Simplified file structure

This commit is contained in:
Eduard Urbach 2024-08-07 19:39:10 +02:00
parent cacee7260a
commit a466281307
Signed by: eduard
GPG key ID: 49226B848C78F6C8
219 changed files with 453 additions and 457 deletions

52
src/token/Token_test.go Normal file
View file

@ -0,0 +1,52 @@
package token_test
import (
"testing"
"git.akyoto.dev/cli/q/src/token"
"git.akyoto.dev/go/assert"
)
func TestTokenEnd(t *testing.T) {
hello := token.Token{
Kind: token.Identifier,
Position: 0,
Length: 5,
}
assert.Equal(t, hello.End(), 5)
}
func TestTokenReset(t *testing.T) {
hello := token.Token{
Kind: token.Identifier,
Position: 1,
Length: 5,
}
hello.Reset()
assert.Equal(t, hello.Position, 0)
assert.Equal(t, hello.Length, 0)
assert.Equal(t, hello.Kind, token.Invalid)
}
func TestTokenText(t *testing.T) {
buffer := []byte("hello, world")
hello := token.Token{Kind: token.Identifier, Position: 0, Length: 5}
comma := token.Token{Kind: token.Separator, Position: 5, Length: 1}
world := token.Token{Kind: token.Identifier, Position: 7, Length: 5}
assert.Equal(t, hello.Text(buffer), "hello")
assert.Equal(t, comma.Text(buffer), ",")
assert.Equal(t, world.Text(buffer), "world")
}
func TestTokenGroups(t *testing.T) {
assignment := token.Token{Kind: token.Assign}
operator := token.Token{Kind: token.Add}
keyword := token.Token{Kind: token.If}
assert.True(t, assignment.IsAssignment())
assert.True(t, operator.IsOperator())
assert.True(t, keyword.IsKeyword())
}