79 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package nomino_test
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 
 | |
| 	"codeberg.org/danjones000/nomino"
 | |
| )
 | |
| 
 | |
| func ExampleWithGenerator_customGenerator() {
 | |
| 	var gen nomino.Generator = func(*nomino.Config) (string, error) {
 | |
| 		return "hello", nil
 | |
| 	}
 | |
| 
 | |
| 	str, _ := gen.Make()
 | |
| 	fmt.Println(str)
 | |
| 
 | |
| 	str, _ = gen.Make(nomino.WithoutExtension())
 | |
| 	fmt.Println(str)
 | |
| 
 | |
| 	// Output:
 | |
| 	// hello.txt
 | |
| 	// hello
 | |
| }
 | |
| 
 | |
| 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
 | |
| }
 | |
| 
 | |
| func ExampleMultiGeneratorInOrder() {
 | |
| 	gen1 := func(*nomino.Config) (string, error) {
 | |
| 		return "bonjour", nil
 | |
| 	}
 | |
| 	gen2 := func(*nomino.Config) (string, error) {
 | |
| 		return "goodbye", nil
 | |
| 	}
 | |
| 	gen := nomino.MultiGeneratorInOrder(gen1, gen2)
 | |
| 
 | |
| 	str, _ := gen.Make()
 | |
| 	fmt.Println(str)
 | |
| 
 | |
| 	str, _ = gen.Make()
 | |
| 	fmt.Println(str)
 | |
| 
 | |
| 	str, _ = gen.Make()
 | |
| 	fmt.Println(str)
 | |
| 
 | |
| 	// Output:
 | |
| 	// bonjour.txt
 | |
| 	// goodbye.txt
 | |
| 	// bonjour.txt
 | |
| }
 | |
| 
 | |
| func ExampleMultiGeneratorRandomOrder() {
 | |
| 	gen1 := func(*nomino.Config) (string, error) {
 | |
| 		return "guten-tag", nil
 | |
| 	}
 | |
| 	gen2 := func(*nomino.Config) (string, error) {
 | |
| 		return "wiedersehen", nil
 | |
| 	}
 | |
| 	gen := nomino.MultiGeneratorRandomOrder(gen1, gen2)
 | |
| 
 | |
| 	str, _ := gen.Make()
 | |
| 	fmt.Println(str)
 | |
| 
 | |
| 	str, _ = gen.Make()
 | |
| 	fmt.Println(str)
 | |
| 
 | |
| 	str, _ = gen.Make()
 | |
| 	fmt.Println(str)
 | |
| }
 |