Generate hello world Zig code
This commit is contained in:
@@ -19,21 +19,49 @@ func Expect[T cmp.Ordered](expected, actual T) error {
|
||||
func TestHelloWorld(t *testing.T) {
|
||||
expected := `//! Hello, world!
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
fn main() void {
|
||||
return;
|
||||
std.debug.print("Hello, world!\n", .{});
|
||||
}
|
||||
`
|
||||
|
||||
root := &zig.Root{
|
||||
ContainerDocComment: "Hello, world!",
|
||||
ContainerMembers: []*zig.ContainerMember{
|
||||
{
|
||||
Decl: &zig.GlobalVarDecl{
|
||||
Const: true,
|
||||
Name: "std",
|
||||
Value: &zig.CallExpr{
|
||||
Fun: &zig.Identifier{Name: "@import"},
|
||||
Args: []zig.Expr{
|
||||
&zig.Literal{Kind: "string", Value: "std"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Decl: &zig.FnDecl{
|
||||
Name: "main",
|
||||
ReturnType: &zig.Identifier{Name: "void"},
|
||||
Body: &zig.Block{
|
||||
Stmts: []zig.Stmt{
|
||||
&zig.ReturnStmt{},
|
||||
&zig.ExprStmt{
|
||||
Expr: &zig.CallExpr{
|
||||
Fun: &zig.FieldAccessExpr{
|
||||
Receiver: &zig.FieldAccessExpr{
|
||||
Receiver: &zig.Identifier{Name: "std"},
|
||||
Field: "debug",
|
||||
},
|
||||
Field: "print",
|
||||
},
|
||||
Args: []zig.Expr{
|
||||
&zig.Literal{Kind: "string", Value: "Hello, world!\n"},
|
||||
&zig.InitListExpr{Empty: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user