// Copyright (c) 2026 Petr BalvĂ­n (https://petrbalvin.org) // SPDX-License-Identifier: BSD-3-Clause package ast import ( "testing" "sourcedock.dev/petrbalvin/gasm-devkit/token" ) func pos(line, col int) token.Position { return token.Position{Line: line, Column: col} } func TestDeclPositions(t *testing.T) { hash := token.Token{Kind: token.Hash, Pos: pos(1, 1)} inc := &Include{Hash: hash} if inc.Pos() != hash.Pos { t.Errorf("Include.Pos() = %v, want %v", inc.Pos(), hash.Pos) } pre := &Preproc{Hash: hash} if pre.Pos() != hash.Pos { t.Errorf("Preproc.Pos() = %v", pre.Pos()) } kw := token.Token{Kind: token.Ident, Text: "TEXT", Pos: pos(5, 1)} text := &Text{Keyword: kw} if text.Pos() != kw.Pos { t.Errorf("Text.Pos() = %v", text.Pos()) } gkw := token.Token{Kind: token.Ident, Text: "GLOBL", Pos: pos(7, 1)} if (&Globl{Keyword: gkw}).Pos() != gkw.Pos { t.Error("Globl.Pos()") } dkw := token.Token{Kind: token.Ident, Text: "DATA", Pos: pos(8, 1)} if (&Data{Keyword: dkw}).Pos() != dkw.Pos { t.Error("Data.Pos()") } } func TestStmtPositions(t *testing.T) { name := token.Token{Kind: token.Ident, Text: "loop", Pos: pos(3, 1)} if (&Label{Name: name}).Pos() != name.Pos { t.Error("Label.Pos()") } mnem := token.Token{Kind: token.Ident, Text: "RET", Pos: pos(4, 2)} if (&Instr{Mnemonic: mnem}).Pos() != mnem.Pos { t.Error("Instr.Pos()") } } // TestInterfaces confirms the node types satisfy their interfaces, so callers // can range over Decls and Stmts. func TestInterfaces(t *testing.T) { var decls []Decl = []Decl{&Include{}, &Preproc{}, &Text{}, &Globl{}, &Data{}} if len(decls) != 5 { t.Fatal("decl interface set") } var stmts []Stmt = []Stmt{&Label{}, &Instr{}} if len(stmts) != 2 { t.Fatal("stmt interface set") } }