nomino/generators_examples_test.go

66 lines
1.2 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
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
}
func ExampleUUID() {
option := nomino.WithGenerator(nomino.UUID())
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)
}