108 lines
1.8 KiB
Go
108 lines
1.8 KiB
Go
package nomino
|
|
|
|
import "fmt"
|
|
|
|
func ExampleWithGenerator_custom_generator() {
|
|
gen := func(*Config) (string, error) {
|
|
return "hello", nil
|
|
}
|
|
option := WithGenerator(gen)
|
|
|
|
str, _ := Make(NewConfig(option))
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(NewConfig(option, WithoutExtension()))
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// hello.txt
|
|
// hello
|
|
}
|
|
|
|
func ExampleIncremental() {
|
|
conf := NewConfig(WithPrefix("foo"), WithGenerator(Incremental()))
|
|
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// foo_0.txt
|
|
// foo_1.txt
|
|
// foo_2.txt
|
|
}
|
|
|
|
func ExampleIncrementalWithStart() {
|
|
conf := NewConfig(WithPrefix("foo"), WithGenerator(IncrementalWithStart(42)))
|
|
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// foo_42.txt
|
|
// foo_43.txt
|
|
// foo_44.txt
|
|
}
|
|
|
|
func ExampleIncrementalWithStep() {
|
|
conf := NewConfig(WithPrefix("foo"), WithGenerator(IncrementalWithStep(2)))
|
|
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// foo_0.txt
|
|
// foo_2.txt
|
|
// foo_4.txt
|
|
}
|
|
|
|
func ExampleIncrementalWithStartAndStep() {
|
|
conf := NewConfig(WithPrefix("foo"), WithGenerator(IncrementalWithStartAndStep(42, 2)))
|
|
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
str, _ = Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output:
|
|
// foo_42.txt
|
|
// foo_44.txt
|
|
// foo_46.txt
|
|
}
|
|
|
|
func ExampleSlug() {
|
|
conf := NewConfig(WithGenerator(Slug()), WithOriginal("My name is Jimmy"))
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output: my-name-is-jimmy.txt
|
|
}
|
|
|
|
func ExampleSlugWithLang() {
|
|
conf := NewConfig(WithGenerator(SlugWithLang("de")), WithOriginal("Diese & Dass"))
|
|
str, _ := Make(conf)
|
|
fmt.Println(str)
|
|
|
|
// Output: diese-und-dass.txt
|
|
}
|