nomino/generators_examples_test.go

66 lines
1.1 KiB
Go
Raw Normal View History

package nomino_test
2025-03-11 16:54:03 -05:00
import (
"fmt"
2025-03-11 16:54:03 -05:00
"codeberg.org/danjones000/nomino"
)
func ExampleWithGenerator_customGenerator() {
gen := func(*nomino.Config) (string, error) {
2025-03-11 16:54:03 -05:00
return "hello", nil
}
option := nomino.WithGenerator(gen)
2025-03-11 16:54:03 -05:00
str, _ := nomino.Make(nomino.NewConfig(option))
2025-03-11 16:54:03 -05:00
fmt.Println(str)
str, _ = nomino.Make(nomino.NewConfig(
option,
nomino.WithoutExtension(),
))
2025-03-11 16:54:03 -05:00
fmt.Println(str)
// Output:
// hello.txt
// hello
}
2025-03-14 21:22:29 -05:00
2025-03-15 16:24:37 -05:00
func ExampleGenerator_Make() {
g := nomino.Incremental()
st, _ := g.Make()
fmt.Println(st)
st, _ = g.Make(nomino.WithPrefix("foo"))
fmt.Println(st)
// Output:
// 0.txt
// foo_1.txt
}
2025-03-14 21:22:29 -05:00
func ExampleMultiGeneratorInOrder() {
gen1 := func(*nomino.Config) (string, error) {
return "hello", nil
}
gen2 := func(*nomino.Config) (string, error) {
return "goodbye", nil
}
gen := nomino.MultiGeneratorInOrder(gen1, gen2)
option := nomino.WithGenerator(gen)
str, _ := nomino.Make(nomino.NewConfig(option))
fmt.Println(str)
str, _ = nomino.Make(nomino.NewConfig(option))
fmt.Println(str)
str, _ = nomino.Make(nomino.NewConfig(option))
fmt.Println(str)
// Output:
// hello.txt
// goodbye.txt
// hello.txt
}