// Copyright (c) 2026 Petr BalvĂ­n (https://petrbalvin.org) // SPDX-License-Identifier: BSD-3-Clause package token import "testing" func TestKindString(t *testing.T) { cases := map[Kind]string{ EOF: "EOF", Ident: "IDENT", Number: "NUMBER", LParen: "(", LShift: "<<", Arrow: "->", Pipe: "|", Illegal: "ILLEGAL", } for k, want := range cases { if got := k.String(); got != want { t.Errorf("Kind(%d).String() = %q, want %q", int(k), got, want) } } // An out-of-range kind falls back to the numeric form. if got := Kind(9999).String(); got != "Kind(9999)" { t.Errorf("Kind(9999).String() = %q", got) } } func TestPosition(t *testing.T) { p := Position{Offset: 10, Line: 3, Column: 7} if got := p.String(); got != "3:7" { t.Errorf("Position.String() = %q, want 3:7", got) } if !p.IsValid() { t.Error("position with a line should be valid") } var zero Position if zero.IsValid() { t.Error("zero position should be invalid") } } func TestTokenString(t *testing.T) { tok := Token{Kind: Ident, Text: "MOVQ", Pos: Position{Line: 1, Column: 2}} got := tok.String() if got == "" || got[0] == ' ' { t.Errorf("Token.String() = %q", got) } }