diff --git a/README.md b/README.md index 7dea473..a48b67f 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ explanatory: | Construct | Name | | ---------------- | ---- | | Keywords | Break, Chan, Const, Continue, Default, Defer, Else, Fallthrough, Func, Go, Goto, Range, Select, Type, Var | -| Functions | Append, Cap, Close, Complex, Copy, Delete, Imag, Len, Make, New, Panic, Print, Println, Real, Recover | +| Functions | Append, Cap, Clear, Close, Complex, Copy, Delete, Imag, Len, Make, Max, Min, New, Panic, Print, Println, Real, Recover | | Types | Bool, Byte, Complex64, Complex128, Error, Float32, Float64, Int, Int8, Int16, Int32, Int64, Rune, String, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr | | Constants | True, False, Iota, Nil | | Helpers | Err | diff --git a/README.md.tpl b/README.md.tpl index 07e1807..c6d22e1 100644 --- a/README.md.tpl +++ b/README.md.tpl @@ -85,7 +85,7 @@ explanatory: | Construct | Name | | ---------------- | ---- | | Keywords | Break, Chan, Const, Continue, Default, Defer, Else, Fallthrough, Func, Go, Goto, Range, Select, Type, Var | -| Functions | Append, Cap, Close, Complex, Copy, Delete, Imag, Len, Make, New, Panic, Print, Println, Real, Recover | +| Functions | Append, Cap, Clear, Close, Complex, Copy, Delete, Imag, Len, Make, Max, Min, New, Panic, Print, Println, Real, Recover | | Types | Bool, Byte, Complex64, Complex128, Error, Float32, Float64, Int, Int8, Int16, Int32, Int64, Rune, String, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr | | Constants | True, False, Iota, Nil | | Helpers | Err | diff --git a/genjen/data.go b/genjen/data.go index 26f52ca..c1570b8 100644 --- a/genjen/data.go +++ b/genjen/data.go @@ -195,6 +195,33 @@ var groups = []struct { separator: ",", parameters: []string{"c"}, }, + { + name: "Clear", + comment: "renders the clear built-in function.", + variadic: false, + opening: "clear(", + closing: ")", + separator: ",", + parameters: []string{"c"}, + }, + { + name: "Min", + comment: "renders the min built-in function.", + variadic: true, + opening: "min(", + closing: ")", + separator: ",", + parameters: []string{"args"}, + }, + { + name: "Max", + comment: "renders the max built-in function.", + variadic: true, + opening: "max(", + closing: ")", + separator: ",", + parameters: []string{"args"}, + }, { name: "Complex", comment: "renders the complex built-in function.", diff --git a/jen/examples_test.go b/jen/examples_test.go index 5eac19c..f1d825a 100644 --- a/jen/examples_test.go +++ b/jen/examples_test.go @@ -973,6 +973,41 @@ func ExampleClose() { // } } +func ExampleClear() { + c := Block( + Id("a").Op(":=").Map(String()).String().Values(), + Clear(Id("a")), + ) + fmt.Printf("%#v", c) + // Output: + // { + // a := map[string]string{} + // clear(a) + // } +} + +func ExampleMin() { + c := Block( + Id("n").Op(":=").Min(Lit(1), Lit(2)), + ) + fmt.Printf("%#v", c) + // Output: + // { + // n := min(1, 2) + // } +} + +func ExampleMax() { + c := Block( + Id("x").Op(":=").Max(Lit(1), Lit(2)), + ) + fmt.Printf("%#v", c) + // Output: + // { + // x := max(1, 2) + // } +} + func ExampleComment() { f := NewFile("a") f.Comment("Foo returns the string \"foo\"") diff --git a/jen/generated.go b/jen/generated.go index 30ceb78..7c52e3a 100644 --- a/jen/generated.go +++ b/jen/generated.go @@ -912,6 +912,136 @@ func (s *Statement) Close(c Code) *Statement { return s } +// Clear renders the clear built-in function. +func Clear(c Code) *Statement { + return newStatement().Clear(c) +} + +// Clear renders the clear built-in function. +func (g *Group) Clear(c Code) *Statement { + s := Clear(c) + g.items = append(g.items, s) + return s +} + +// Clear renders the clear built-in function. +func (s *Statement) Clear(c Code) *Statement { + g := &Group{ + close: ")", + items: []Code{c}, + multi: false, + name: "clear", + open: "clear(", + separator: ",", + } + *s = append(*s, g) + return s +} + +// Min renders the min built-in function. +func Min(args ...Code) *Statement { + return newStatement().Min(args...) +} + +// Min renders the min built-in function. +func (g *Group) Min(args ...Code) *Statement { + s := Min(args...) + g.items = append(g.items, s) + return s +} + +// Min renders the min built-in function. +func (s *Statement) Min(args ...Code) *Statement { + g := &Group{ + close: ")", + items: args, + multi: false, + name: "min", + open: "min(", + separator: ",", + } + *s = append(*s, g) + return s +} + +// MinFunc renders the min built-in function. +func MinFunc(f func(*Group)) *Statement { + return newStatement().MinFunc(f) +} + +// MinFunc renders the min built-in function. +func (g *Group) MinFunc(f func(*Group)) *Statement { + s := MinFunc(f) + g.items = append(g.items, s) + return s +} + +// MinFunc renders the min built-in function. +func (s *Statement) MinFunc(f func(*Group)) *Statement { + g := &Group{ + close: ")", + multi: false, + name: "min", + open: "min(", + separator: ",", + } + f(g) + *s = append(*s, g) + return s +} + +// Max renders the max built-in function. +func Max(args ...Code) *Statement { + return newStatement().Max(args...) +} + +// Max renders the max built-in function. +func (g *Group) Max(args ...Code) *Statement { + s := Max(args...) + g.items = append(g.items, s) + return s +} + +// Max renders the max built-in function. +func (s *Statement) Max(args ...Code) *Statement { + g := &Group{ + close: ")", + items: args, + multi: false, + name: "max", + open: "max(", + separator: ",", + } + *s = append(*s, g) + return s +} + +// MaxFunc renders the max built-in function. +func MaxFunc(f func(*Group)) *Statement { + return newStatement().MaxFunc(f) +} + +// MaxFunc renders the max built-in function. +func (g *Group) MaxFunc(f func(*Group)) *Statement { + s := MaxFunc(f) + g.items = append(g.items, s) + return s +} + +// MaxFunc renders the max built-in function. +func (s *Statement) MaxFunc(f func(*Group)) *Statement { + g := &Group{ + close: ")", + multi: false, + name: "max", + open: "max(", + separator: ",", + } + f(g) + *s = append(*s, g) + return s +} + // Complex renders the complex built-in function. func Complex(r Code, i Code) *Statement { return newStatement().Complex(r, i) diff --git a/jen/hints.go b/jen/hints.go index 9b54ef6..172c06b 100644 --- a/jen/hints.go +++ b/jen/hints.go @@ -8,6 +8,7 @@ var standardLibraryHints = map[string]string{ "archive/zip": "zip", "bufio": "bufio", "bytes": "bytes", + "cmp": "cmp", "compress/bzip2": "bzip2", "compress/flate": "flate", "compress/gzip": "gzip", @@ -112,6 +113,7 @@ var standardLibraryHints = map[string]string{ "image/png": "png", "index/suffixarray": "suffixarray", "internal/abi": "abi", + "internal/bisect": "bisect", "internal/buildcfg": "buildcfg", "internal/bytealg": "bytealg", "internal/cfg": "cfg", @@ -137,6 +139,7 @@ var standardLibraryHints = map[string]string{ "internal/fuzz": "fuzz", "internal/goarch": "goarch", "internal/godebug": "godebug", + "internal/godebugs": "godebugs", "internal/goexperiment": "goexperiment", "internal/goos": "goos", "internal/goroot": "goroot", @@ -168,11 +171,19 @@ var standardLibraryHints = map[string]string{ "internal/types/errors": "errors", "internal/unsafeheader": "unsafeheader", "internal/xcoff": "xcoff", + "internal/zstd": "zstd", "io": "io", "io/fs": "fs", "io/ioutil": "ioutil", "log": "log", + "log/internal": "internal", + "log/slog": "slog", + "log/slog/internal": "internal", + "log/slog/internal/benchmarks": "benchmarks", + "log/slog/internal/buffer": "buffer", + "log/slog/internal/slogtest": "slogtest", "log/syslog": "syslog", + "maps": "maps", "math": "math", "math/big": "big", "math/bits": "bits", @@ -221,10 +232,12 @@ var standardLibraryHints = map[string]string{ "runtime/internal/atomic": "atomic", "runtime/internal/math": "math", "runtime/internal/sys": "sys", + "runtime/internal/wasitest": "wasi", "runtime/metrics": "metrics", "runtime/pprof": "pprof", "runtime/race": "race", "runtime/trace": "trace", + "slices": "slices", "sort": "sort", "strconv": "strconv", "strings": "strings", @@ -236,6 +249,7 @@ var standardLibraryHints = map[string]string{ "testing/internal/testdeps": "testdeps", "testing/iotest": "iotest", "testing/quick": "quick", + "testing/slogtest": "slogtest", "text/scanner": "scanner", "text/tabwriter": "tabwriter", "text/template": "template", diff --git a/jen/reserved.go b/jen/reserved.go index 457668e..242cda8 100644 --- a/jen/reserved.go +++ b/jen/reserved.go @@ -4,7 +4,7 @@ var reserved = []string{ /* keywords */ "break", "default", "func", "interface", "select", "case", "defer", "go", "map", "struct", "chan", "else", "goto", "package", "switch", "const", "fallthrough", "if", "range", "type", "continue", "for", "import", "return", "var", /* predeclared */ - "bool", "byte", "complex64", "complex128", "error", "float32", "float64", "int", "int8", "int16", "int32", "int64", "rune", "string", "uint", "uint8", "uint16", "uint32", "uint64", "uintptr", "true", "false", "iota", "nil", "append", "cap", "close", "complex", "copy", "delete", "imag", "len", "make", "new", "panic", "print", "println", "real", "recover", + "bool", "byte", "complex64", "complex128", "error", "float32", "float64", "int", "int8", "int16", "int32", "int64", "rune", "string", "uint", "uint8", "uint16", "uint32", "uint64", "uintptr", "true", "false", "iota", "nil", "append", "cap", "close", "clear", "min", "max", "complex", "copy", "delete", "imag", "len", "make", "new", "panic", "print", "println", "real", "recover", /* common variables */ "err", }