54 lines
889 B
Go

package zig_test
import (
"cmp"
"fmt"
"strings"
"testing"
"git.frop.prof/luke/go-zig-compiler/internal/zig"
)
func Expect[T cmp.Ordered](expected, actual T) error {
if expected != actual {
return fmt.Errorf("\nExpected: %v\nActual: %v", expected, actual)
}
return nil
}
func TestHelloWorld(t *testing.T) {
expected := `//! Hello, world!
fn main() void {
return;
}
`
root := &zig.Root{
ContainerDocComment: "Hello, world!",
ContainerMembers: []*zig.ContainerMember{
{
Decl: &zig.FnDecl{
Name: "main",
ReturnType: &zig.Identifier{Name: "void"},
Body: &zig.Block{
Stmts: []zig.Stmt{
&zig.ReturnStmt{},
},
},
},
},
},
}
sb := new(strings.Builder)
err := zig.Write(sb, root)
if err != nil {
t.FailNow()
}
actual := sb.String()
if err = Expect(expected, actual); err != nil {
t.Error(err)
}
}