示例#1
0
func TestListFunc1(t *testing.T) {
	t.Log("Test custom template function - minus1")
	const await = "red, blue, white.\n"
	if got := easygen.Generate(false, "test/listfunc1"); got != await {
		t.Errorf("Mismatch:, got '%s' instead", got)
	}
}
示例#2
0
// Test the provided listfunc1, template and data
func ExampleGenerate_listfunc1() {
	// Equivalent testing on commandline:
	//   easygen test/listfunc1
	fmt.Print(easygen.Generate(false, "test/listfunc1"))
	// Output:
	// red, blue, white.
}
示例#3
0
func TestList1Text(t *testing.T) {
	t.Log("Second test, with text template")
	const await = "The quoted colors are: \"red\", \"blue\", \"white\", .\n"
	if got := easygen.Generate(false, "test/list1"); got != await {
		t.Errorf("Mismatch:, got '%s' instead", got)
	}
}
示例#4
0
func TestList1HTML(t *testing.T) {
	t.Log("Second test, with html template")
	const await = "The quoted colors are: "red", "blue", "white", .\n"
	if got := easygen.Generate(true, "test/list1"); got != await {
		t.Errorf("Mismatch:, got '%s' instead", got)
	}
}
示例#5
0
func TestList0(t *testing.T) {
	t.Log("First and plainest list test")
	const await = "The colors are: red, blue, white, .\n"
	if got := easygen.Generate(false, "test/list0"); got != await {
		t.Errorf("Mismatch:, got '%s' instead", got)
	}
}
示例#6
0
// Test the provided Cobra/Viper command line flag auto generation
func ExampleGenerate_commandLineCobraViper() {
	// Equivalent testing on commandline:
	//   easygen test/commandlineCV
	fmt.Print(easygen.Generate(false, "test/commandlineCV"))
	// Output:
	//
	//	flags.Bool("debug", false, "Turn on debugging.")
	//	viper.BindPFlag("debug", flags.Lookup("debug"))
	//
	//	flags.String("addr", "localhost:5002", "Address of the service.")
	//	viper.BindPFlag("addr", flags.Lookup("addr"))
	//
	//	flags.String("smtp-addr", "localhost:25", "Address of the SMTP server.")
	//	viper.BindPFlag("smtp-addr", flags.Lookup("smtp-addr"))
	//
	//	flags.String("smtp-user", "", "User for the SMTP server.")
	//	viper.BindPFlag("smtp-user", flags.Lookup("smtp-user"))
	//
	//	flags.String("smtp-password", "", "Password for the SMTP server.")
	//	viper.BindPFlag("smtp-password", flags.Lookup("smtp-password"))
	//
	//	flags.String("email-from", "*****@*****.**", "The from email address.")
	//	viper.BindPFlag("email-from", flags.Lookup("email-from"))
	//
}
示例#7
0
// Test the provided listfunc2, template and data
func ExampleGenerate_listfunc2() {
	// Equivalent testing on commandline:
	//   easygen test/listfunc2
	fmt.Print(easygen.Generate(false, "test/listfunc2"))
	// Output:
	// some-init-method 5 5 someInitMethod SomeInitMethod
}
示例#8
0
// Test the provided Cobra/Viper command line flag init() function auto generation
func ExampleGenerate_commandLineCobraViperInit() {
	// Equivalent testing on commandline:
	//   easygen test/commandlineCVFull
	fmt.Print(easygen.Generate(false, "test/commandlineCVFull"))
	// Output:
	// func init() {
	//
	//   viper.SetEnvPrefix("DISPATCH")
	//   viper.AutomaticEnv()
	//
	//   /*
	//
	//     When AutomaticEnv called, Viper will check for an environment variable any
	//     time a viper.Get request is made. It will apply the following rules. It
	//     will check for a environment variable with a name matching the key
	//     uppercased and prefixed with the EnvPrefix if set.
	//
	//   */
	//
	//   flags := mainCmd.Flags()
	//
	//   flags.Bool("Debug", false, "Turn on debugging.")
	//   viper.BindPFlag("Debug", flags.Lookup("Debug"))
	//
	//   flags.String("addr", "localhost:5002", "Address of the service.")
	//   viper.BindPFlag("addr", flags.Lookup("addr"))
	//
	//   flags.String("smtp-addr", "localhost:25", "Address of the SMTP server.")
	//   viper.BindPFlag("smtp-addr", flags.Lookup("smtp-addr"))
	//
	//   flags.String("smtp-user", "", "User for the SMTP server.")
	//   viper.BindPFlag("smtp-user", flags.Lookup("smtp-user"))
	//
	//   flags.String("smtp-password", "", "Password for the SMTP server.")
	//   viper.BindPFlag("smtp-password", flags.Lookup("smtp-password"))
	//
	//   flags.String("email-from", "*****@*****.**", "The from email address.")
	//   viper.BindPFlag("email-from", flags.Lookup("email-from"))
	//
	//   // Viper supports reading from yaml, toml and/or json files. Viper can
	//   // search multiple paths. Paths will be searched in the order they are
	//   // provided. Searches stopped once Config File found.
	//
	//   viper.SetConfigName("CommandLineCV") // name of config file (without extension)
	//
	//   viper.AddConfigPath("/tmp")
	//   viper.AddConfigPath(".")
	//
	//   err := viper.ReadInConfig()
	//   if err != nil {
	//     println("No config file found. Using built-in defaults.")
	//   }
	//
	// }
}
示例#9
0
func main() {
	flag.Usage = easygen.Usage
	flag.Parse()

	// One mandatory non-flag arguments
	if len(flag.Args()) < 1 {
		easygen.Usage()
	}
	fileName := flag.Args()[0]
	easygen.TFStringsInit()

	fmt.Print(easygen.Generate(easygen.Opts.HTML, fileName))
}