♻️ 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
121
gen_int_examples_test.go
Normal file
121
gen_int_examples_test.go
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
package nomino_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"codeberg.org/danjones000/nomino"
|
||||
)
|
||||
|
||||
func ExampleIncremental() {
|
||||
conf := nomino.NewConfig(
|
||||
nomino.WithPrefix("foo"),
|
||||
nomino.WithGenerator(nomino.Incremental()),
|
||||
)
|
||||
|
||||
str, _ := nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
// Output:
|
||||
// foo_0.txt
|
||||
// foo_1.txt
|
||||
// foo_2.txt
|
||||
}
|
||||
|
||||
func ExampleIncrementalStart() {
|
||||
conf := nomino.NewConfig(
|
||||
nomino.WithPrefix("foo"),
|
||||
nomino.WithGenerator(nomino.Incremental(
|
||||
nomino.IncrementalStart(42),
|
||||
)),
|
||||
)
|
||||
|
||||
str, _ := nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
// Output:
|
||||
// foo_42.txt
|
||||
// foo_43.txt
|
||||
// foo_44.txt
|
||||
}
|
||||
|
||||
func ExampleIncrementalStep() {
|
||||
conf := nomino.NewConfig(
|
||||
nomino.WithPrefix("foo"),
|
||||
nomino.WithGenerator(nomino.Incremental(
|
||||
nomino.IncrementalStep(2),
|
||||
)),
|
||||
)
|
||||
|
||||
str, _ := nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
// Output:
|
||||
// foo_0.txt
|
||||
// foo_2.txt
|
||||
// foo_4.txt
|
||||
}
|
||||
|
||||
func ExampleIncremental_withStartAndStep() {
|
||||
conf := nomino.NewConfig(
|
||||
nomino.WithPrefix("foo"),
|
||||
nomino.WithGenerator(nomino.Incremental(
|
||||
nomino.IncrementalStart(42),
|
||||
nomino.IncrementalStep(2),
|
||||
)),
|
||||
)
|
||||
|
||||
str, _ := nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
// Output:
|
||||
// foo_42.txt
|
||||
// foo_44.txt
|
||||
// foo_46.txt
|
||||
}
|
||||
|
||||
func ExampleIncrementalFormat() {
|
||||
conf := nomino.NewConfig(
|
||||
nomino.WithPrefix("foo"),
|
||||
nomino.WithGenerator(nomino.Incremental(
|
||||
nomino.IncrementalFormat("%03d"),
|
||||
)),
|
||||
)
|
||||
|
||||
str, _ := nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
str, _ = nomino.Make(conf)
|
||||
fmt.Println(str)
|
||||
|
||||
// Output:
|
||||
// foo_000.txt
|
||||
// foo_001.txt
|
||||
// foo_002.txt
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue