|
| 1 | +/* |
| 2 | + * Copyright (c) 2025-2026 Mikhail Knyazhev <markus621@yandex.com>. All rights reserved. |
| 3 | + * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. |
| 4 | + */ |
| 5 | + |
| 6 | +package golang_test |
| 7 | + |
| 8 | +import ( |
| 9 | + "bytes" |
| 10 | + "fmt" |
| 11 | + "testing" |
| 12 | + |
| 13 | + . "go.osspkg.com/gogen/golang" |
| 14 | +) |
| 15 | + |
| 16 | +func Test_newStmt(t *testing.T) { |
| 17 | + //SetRawMode() |
| 18 | + |
| 19 | + buf := bytes.NewBuffer(nil) |
| 20 | + |
| 21 | + stmt := Comment("Autogenerate code"). |
| 22 | + Package("main"). |
| 23 | + Import("fmt", "fmt"). |
| 24 | + Import("fmt2", "fmt"). |
| 25 | + Join( |
| 26 | + Func().ID("main").Bracket().Block( |
| 27 | + Comment("d"). |
| 28 | + Var().ID("a").Op("="). |
| 29 | + Map(Interface().Block(), Interface().Block(ID("Do").Bracket().Error())). |
| 30 | + Block( |
| 31 | + Text("a").Op(":").Text("").Op(","), |
| 32 | + Array(2).Int8().Op(":").Raw("1").Op(","), |
| 33 | + ). |
| 34 | + Comment("d"), |
| 35 | + Var().ID("b").Op("=").New(Int8()), |
| 36 | + Var().ID("b").Op("=").Make(Slice().Int8(), 0, 10), |
| 37 | + Op("*").ID("aaa").Op("=").Append(Op("*").ID("aaa"), Slice().Byte().Op("...")), |
| 38 | + For().List(ID("a"), ID("b")).Op(":=").Range().Pkg("fmt").ID("aa").Block(), |
| 39 | + For().Block( |
| 40 | + Select().Block(), |
| 41 | + ), |
| 42 | + Switch().ID("aa").Op(".").Bracket(ID("type")).Block( |
| 43 | + Case().Slice().Byte().Op(":").Block( |
| 44 | + Pkg("fmt").ID("Println").Call(ID("aa")), |
| 45 | + ), |
| 46 | + Default().Op(":"), |
| 47 | + ), |
| 48 | + ), |
| 49 | + ) |
| 50 | + |
| 51 | + if err := Render(buf, stmt); err != nil { |
| 52 | + t.Fatal(err) |
| 53 | + } |
| 54 | + |
| 55 | + fmt.Println("______________________________") |
| 56 | + fmt.Print(buf.String()) |
| 57 | + fmt.Println("______________________________") |
| 58 | +} |
0 commit comments