From 1d7dc665d64432b642abddc3caa7e8011f0e3181 Mon Sep 17 00:00:00 2001 From: Martino Ferrari Date: Tue, 27 Jan 2026 15:31:01 +0100 Subject: [PATCH] More tests on AST --- internal/parser/ast.go | 6 ++++++ test/ast_test.go | 24 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/internal/parser/ast.go b/internal/parser/ast.go index ff51c7d..fa1ca8e 100644 --- a/internal/parser/ast.go +++ b/internal/parser/ast.go @@ -45,6 +45,8 @@ type Subnode struct { Definitions []Definition } +func (s *Subnode) Pos() Position { return s.Position } + type Value interface { Node isValue() @@ -115,7 +117,11 @@ type Comment struct { Doc bool // true if starts with //# } +func (c *Comment) Pos() Position { return c.Position } + type Pragma struct { Position Position Text string } + +func (p *Pragma) Pos() Position { return p.Position } diff --git a/test/ast_test.go b/test/ast_test.go index 39d2071..4feb0be 100644 --- a/test/ast_test.go +++ b/test/ast_test.go @@ -84,11 +84,29 @@ func TestASTCoverage(t *testing.T) { // Package pkg := &parser.Package{Position: pos} - // Package implements Node? - // ast.go: func (p *Package) Pos() Position { return p.Position } - // Yes. n = pkg if n.Pos() != pos { t.Error("Package.Pos failed") } + + // Subnode + sn := &parser.Subnode{Position: pos} + n = sn + if n.Pos() != pos { + t.Error("Subnode.Pos failed") + } + + // Comment + cmt := &parser.Comment{Position: pos} + n = cmt + if n.Pos() != pos { + t.Error("Comment.Pos failed") + } + + // Pragma + prg := &parser.Pragma{Position: pos} + n = prg + if n.Pos() != pos { + t.Error("Pragma.Pos failed") + } }