nomino/generators_examples_test.go

80 lines
1.3 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() {
2025-03-15 21:00:54 -05:00
var gen nomino.Generator = func(*nomino.Config) (string, error) {
2025-03-11 16:54:03 -05:00
return "hello", nil
}
2025-03-15 21:00:54 -05:00
str, _ := gen.Make()
2025-03-11 16:54:03 -05:00
fmt.Println(str)
2025-03-15 21:00:54 -05:00
str, _ = gen.Make(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)
2025-03-15 21:00:54 -05:00
str, _ := gen.Make()
2025-03-14 21:22:29 -05:00
fmt.Println(str)
2025-03-15 21:00:54 -05:00
str, _ = gen.Make()
2025-03-14 21:22:29 -05:00
fmt.Println(str)
2025-03-15 21:00:54 -05:00
str, _ = gen.Make()
2025-03-14 21:22:29 -05:00
fmt.Println(str)
// Output:
// hello.txt
// goodbye.txt
// hello.txt
}
2025-03-15 21:00:54 -05:00
func ExampleMultiGeneratorRandomOrder() {
gen1 := func(*nomino.Config) (string, error) {
return "hello", nil
}
gen2 := func(*nomino.Config) (string, error) {
return "goodbye", nil
}
gen := nomino.MultiGeneratorRandomOrder(gen1, gen2)
str, _ := gen.Make()
fmt.Println(str)
str, _ = gen.Make()
fmt.Println(str)
str, _ = gen.Make()
fmt.Println(str)
}