♻️ Refactor Incremental Generator to single function with options
This commit is contained in:
parent
63d538d889
commit
586fe4f1de
4 changed files with 176 additions and 182 deletions
|
|
@ -19,133 +19,6 @@ func ExampleWithGenerator_custom_generator() {
|
|||
// 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 ExampleIncrementalFormat() {
|
||||
conf := NewConfig(
|
||||
WithPrefix("foo"),
|
||||
WithGenerator(IncrementalFormat("%03d")),
|
||||
)
|
||||
|
||||
str, _ := Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
// Output:
|
||||
// foo_000.txt
|
||||
// foo_001.txt
|
||||
// foo_002.txt
|
||||
}
|
||||
|
||||
func ExampleIncrementalFormatWithStart() {
|
||||
conf := NewConfig(
|
||||
WithPrefix("foo"),
|
||||
WithGenerator(IncrementalFormatWithStart(9, "%02d")),
|
||||
)
|
||||
|
||||
str, _ := Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
// Output:
|
||||
// foo_09.txt
|
||||
// foo_10.txt
|
||||
}
|
||||
|
||||
func ExampleIncrementalFormatWithStep() {
|
||||
conf := NewConfig(
|
||||
WithPrefix("foo"),
|
||||
WithGenerator(IncrementalFormatWithStep(10, "%02d")),
|
||||
)
|
||||
|
||||
str, _ := Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
// Output:
|
||||
// foo_00.txt
|
||||
// foo_10.txt
|
||||
}
|
||||
|
||||
func ExampleSlug() {
|
||||
conf := NewConfig(WithGenerator(Slug()), WithOriginal("My name is Jimmy"))
|
||||
str, _ := Make(conf)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue