Added token tests
This commit is contained in:
parent
c0f399df7f
commit
18993e0855
7 changed files with 241 additions and 75 deletions
|
@ -1,16 +1,24 @@
|
|||
package token
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"bytes"
|
||||
)
|
||||
|
||||
// List is a slice of tokens.
|
||||
type List []Token
|
||||
|
||||
// String implements string serialization.
|
||||
func (list List) String() string {
|
||||
builder := strings.Builder{}
|
||||
builder := bytes.Buffer{}
|
||||
var last Token
|
||||
|
||||
for _, t := range list {
|
||||
builder.WriteString(t.String())
|
||||
if t.Kind == Identifier && last.Kind == Separator {
|
||||
builder.WriteByte(' ')
|
||||
}
|
||||
|
||||
builder.Write(t.Bytes)
|
||||
last = t
|
||||
}
|
||||
|
||||
return builder.String()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue