From 611b33b6e65fb1cf0eaec29c1390947fb1130e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=2E=20Garz=C3=A3o?= Date: Sun, 26 Oct 2025 09:21:06 -0300 Subject: [PATCH 01/11] chore: remove useless code --- internal/codegenerator/get_test_elements_all_types_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/codegenerator/get_test_elements_all_types_test.go b/internal/codegenerator/get_test_elements_all_types_test.go index 8590870..ccb2982 100644 --- a/internal/codegenerator/get_test_elements_all_types_test.go +++ b/internal/codegenerator/get_test_elements_all_types_test.go @@ -1150,7 +1150,6 @@ func TestDefineTestElementsWithAllTypes(t *testing.T) { return } for _, fieldType := range fieldTypes { - // op, _, _ := strings.Cut(tt.validation, "=") validation := replaceValidationValue(tt.validation, check.value) want := TestElements{ concatOperator: check.want.concatOperator, From e3246038bfe469d8a26e4127093b79ba5088b125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=2E=20Garz=C3=A3o?= Date: Sun, 26 Oct 2025 09:32:57 -0300 Subject: [PATCH 02/11] feat: testgen building end-to-end tests --- testgen/generate_tests.go | 13 + testgen/generate_validation_types_tests.go | 144 ++++ testgen/no_pointer_tests.tpl | 50 ++ testgen/pointer_tests.tpl | 58 ++ testgen/validations.go | 877 +++++++++++++++++++++ 5 files changed, 1142 insertions(+) create mode 100644 testgen/generate_tests.go create mode 100644 testgen/generate_validation_types_tests.go create mode 100644 testgen/no_pointer_tests.tpl create mode 100644 testgen/pointer_tests.tpl create mode 100644 testgen/validations.go diff --git a/testgen/generate_tests.go b/testgen/generate_tests.go new file mode 100644 index 0000000..154d76d --- /dev/null +++ b/testgen/generate_tests.go @@ -0,0 +1,13 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Generating tests files") + + generateValidationTypesTests() + + fmt.Println("Generating done") +} diff --git a/testgen/generate_validation_types_tests.go b/testgen/generate_validation_types_tests.go new file mode 100644 index 0000000..9b53221 --- /dev/null +++ b/testgen/generate_validation_types_tests.go @@ -0,0 +1,144 @@ +package main + +import ( + "bytes" + "fmt" + "go/format" + "log" + "os" + "strings" + "text/template" + + "github.com/opencodeco/validgen/internal/common" + "golang.org/x/text/cases" + "golang.org/x/text/language" +) + +type AllTestCasesToGenerate struct { + TestCases []TestCaseToGenerate +} + +type TestCaseToGenerate struct { + StructName string + Tests []TestCase +} + +type TestCase struct { + FieldName string + Validation string + FieldType string + BasicType string + ValidCase string + InvalidCase string + ErrorMessage string +} + +func generateValidationTypesTests() { + generateValidationTypesTestsFile("no_pointer_tests.tpl", "generated_no_pointer_tests.go", false) + generateValidationTypesTestsFile("pointer_tests.tpl", "generated_pointer_tests.go", true) +} + +func generateValidationTypesTestsFile(tpl, dest string, pointer bool) { + log.Printf("Generating validation types test file: tpl[%s] dest[%s] pointer[%v]\n", tpl, dest, pointer) + + allTestsToGenerate := AllTestCasesToGenerate{} + + for _, testCase := range typesValidation { + structName := testCase.tag + "StructFields" + if pointer { + structName += "Pointer" + } + allTestsToGenerate.TestCases = append(allTestsToGenerate.TestCases, TestCaseToGenerate{ + StructName: structName, + }) + for _, toGenerate := range testCase.testCases { + // Default ("") gen no pointer and pointer test. + if toGenerate.generateFor != "" { + if toGenerate.generateFor == "pointer" && !pointer { + continue + } + if toGenerate.generateFor == "nopointer" && pointer { + continue + } + } + normalizedType := toGenerate.typeClass + if pointer { + normalizedType = "*" + normalizedType + } + fTypes := common.HelperFromNormalizedToBasicTypes(normalizedType) + sNames := common.HelperFromNormalizedToStringNames(normalizedType) + for i := range fTypes { + validation := testCase.tag + if testCase.argsCount != common.ZeroValue { + validation += "=" + toGenerate.validation + } + fieldName := "Field" + cases.Title(language.Und).String(testCase.tag) + sNames[i] + basicType, _ := strings.CutPrefix(fTypes[i], "*") + + errorMessage := toGenerate.errorMessage + errorMessage = strings.ReplaceAll(errorMessage, "{{.FieldName}}", fieldName) + errorMessage = strings.ReplaceAll(errorMessage, "{{.Target}}", toGenerate.validation) + errorMessage = strings.ReplaceAll(errorMessage, "{{.Targets}}", targetsInMessage(toGenerate.validation)) + + allTestsToGenerate.TestCases[len(allTestsToGenerate.TestCases)-1].Tests = append(allTestsToGenerate.TestCases[len(allTestsToGenerate.TestCases)-1].Tests, TestCase{ + FieldName: fieldName, + Validation: validation, + FieldType: fTypes[i], + BasicType: basicType, + ValidCase: strings.ReplaceAll(toGenerate.validCase, "{{.BasicType}}", basicType), + InvalidCase: strings.ReplaceAll(toGenerate.invalidCase, "{{.BasicType}}", basicType), + ErrorMessage: errorMessage, + }) + } + } + } + + if err := allTestsToGenerate.GenerateFile(tpl, dest); err != nil { + log.Fatalf("error generation validation types file %s", err) + } + + log.Printf("Generating %s done\n", dest) +} + +func (at *AllTestCasesToGenerate) GenerateFile(tplFile, output string) error { + tpl, err := os.ReadFile(tplFile) + if err != nil { + return fmt.Errorf("error reading %s: %s", tplFile, err) + } + + tmpl, err := template.New("ValidationTypesTests").Parse(string(tpl)) + if err != nil { + return err + } + + code := new(bytes.Buffer) + if err := tmpl.Execute(code, at); err != nil { + return err + } + + // if err := os.WriteFile(output, code.Bytes(), 0644); err != nil { + // return err + // } + + formattedCode, err := format.Source(code.Bytes()) + if err != nil { + return err + } + + if err := os.WriteFile(output, formattedCode, 0644); err != nil { + return err + } + + return nil +} + +func targetsInMessage(validation string) string { + tokens := strings.Split(validation, " ") + + msg := "" + for _, token := range tokens { + msg += "'" + token + "' " + } + + return strings.TrimSpace(msg) +} diff --git a/testgen/no_pointer_tests.tpl b/testgen/no_pointer_tests.tpl new file mode 100644 index 0000000..8badfdf --- /dev/null +++ b/testgen/no_pointer_tests.tpl @@ -0,0 +1,50 @@ +// Code generated by TestGenerator. DO NOT EDIT. + +package main + +import ( + "log" +) + +func noPointerTests() { +{{range .TestCases}}{{.StructName}}Tests() +{{end}} +} + +{{range .TestCases}} + +type {{.StructName}} struct { + {{range .Tests}}{{.FieldName}} {{.FieldType}} `valid:"{{.Validation}}"` + {{end}} +} + +func {{.StructName}}Tests() { + log.Println("starting {{.StructName}} types tests") + + var expectedMsgErrors []string + var errs []error + + // Test case 1: All failure scenarios (invalid cases) + v := &{{.StructName}}{} + expectedMsgErrors = []string{ + {{range .Tests}}"{{.ErrorMessage}}", + {{end}} + } + + {{range .Tests}}{{ if ne .InvalidCase "--" }}v.{{.FieldName}} = {{.InvalidCase}}{{end}} + {{end}} + errs = {{.StructName}}Validate(v) + assertExpectedErrorMsgs("testcase 1", errs, expectedMsgErrors) + + // Test case 2: All valid cases + v = &{{.StructName}}{} + {{range .Tests}}v.{{.FieldName}} = {{.ValidCase}} + {{end}} + expectedMsgErrors = nil + errs = {{.StructName}}Validate(v) + assertExpectedErrorMsgs("testcase 2", errs, expectedMsgErrors) + + log.Println("{{.StructName}} types tests ok") +} + +{{end}} \ No newline at end of file diff --git a/testgen/pointer_tests.tpl b/testgen/pointer_tests.tpl new file mode 100644 index 0000000..6528758 --- /dev/null +++ b/testgen/pointer_tests.tpl @@ -0,0 +1,58 @@ +// Code generated by TestGenerator. DO NOT EDIT. + +package main + +import ( + "log" +) + +func pointerTests() { +{{range .TestCases}}{{.StructName}}Tests() +{{end}} +} + +{{range .TestCases}} + +type {{.StructName}} struct { + {{range .Tests}}{{.FieldName}} {{.FieldType}} `valid:"{{.Validation}}"` + {{end}} +} + +func {{.StructName}}Tests() { + log.Println("starting {{.StructName}} types tests") + + var expectedMsgErrors []string + var errs []error + + // Test case 1: All failure scenarios (nil values) + v := &{{.StructName}}{} + expectedMsgErrors = []string{ + {{range .Tests}}"{{.ErrorMessage}}", + {{end}} + } + errs = {{.StructName}}Validate(v) + assertExpectedErrorMsgs("testcase 1", errs, expectedMsgErrors) + + // Test case 2: All failure scenarios (invalid cases) + {{range .Tests}}{{ if ne .InvalidCase "--" }}var Invalid{{.FieldName}} {{.BasicType}} = {{.InvalidCase}}{{end}} + {{end}} + v = &{{.StructName}}{} + {{range .Tests}}{{ if ne .InvalidCase "--" }}v.{{.FieldName}} = &Invalid{{.FieldName}}{{end}} + {{end}} + errs = {{.StructName}}Validate(v) + assertExpectedErrorMsgs("testcase 2", errs, expectedMsgErrors) + + // Test case 3: All valid cases + {{range .Tests}}var Valid{{.FieldName}} {{.BasicType}} = {{.ValidCase}} + {{end}} + v = &{{.StructName}}{} + {{range .Tests}}v.{{.FieldName}} = &Valid{{.FieldName}} + {{end}} + expectedMsgErrors = nil + errs = {{.StructName}}Validate(v) + assertExpectedErrorMsgs("testcase 3", errs, expectedMsgErrors) + + log.Println("{{.StructName}} types tests ok") +} + +{{end}} \ No newline at end of file diff --git a/testgen/validations.go b/testgen/validations.go new file mode 100644 index 0000000..c0c5661 --- /dev/null +++ b/testgen/validations.go @@ -0,0 +1,877 @@ +package main + +import "github.com/opencodeco/validgen/internal/common" + +type typeValidation struct { + typeClass string + validation string + validCase string + invalidCase string + errorMessage string + generateFor string +} + +var typesValidation = []struct { + tag string + validatorTag string + isFieldValidation bool + argsCount common.CountValues + testCases []typeValidation +}{ + // email operations + { + tag: "email", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.ZeroValue, + testCases: []typeValidation{ + { + // email: "" + typeClass: ``, + validation: ``, + validCase: `"abcde@example.com"`, + invalidCase: `"abcde@example"`, + errorMessage: `{{.FieldName}} must be a valid email`, + }, + }, + }, + + // required operations + { + tag: "required", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.ZeroValue, + testCases: []typeValidation{ + // required: "", "", "", "" + { + typeClass: ``, + validation: ``, + validCase: `"abcde"`, + invalidCase: `""`, + errorMessage: `{{.FieldName}} is required`, + }, + { + typeClass: ``, + validation: ``, + validCase: `32`, + invalidCase: `0`, + errorMessage: `{{.FieldName}} is required`, + }, + { + typeClass: ``, + validation: ``, + validCase: `12.34`, + invalidCase: `0`, + errorMessage: `{{.FieldName}} is required`, + }, + { + typeClass: ``, + validation: ``, + validCase: `true`, + invalidCase: `false`, + errorMessage: `{{.FieldName}} is required`, + }, + + // required: "[]", "[]", "[]", "[]" + { + typeClass: `[]`, + validation: ``, + validCase: `{{.BasicType}}{"abcde"}`, + invalidCase: `{{.BasicType}}{}`, + errorMessage: `{{.FieldName}} must not be empty`, + }, + { + typeClass: `[]`, + validation: ``, + validCase: `{{.BasicType}}{32}`, + invalidCase: `{{.BasicType}}{}`, + errorMessage: `{{.FieldName}} must not be empty`, + }, + { + typeClass: `[]`, + validation: ``, + validCase: `{{.BasicType}}{12.34}`, + invalidCase: `{{.BasicType}}{}`, + errorMessage: `{{.FieldName}} must not be empty`, + }, + { + typeClass: `[]`, + validation: ``, + validCase: `{{.BasicType}}{true}`, + invalidCase: `{{.BasicType}}{}`, + errorMessage: `{{.FieldName}} must not be empty`, + }, + + // required: "[N]", "[N]", "[N]", "[N]" + { + typeClass: `[N]`, + validation: ``, + validCase: `{{.BasicType}}{"abcde"}`, + invalidCase: `--`, + errorMessage: `{{.FieldName}} must not be empty`, + generateFor: "pointer", + }, + { + typeClass: `[N]`, + validation: ``, + validCase: `{{.BasicType}}{32}`, + invalidCase: `--`, + errorMessage: `{{.FieldName}} must not be empty`, + generateFor: "pointer", + }, + { + typeClass: `[N]`, + validation: ``, + validCase: `{{.BasicType}}{12.34}`, + invalidCase: `--`, + errorMessage: `{{.FieldName}} must not be empty`, + generateFor: "pointer", + }, + { + typeClass: `[N]`, + validation: ``, + validCase: `{{.BasicType}}{true}`, + invalidCase: `--`, + errorMessage: `{{.FieldName}} must not be empty`, + generateFor: "pointer", + }, + + // required: "map[]", "map[]", "map[]", "map[]" + { + typeClass: `map[]`, + validation: ``, + validCase: `{{.BasicType}}{"abcde":"value"}`, + invalidCase: `{{.BasicType}}{}`, + errorMessage: `{{.FieldName}} must not be empty`, + }, + { + typeClass: `map[]`, + validation: ``, + validCase: `{{.BasicType}}{32:64}`, + invalidCase: `{{.BasicType}}{}`, + errorMessage: `{{.FieldName}} must not be empty`, + }, + { + typeClass: `map[]`, + validation: ``, + validCase: `{{.BasicType}}{12.34:56.78}`, + invalidCase: `{{.BasicType}}{}`, + errorMessage: `{{.FieldName}} must not be empty`, + }, + { + typeClass: `map[]`, + validation: ``, + validCase: `{{.BasicType}}{true:true}`, + invalidCase: `{{.BasicType}}{}`, + errorMessage: `{{.FieldName}} must not be empty`, + }, + }, + }, + + // eq operations + { + tag: "eq", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.OneValue, + testCases: []typeValidation{ + // eq: "", "", "", "" + { + typeClass: ``, + validation: `abcde`, + validCase: `"abcde"`, + invalidCase: `"fghij"`, + errorMessage: `{{.FieldName}} must be equal to '{{.Target}}'`, + }, + { + typeClass: ``, + validation: `32`, + validCase: `32`, + invalidCase: `64`, + errorMessage: `{{.FieldName}} must be equal to {{.Target}}`, + }, + { + typeClass: ``, + validation: `12.34`, + validCase: `12.34`, + invalidCase: `34.56`, + errorMessage: `{{.FieldName}} must be equal to {{.Target}}`, + }, + { + typeClass: ``, + validation: `true`, + validCase: `true`, + invalidCase: `false`, + errorMessage: `{{.FieldName}} must be equal to {{.Target}}`, + }, + }, + }, + + // neq operations + { + tag: "neq", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.OneValue, + testCases: []typeValidation{ + // neq: "", "", "", "" + { + typeClass: ``, + validation: `abcde`, + validCase: `"fghij"`, + invalidCase: `"abcde"`, + errorMessage: `{{.FieldName}} must not be equal to '{{.Target}}'`, + }, + { + typeClass: ``, + validation: `32`, + validCase: `64`, + invalidCase: `32`, + errorMessage: `{{.FieldName}} must not be equal to {{.Target}}`, + }, + { + typeClass: ``, + validation: `12.34`, + validCase: `34.56`, + invalidCase: `12.34`, + errorMessage: `{{.FieldName}} must not be equal to {{.Target}}`, + }, + { + typeClass: ``, + validation: `true`, + validCase: `false`, + invalidCase: `true`, + errorMessage: `{{.FieldName}} must not be equal to {{.Target}}`, + }, + }, + }, + + // gt operations + { + tag: "gt", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.OneValue, + testCases: []typeValidation{ + // gt: "", "" + { + typeClass: ``, + validation: `32`, + validCase: `33`, + invalidCase: `31`, + errorMessage: `{{.FieldName}} must be > {{.Target}}`, + }, + { + typeClass: ``, + validation: `12.34`, + validCase: `12.35`, + invalidCase: `12.34`, + errorMessage: `{{.FieldName}} must be > {{.Target}}`, + }, + }, + }, + + // gte operations + { + tag: "gte", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.OneValue, + testCases: []typeValidation{ + // gte: "", "" + { + typeClass: ``, + validation: `32`, + validCase: `32`, + invalidCase: `31`, + errorMessage: `{{.FieldName}} must be >= {{.Target}}`, + }, + { + typeClass: ``, + validation: `12.34`, + validCase: `12.34`, + invalidCase: `12.33`, + errorMessage: `{{.FieldName}} must be >= {{.Target}}`, + }, + }, + }, + + // lt operations + { + tag: "lt", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.OneValue, + testCases: []typeValidation{ + // lt: "", "" + { + typeClass: ``, + validation: `32`, + validCase: `31`, + invalidCase: `33`, + errorMessage: `{{.FieldName}} must be < {{.Target}}`, + }, + { + typeClass: ``, + validation: `12.34`, + validCase: `12.33`, + invalidCase: `12.35`, + errorMessage: `{{.FieldName}} must be < {{.Target}}`, + }, + }, + }, + + // lte operations + { + tag: "lte", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.OneValue, + testCases: []typeValidation{ + // lte: "", "" + { + typeClass: ``, + validation: `32`, + validCase: `32`, + invalidCase: `33`, + errorMessage: `{{.FieldName}} must be <= {{.Target}}`, + }, + { + typeClass: ``, + validation: `12.34`, + validCase: `12.34`, + invalidCase: `12.35`, + errorMessage: `{{.FieldName}} must be <= {{.Target}}`, + }, + }, + }, + + // min operations + { + tag: "min", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.OneValue, + testCases: []typeValidation{ + // min: "" + { + typeClass: ``, + validation: `5`, + validCase: `"abcde"`, + invalidCase: `"abc"`, + errorMessage: `{{.FieldName}} length must be >= {{.Target}}`, + }, + + // min: "[]", "[]", "[]", "[]" + { + typeClass: `[]`, + validation: `2`, + validCase: `{{.BasicType}}{"abc", "def"}`, + invalidCase: `{{.BasicType}}{"abc"}`, + errorMessage: `{{.FieldName}} must have at least {{.Target}} elements`, + }, + { + typeClass: `[]`, + validation: `2`, + validCase: `{{.BasicType}}{65, 67}`, + invalidCase: `{{.BasicType}}{65}`, + errorMessage: `{{.FieldName}} must have at least {{.Target}} elements`, + }, + { + typeClass: `[]`, + validation: `2`, + validCase: `{{.BasicType}}{65.65, 67.67}`, + invalidCase: `{{.BasicType}}{65.65}`, + errorMessage: `{{.FieldName}} must have at least {{.Target}} elements`, + }, + { + typeClass: `[]`, + validation: `2`, + validCase: `{{.BasicType}}{true, false}`, + invalidCase: `{{.BasicType}}{true}`, + errorMessage: `{{.FieldName}} must have at least {{.Target}} elements`, + }, + + // min: "map[]", "map[]", "map[]", "map[]" + { + typeClass: `map[]`, + validation: `2`, + validCase: `{{.BasicType}}{"a": "1", "b": "2"}`, + invalidCase: `{{.BasicType}}{"a": "1"}`, + errorMessage: `{{.FieldName}} must have at least {{.Target}} elements`, + }, + { + typeClass: `map[]`, + validation: `2`, + validCase: `{{.BasicType}}{1: 65, 2: 67}`, + invalidCase: `{{.BasicType}}{1: 65}`, + errorMessage: `{{.FieldName}} must have at least {{.Target}} elements`, + }, + { + typeClass: `map[]`, + validation: `2`, + validCase: `{{.BasicType}}{1: 65.65, 2: 67.67}`, + invalidCase: `{{.BasicType}}{1: 65.65}`, + errorMessage: `{{.FieldName}} must have at least {{.Target}} elements`, + }, + { + typeClass: `map[]`, + validation: `2`, + validCase: `{{.BasicType}}{true: true, false: false}`, + invalidCase: `{{.BasicType}}{true: true}`, + errorMessage: `{{.FieldName}} must have at least {{.Target}} elements`, + }, + }, + }, + + // max operations + { + tag: "max", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.OneValue, + testCases: []typeValidation{ + // max: "" + { + typeClass: ``, + validation: `3`, + validCase: `"abc"`, + invalidCase: `"abcde"`, + errorMessage: `{{.FieldName}} length must be <= 3`, + }, + + // max: "[]", "[]", "[]", "[]" + { + typeClass: `[]`, + validation: `2`, + validCase: `{{.BasicType}}{"abc", "def"}`, + invalidCase: `{{.BasicType}}{"abc", "def", "ghi"}`, + errorMessage: `{{.FieldName}} must have at most {{.Target}} elements`, + }, + { + typeClass: `[]`, + validation: `2`, + validCase: `{{.BasicType}}{65, 67}`, + invalidCase: `{{.BasicType}}{65, 66, 67}`, + errorMessage: `{{.FieldName}} must have at most {{.Target}} elements`, + }, + { + typeClass: `[]`, + validation: `2`, + validCase: `{{.BasicType}}{65.65, 67.67}`, + invalidCase: `{{.BasicType}}{65.65, 66.66, 67.67}`, + errorMessage: `{{.FieldName}} must have at most {{.Target}} elements`, + }, + { + typeClass: `[]`, + validation: `2`, + validCase: `{{.BasicType}}{true, false}`, + invalidCase: `{{.BasicType}}{true, false, true}`, + errorMessage: `{{.FieldName}} must have at most {{.Target}} elements`, + }, + + // max: "map[]", "map[]", "map[]", "map[]" + { + typeClass: `map[]`, + validation: `2`, + validCase: `{{.BasicType}}{"a": "1", "b": "2"}`, + invalidCase: `{{.BasicType}}{"a": "1", "b": "2", "c": "3"}`, + errorMessage: `{{.FieldName}} must have at most {{.Target}} elements`, + }, + { + typeClass: `map[]`, + validation: `2`, + validCase: `{{.BasicType}}{1: 65, 2: 67}`, + invalidCase: `{{.BasicType}}{1: 65, 2: 67, 3: 68}`, + errorMessage: `{{.FieldName}} must have at most {{.Target}} elements`, + }, + { + typeClass: `map[]`, + validation: `2`, + validCase: `{{.BasicType}}{1: 65.65, 2: 67.67}`, + invalidCase: `{{.BasicType}}{1: 65.65, 2: 66.66, 3: 67.67}`, + errorMessage: `{{.FieldName}} must have at most {{.Target}} elements`, + }, + { + typeClass: `map[]`, + validation: `1`, + validCase: `{{.BasicType}}{true: true}`, + invalidCase: `{{.BasicType}}{true: true, false: false}`, + errorMessage: `{{.FieldName}} must have at most {{.Target}} elements`, + }, + }, + }, + + // eq_ignore_case operations + { + tag: "eq_ignore_case", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.OneValue, + testCases: []typeValidation{ + // eq_ignore_case: "" + { + typeClass: ``, + validation: `abcde`, + validCase: `"AbCdE"`, + invalidCase: `"a1b2c3"`, + errorMessage: `{{.FieldName}} must be equal to '{{.Target}}'`, + }, + }, + }, + + // neq_ignore_case operations + { + tag: "neq_ignore_case", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.OneValue, + testCases: []typeValidation{ + // neq_ignore_case: "" + { + typeClass: ``, + validation: `abcde`, + validCase: `"a1b2c3"`, + invalidCase: `"AbCdE"`, + errorMessage: `{{.FieldName}} must not be equal to '{{.Target}}'`, + }, + }, + }, + + // len operations + { + tag: "len", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.OneValue, + testCases: []typeValidation{ + // len: "" + { + typeClass: ``, + validation: `2`, + validCase: `"ab"`, + invalidCase: `"abcde"`, + errorMessage: `{{.FieldName}} length must be {{.Target}}`, + }, + + // len: "[]", "[]", "[]", "[]" + { + typeClass: `[]`, + validation: `2`, + validCase: `{{.BasicType}}{"abc", "def"}`, + invalidCase: `{{.BasicType}}{"abc", "def", "ghi"}`, + errorMessage: `{{.FieldName}} must have exactly {{.Target}} elements`, + }, + { + typeClass: `[]`, + validation: `2`, + validCase: `{{.BasicType}}{65, 67}`, + invalidCase: `{{.BasicType}}{65, 66, 67}`, + errorMessage: `{{.FieldName}} must have exactly {{.Target}} elements`, + }, + { + typeClass: `[]`, + validation: `2`, + validCase: `{{.BasicType}}{65.65, 67.67}`, + invalidCase: `{{.BasicType}}{65.65, 66.66, 67.67}`, + errorMessage: `{{.FieldName}} must have exactly {{.Target}} elements`, + }, + { + typeClass: `[]`, + validation: `2`, + validCase: `{{.BasicType}}{true, false}`, + invalidCase: `{{.BasicType}}{true, false, true}`, + errorMessage: `{{.FieldName}} must have exactly {{.Target}} elements`, + }, + + // len: "map[]", "map[]", "map[]", "map[]" + { + typeClass: `map[]`, + validation: `2`, + validCase: `{{.BasicType}}{"a": "1", "b": "2"}`, + invalidCase: `{{.BasicType}}{"a": "1", "b": "2", "c": "3"}`, + errorMessage: `{{.FieldName}} must have exactly {{.Target}} elements`, + }, + { + typeClass: `map[]`, + validation: `2`, + validCase: `{{.BasicType}}{1: 65, 2: 67}`, + invalidCase: `{{.BasicType}}{1: 65, 2: 67, 3: 68}`, + errorMessage: `{{.FieldName}} must have exactly {{.Target}} elements`, + }, + { + typeClass: `map[]`, + validation: `2`, + validCase: `{{.BasicType}}{1: 65.65, 2: 67.67}`, + invalidCase: `{{.BasicType}}{1: 65.65, 2: 66.66, 3: 67.67}`, + errorMessage: `{{.FieldName}} must have exactly {{.Target}} elements`, + }, + { + typeClass: `map[]`, + validation: `2`, + validCase: `{{.BasicType}}{true: true, false: false}`, + invalidCase: `{{.BasicType}}{true: true}`, + errorMessage: `{{.FieldName}} must have exactly {{.Target}} elements`, + }, + }, + }, + + // in operations + { + tag: "in", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.ManyValues, + testCases: []typeValidation{ + // in: "", "", "", "" + { + typeClass: ``, + validation: `ab cd ef`, + validCase: `"cd"`, + invalidCase: `"fg"`, + errorMessage: `{{.FieldName}} must be one of {{.Targets}}`, + }, + { + typeClass: ``, + validation: `12 34 56`, + validCase: `34`, + invalidCase: `78`, + errorMessage: `{{.FieldName}} must be one of {{.Targets}}`, + }, + { + typeClass: ``, + validation: `11.11 22.22 33.33`, + validCase: `22.22`, + invalidCase: `44.44`, + errorMessage: `{{.FieldName}} must be one of {{.Targets}}`, + }, + { + typeClass: ``, + validation: `true`, + validCase: `true`, + invalidCase: `false`, + errorMessage: `{{.FieldName}} must be one of {{.Targets}}`, + }, + + // in: "[]", "[]", "[]", "[]" + { + typeClass: `[]`, + validation: `ab cd ef`, + validCase: `{{.BasicType}}{"ab", "ef"}`, + invalidCase: `{{.BasicType}}{"ab", "gh", "ef"}`, + errorMessage: `{{.FieldName}} elements must be one of {{.Targets}}`, + }, + { + typeClass: `[]`, + validation: `12 34 56`, + validCase: `{{.BasicType}}{12, 56}`, + invalidCase: `{{.BasicType}}{12, 78, 56}`, + errorMessage: `{{.FieldName}} elements must be one of {{.Targets}}`, + }, + { + typeClass: `[]`, + validation: `11.11 22.22 33.33`, + validCase: `{{.BasicType}}{11.11, 22.22}`, + invalidCase: `{{.BasicType}}{11.11, 44.44, 33.33}`, + errorMessage: `{{.FieldName}} elements must be one of {{.Targets}}`, + }, + { + typeClass: `[]`, + validation: `true`, + validCase: `{{.BasicType}}{true, true}`, + invalidCase: `{{.BasicType}}{true, false, true}`, + errorMessage: `{{.FieldName}} elements must be one of {{.Targets}}`, + }, + + // in: "[]", "[]", "[]", "[]" + { + typeClass: `[N]`, + validation: `ab cd ef`, + validCase: `{{.BasicType}}{"ab", "ef", "ab"}`, + invalidCase: `{{.BasicType}}{"ab", "gh", "ef"}`, + errorMessage: `{{.FieldName}} elements must be one of {{.Targets}}`, + }, + { + typeClass: `[N]`, + validation: `12 34 56`, + validCase: `{{.BasicType}}{12, 56, 12}`, + invalidCase: `{{.BasicType}}{12, 78, 56}`, + errorMessage: `{{.FieldName}} elements must be one of {{.Targets}}`, + }, + { + typeClass: `[N]`, + validation: `11.11 22.22 33.33`, + validCase: `{{.BasicType}}{11.11, 22.22, 11.11}`, + invalidCase: `{{.BasicType}}{11.11, 44.44, 33.33}`, + errorMessage: `{{.FieldName}} elements must be one of {{.Targets}}`, + }, + { + typeClass: `[N]`, + validation: `true`, + validCase: `{{.BasicType}}{true, true, true}`, + invalidCase: `{{.BasicType}}{true, false, true}`, + errorMessage: `{{.FieldName}} elements must be one of {{.Targets}}`, + }, + + // in: "map[]", "map[]", "map[]", "map[]" + { + typeClass: `map[]`, + validation: `a b c`, + validCase: `{{.BasicType}}{"a": "1", "b": "2", "c": "3"}`, + invalidCase: `{{.BasicType}}{"a": "1", "d": "9", "c": "3"}`, + errorMessage: `{{.FieldName}} elements must be one of {{.Targets}}`, + }, + { + typeClass: `map[]`, + validation: `1 2 3`, + validCase: `{{.BasicType}}{1: 65, 2: 67, 3: 68}`, + invalidCase: `{{.BasicType}}{1: 65, 4: 69, 3: 68}`, + errorMessage: `{{.FieldName}} elements must be one of {{.Targets}}`, + }, + { + typeClass: `map[]`, + validation: `11.11 22.22 33.33`, + validCase: `{{.BasicType}}{11.11: 11.11, 22.22: 22.22, 33.33: 33.33}`, + invalidCase: `{{.BasicType}}{11.11: 11.11, 44.44: 44.44, 33.33: 33.33}`, + errorMessage: `{{.FieldName}} elements must be one of {{.Targets}}`, + }, + { + typeClass: `map[]`, + validation: `false`, + validCase: `{{.BasicType}}{false: false}`, + invalidCase: `{{.BasicType}}{true: true, false: false}`, + errorMessage: `{{.FieldName}} elements must be one of {{.Targets}}`, + }, + }, + }, + + // nin operations + { + tag: "nin", + validatorTag: ``, + isFieldValidation: false, + argsCount: common.ManyValues, + testCases: []typeValidation{ + // nin: "[]", "[]", "[]", "[]" + { + typeClass: ``, + validation: `ab cd ef`, + validCase: `"fg"`, + invalidCase: `"cd"`, + errorMessage: `{{.FieldName}} must not be one of {{.Targets}}`, + }, + { + typeClass: ``, + validation: `12 34 56`, + validCase: `78`, + invalidCase: `34`, + errorMessage: `{{.FieldName}} must not be one of {{.Targets}}`, + }, + { + typeClass: ``, + validation: `11.11 22.22 33.33`, + validCase: `44.44`, + invalidCase: `22.22`, + errorMessage: `{{.FieldName}} must not be one of {{.Targets}}`, + }, + { + typeClass: ``, + validation: `true`, + validCase: `false`, + invalidCase: `true`, + errorMessage: `{{.FieldName}} must not be one of {{.Targets}}`, + }, + + // nin: "[]", "[]", "[]", "[]" + { + typeClass: `[]`, + validation: `ab cd ef`, + validCase: `{{.BasicType}}{"gh", "ij", "kl"}`, + invalidCase: `{{.BasicType}}{"ab", "ef"}`, + errorMessage: `{{.FieldName}} elements must not be one of {{.Targets}}`, + }, + { + typeClass: `[]`, + validation: `12 34 56`, + validCase: `{{.BasicType}}{78, 91}`, + invalidCase: `{{.BasicType}}{12, 78, 56}`, + errorMessage: `{{.FieldName}} elements must not be one of {{.Targets}}`, + }, + { + typeClass: `[]`, + validation: `11.11 22.22 33.33`, + validCase: `{{.BasicType}}{44.44, 55.55, 66.66}`, + invalidCase: `{{.BasicType}}{11.11, 44.44, 33.33}`, + errorMessage: `{{.FieldName}} elements must not be one of {{.Targets}}`, + }, + { + typeClass: `[]`, + validation: `true`, + validCase: `{{.BasicType}}{false, false, false}`, + invalidCase: `{{.BasicType}}{true, false, true}`, + errorMessage: `{{.FieldName}} elements must not be one of {{.Targets}}`, + }, + + // nin: "[]", "[]", "[]", "[]" + { + typeClass: `[N]`, + validation: `ab cd ef`, + validCase: `{{.BasicType}}{"gh", "ij", "kl"}`, + invalidCase: `{{.BasicType}}{"ab", "gh", "ef"}`, + errorMessage: `{{.FieldName}} elements must not be one of {{.Targets}}`, + }, + { + typeClass: `[N]`, + validation: `12 34 56`, + validCase: `{{.BasicType}}{78, 91, 23}`, + invalidCase: `{{.BasicType}}{12, 78, 56}`, + errorMessage: `{{.FieldName}} elements must not be one of {{.Targets}}`, + }, + { + typeClass: `[N]`, + validation: `11.11 22.22 33.33`, + validCase: `{{.BasicType}}{44.44, 55.55, 66.66}`, + invalidCase: `{{.BasicType}}{11.11, 44.44, 33.33}`, + errorMessage: `{{.FieldName}} elements must not be one of {{.Targets}}`, + }, + { + typeClass: `[N]`, + validation: `true`, + validCase: `{{.BasicType}}{false, false, false}`, + invalidCase: `{{.BasicType}}{true, false, true}`, + errorMessage: `{{.FieldName}} elements must not be one of {{.Targets}}`, + }, + + // nin: "map[]", "map[]", "map[]", "map[]" + { + typeClass: `map[]`, + validation: `a b c`, + validCase: `{{.BasicType}}{"d": "1", "e": "2", "f": "3"}`, + invalidCase: `{{.BasicType}}{"a": "1", "d": "9", "c": "3"}`, + errorMessage: `{{.FieldName}} elements must not be one of {{.Targets}}`, + }, + { + typeClass: `map[]`, + validation: `1 2 3`, + validCase: `{{.BasicType}}{5: 55, 6: 66, 7: 77}`, + invalidCase: `{{.BasicType}}{1: 11, 4: 44, 3: 33}`, + errorMessage: `{{.FieldName}} elements must not be one of {{.Targets}}`, + }, + { + typeClass: `map[]`, + validation: `11.11 22.22 33.33`, + validCase: `{{.BasicType}}{44.44: 44.44, 55.55: 55.55, 66.66: 66.66}`, + invalidCase: `{{.BasicType}}{11.11: 11.11, 44.44: 44.44, 33.33: 33.33}`, + errorMessage: `{{.FieldName}} elements must not be one of {{.Targets}}`, + }, + { + typeClass: `map[]`, + validation: `false`, + validCase: `{{.BasicType}}{true: true}`, + invalidCase: `{{.BasicType}}{true: true, false: false}`, + errorMessage: `{{.FieldName}} elements must not be one of {{.Targets}}`, + }, + }, + }, +} From 2cdca9917b9d57923c89a9f336dd895d0e1c13da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=2E=20Garz=C3=A3o?= Date: Sun, 26 Oct 2025 13:01:02 -0300 Subject: [PATCH 03/11] chore: turn public GenValidations api --- .../build_func_validator_test.go | 2 +- internal/codegenerator/build_validator.go | 10 +++---- .../codegenerator/build_validator_test.go | 26 +++++++++---------- internal/codegenerator/codegen.go | 4 +-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/internal/codegenerator/build_func_validator_test.go b/internal/codegenerator/build_func_validator_test.go index 48741a2..6108d9a 100644 --- a/internal/codegenerator/build_func_validator_test.go +++ b/internal/codegenerator/build_func_validator_test.go @@ -173,7 +173,7 @@ return errs for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gv := genValidations{ + gv := GenValidations{ Struct: tt.fields.Struct, } got, err := gv.BuildFuncValidatorCode() diff --git a/internal/codegenerator/build_validator.go b/internal/codegenerator/build_validator.go index 0ff1891..07a3f2b 100644 --- a/internal/codegenerator/build_validator.go +++ b/internal/codegenerator/build_validator.go @@ -27,12 +27,12 @@ type fieldTpl struct { Validations []*analyzer.Validation } -func (gv *genValidations) BuildFuncValidatorCode() (string, error) { +func (gv *GenValidations) BuildFuncValidatorCode() (string, error) { stTpl := StructToTpl(gv.Struct) funcMap := template.FuncMap{ - "buildValidationCode": gv.buildValidationCode, + "buildValidationCode": gv.BuildValidationCode, } tmpl, err := template.New("FuncValidator").Funcs(funcMap).Parse(funcValidatorTpl) @@ -48,7 +48,7 @@ func (gv *genValidations) BuildFuncValidatorCode() (string, error) { return code.String(), nil } -func (gv *genValidations) buildValidationCode(fieldName string, fieldType common.FieldType, fieldValidations []*analyzer.Validation) (string, error) { +func (gv *GenValidations) BuildValidationCode(fieldName string, fieldType common.FieldType, fieldValidations []*analyzer.Validation) (string, error) { tests := "" for _, fieldValidation := range fieldValidations { @@ -73,7 +73,7 @@ func (gv *genValidations) buildValidationCode(fieldName string, fieldType common return tests, nil } -func (gv *genValidations) buildIfCode(fieldName string, fieldType common.FieldType, fieldValidation *analyzer.Validation) (string, error) { +func (gv *GenValidations) buildIfCode(fieldName string, fieldType common.FieldType, fieldValidation *analyzer.Validation) (string, error) { testElements, err := DefineTestElements(fieldName, fieldType, fieldValidation) if err != nil { return "", fmt.Errorf("field %s: %w", fieldName, err) @@ -95,7 +95,7 @@ errs = append(errs, types.NewValidationError("%s")) `, booleanCondition, testElements.errorMessage), nil } -func (gv *genValidations) buildIfNestedCode(fieldName string, fieldType common.FieldType) (string, error) { +func (gv *GenValidations) buildIfNestedCode(fieldName string, fieldType common.FieldType) (string, error) { _, ok := gv.StructsWithValidation[fieldType.BaseType] if !ok { return "", fmt.Errorf("no validator found for struct type %s", fieldType) diff --git a/internal/codegenerator/build_validator_test.go b/internal/codegenerator/build_validator_test.go index c5bfcf6..ae53669 100644 --- a/internal/codegenerator/build_validator_test.go +++ b/internal/codegenerator/build_validator_test.go @@ -9,7 +9,7 @@ import ( "github.com/opencodeco/validgen/internal/parser" ) -func TestBuildValidationCode(t *testing.T) { +func TestBuildValidationCodeOld(t *testing.T) { type args struct { fieldName string fieldType common.FieldType @@ -259,15 +259,15 @@ errs = append(errs, types.NewValidationError("mapField must have exactly 3 eleme for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gv := genValidations{} + gv := GenValidations{} validation := AssertParserValidation(t, tt.args.fieldValidation) - got, err := gv.buildValidationCode(tt.args.fieldName, tt.args.fieldType, []*analyzer.Validation{validation}) + got, err := gv.BuildValidationCode(tt.args.fieldName, tt.args.fieldType, []*analyzer.Validation{validation}) if err != nil { - t.Errorf("buildValidationCode() error = %v, wantErr %v", err, nil) + t.Errorf("BuildValidationCode() error = %v, wantErr %v", err, nil) return } if got != tt.want { - t.Errorf("buildValidationCode() = %v, want %v", got, tt.want) + t.Errorf("BuildValidationCode() = %v, want %v", got, tt.want) } }) } @@ -330,7 +330,7 @@ errs = append(errs, types.NewValidationError("Field must have at least 2 element for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gv := genValidations{ + gv := GenValidations{ Struct: &analyzer.Struct{ Struct: parser.Struct{ PackageName: "main", @@ -340,13 +340,13 @@ errs = append(errs, types.NewValidationError("Field must have at least 2 element } gv.StructsWithValidation[tt.args.fieldType.BaseType] = struct{}{} validation := AssertParserValidation(t, tt.args.fieldValidation) - got, err := gv.buildValidationCode(tt.args.fieldName, tt.args.fieldType, []*analyzer.Validation{validation}) + got, err := gv.BuildValidationCode(tt.args.fieldName, tt.args.fieldType, []*analyzer.Validation{validation}) if err != nil { - t.Errorf("buildValidationCode() error = %v, wantErr %v", err, nil) + t.Errorf("BuildValidationCode() error = %v, wantErr %v", err, nil) return } if got != tt.want { - t.Errorf("buildValidationCode() = %v, want %v", got, tt.want) + t.Errorf("BuildValidationCode() = %v, want %v", got, tt.want) } }) } @@ -506,15 +506,15 @@ errs = append(errs, types.NewValidationError("field must have exactly 3 elements for _, tt := range tests { testName := fmt.Sprintf("validation: %s with %s (%s)", tt.validation, tt.fieldType.ToGenericType(), tt.fieldType.ToNormalizedString()) t.Run(testName, func(t *testing.T) { - gv := genValidations{} + gv := GenValidations{} validation := AssertParserValidation(t, tt.validation) - got, err := gv.buildValidationCode("field", tt.fieldType, []*analyzer.Validation{validation}) + got, err := gv.BuildValidationCode("field", tt.fieldType, []*analyzer.Validation{validation}) if err != nil { - t.Errorf("buildValidationCode() error = %v, wantErr %v", err, nil) + t.Errorf("BuildValidationCode() error = %v, wantErr %v", err, nil) return } if got != tt.want { - t.Errorf("buildValidationCode() = %v, want %v", got, tt.want) + t.Errorf("BuildValidationCode() = %v, want %v", got, tt.want) } }) } diff --git a/internal/codegenerator/codegen.go b/internal/codegenerator/codegen.go index fe581f6..c56991a 100644 --- a/internal/codegenerator/codegen.go +++ b/internal/codegenerator/codegen.go @@ -6,7 +6,7 @@ import ( "github.com/opencodeco/validgen/internal/parser" ) -type genValidations struct { +type GenValidations struct { StructsWithValidation map[string]struct{} Struct *analyzer.Struct } @@ -26,7 +26,7 @@ func GenerateCode(structs []*analyzer.Struct) (map[string]*Pkg, error) { continue } - codeInfo := &genValidations{ + codeInfo := &GenValidations{ StructsWithValidation: structsWithValidation, Struct: st, } From c2142d242c3b735db1a51d7adf83853c4550d486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=2E=20Garz=C3=A3o?= Date: Sun, 26 Oct 2025 13:04:47 -0300 Subject: [PATCH 04/11] feat: testgen bulding validation code tests --- testgen/build_validation_code_test.tpl | 47 ++++++++ testgen/generate_tests.go | 1 + testgen/generate_validation_code_tests.go | 127 +++++++++++++++++++++ testgen/generate_validation_types_tests.go | 4 +- 4 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 testgen/build_validation_code_test.tpl create mode 100644 testgen/generate_validation_code_tests.go diff --git a/testgen/build_validation_code_test.tpl b/testgen/build_validation_code_test.tpl new file mode 100644 index 0000000..c80c514 --- /dev/null +++ b/testgen/build_validation_code_test.tpl @@ -0,0 +1,47 @@ +package codegenerator + +import ( + "testing" + + "github.com/opencodeco/validgen/internal/analyzer" + "github.com/opencodeco/validgen/internal/common" +) + +func {{.FuncName}}(t *testing.T) { + type args struct { + fieldName string + fieldType common.FieldType + fieldValidation string + } + tests := []struct { + name string + args args + want string + }{ +{{range .Tests}} { + name: "{{.TestName}}", + args: args{ + fieldName: "{{.FieldName}}", + fieldType: common.FieldType{ComposedType: "{{.FieldType.ComposedType}}", BaseType: "{{.FieldType.BaseType}}", Size: "{{.FieldType.Size}}"}, + fieldValidation: "{{.Validation}}", + }, + want: `{{.ExpectedCode}}`, + }, +{{end}} + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gv := GenValidations{} + validation := AssertParserValidation(t, tt.args.fieldValidation) + got, err := gv.BuildValidationCode(tt.args.fieldName, tt.args.fieldType, []*analyzer.Validation{validation}) + if err != nil { + t.Errorf("BuildValidationCode() error = %v, wantErr %v", err, nil) + return + } + if got != tt.want { + t.Errorf("BuildValidationCode() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/testgen/generate_tests.go b/testgen/generate_tests.go index 154d76d..3a2775a 100644 --- a/testgen/generate_tests.go +++ b/testgen/generate_tests.go @@ -8,6 +8,7 @@ func main() { fmt.Println("Generating tests files") generateValidationTypesTests() + generateValidationCodeTests() fmt.Println("Generating done") } diff --git a/testgen/generate_validation_code_tests.go b/testgen/generate_validation_code_tests.go new file mode 100644 index 0000000..6eadbcc --- /dev/null +++ b/testgen/generate_validation_code_tests.go @@ -0,0 +1,127 @@ +package main + +import ( + "bytes" + "fmt" + "go/format" + "log" + "os" + "text/template" + + "github.com/opencodeco/validgen/internal/analyzer" + "github.com/opencodeco/validgen/internal/codegenerator" + "github.com/opencodeco/validgen/internal/common" + "golang.org/x/text/cases" + "golang.org/x/text/language" +) + +type ValidationCodeTestCases struct { + FuncName string + Tests []ValidationCodeTestCase +} + +type ValidationCodeTestCase struct { + TestName string + FieldName string + FieldType common.FieldType + Validation string + ExpectedCode string +} + +func generateValidationCodeTests() { + generateValidationCodeTestsFile("build_validation_code_test.tpl", "generated_validation_code_no_pointer_test.go", false) + generateValidationCodeTestsFile("build_validation_code_test.tpl", "generated_validation_code_pointer_test.go", true) +} + +func generateValidationCodeTestsFile(tpl, dest string, pointer bool) { + log.Printf("Generating validation code test file: tpl[%s] dest[%s] pointer[%v]\n", tpl, dest, pointer) + + funcName := "TestBuildValidationCode" + if pointer { + funcName += "Pointer" + } + + testCases := ValidationCodeTestCases{ + FuncName: funcName, + } + + for _, typeValidation := range typesValidation { + for _, toGenerate := range typeValidation.testCases { + // Default ("") gen no pointer and pointer test. + if toGenerate.generateFor != "" { + if toGenerate.generateFor == "pointer" && !pointer { + continue + } + if toGenerate.generateFor == "nopointer" && pointer { + continue + } + } + + normalizedType := toGenerate.typeClass + if pointer { + normalizedType = "*" + normalizedType + } + + fieldTypes, _ := common.HelperFromNormalizedToFieldTypes(normalizedType) + for _, fieldType := range fieldTypes { + validation := typeValidation.tag + if typeValidation.argsCount != common.ZeroValue { + validation += "=" + toGenerate.validation + } + testName := fmt.Sprintf("%s_%s_%s", typeValidation.tag, cases.Lower(language.Und).String(fieldType.ToStringName()), validation) + fieldName := "Field" + cases.Title(language.Und).String(typeValidation.tag) + fieldType.ToStringName() + gv := codegenerator.GenValidations{} + parsedValidation, err := analyzer.ParserValidation(validation) + if err != nil { + log.Fatalf("failed to parse validation %q: %v", validation, err) + } + expectedValidationCode, err := gv.BuildValidationCode(fieldName, fieldType, []*analyzer.Validation{parsedValidation}) + if err != nil { + log.Fatalf("failed to build validation code for %q: %v", fieldName, err) + } + + testCases.Tests = append(testCases.Tests, ValidationCodeTestCase{ + TestName: testName, + FieldName: fieldName, + FieldType: fieldType, + Validation: validation, + ExpectedCode: expectedValidationCode, + }) + } + } + } + + if err := testCases.GenerateFile(tpl, dest); err != nil { + log.Fatalf("error generation validation code tests file %s", err) + } + + log.Printf("Generating %s done\n", dest) +} + +func (at *ValidationCodeTestCases) GenerateFile(tplFile, output string) error { + tpl, err := os.ReadFile(tplFile) + if err != nil { + return fmt.Errorf("error reading %s: %s", tplFile, err) + } + + tmpl, err := template.New("ValidationCodeTests").Parse(string(tpl)) + if err != nil { + return err + } + + code := new(bytes.Buffer) + if err := tmpl.Execute(code, at); err != nil { + return err + } + + formattedCode, err := format.Source(code.Bytes()) + if err != nil { + return err + } + + if err := os.WriteFile(output, formattedCode, 0644); err != nil { + return err + } + + return nil +} diff --git a/testgen/generate_validation_types_tests.go b/testgen/generate_validation_types_tests.go index 9b53221..3c84647 100644 --- a/testgen/generate_validation_types_tests.go +++ b/testgen/generate_validation_types_tests.go @@ -34,8 +34,8 @@ type TestCase struct { } func generateValidationTypesTests() { - generateValidationTypesTestsFile("no_pointer_tests.tpl", "generated_no_pointer_tests.go", false) - generateValidationTypesTestsFile("pointer_tests.tpl", "generated_pointer_tests.go", true) + generateValidationTypesTestsFile("no_pointer_tests.tpl", "generated_endtoend_no_pointer_tests.go", false) + generateValidationTypesTestsFile("pointer_tests.tpl", "generated_endtoend_pointer_tests.go", true) } func generateValidationTypesTestsFile(tpl, dest string, pointer bool) { From f6bdb383b08f8b3daf88fe7280bb0dfc60befc87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=2E=20Garz=C3=A3o?= Date: Sun, 26 Oct 2025 13:06:25 -0300 Subject: [PATCH 05/11] test: add generated validation code test files --- ...nerated_validation_code_no_pointer_test.go | 3877 ++++++++++++++++ .../generated_validation_code_pointer_test.go | 4045 +++++++++++++++++ 2 files changed, 7922 insertions(+) create mode 100644 internal/codegenerator/generated_validation_code_no_pointer_test.go create mode 100644 internal/codegenerator/generated_validation_code_pointer_test.go diff --git a/internal/codegenerator/generated_validation_code_no_pointer_test.go b/internal/codegenerator/generated_validation_code_no_pointer_test.go new file mode 100644 index 0000000..ed605a7 --- /dev/null +++ b/internal/codegenerator/generated_validation_code_no_pointer_test.go @@ -0,0 +1,3877 @@ +package codegenerator + +import ( + "testing" + + "github.com/opencodeco/validgen/internal/analyzer" + "github.com/opencodeco/validgen/internal/common" +) + +func TestBuildValidationCode(t *testing.T) { + type args struct { + fieldName string + fieldType common.FieldType + fieldValidation string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "email_string_email", + args: args{ + fieldName: "FieldEmailString", + fieldType: common.FieldType{ComposedType: "", BaseType: "string", Size: ""}, + fieldValidation: "email", + }, + want: `if !(types.IsValidEmail(obj.FieldEmailString)) { +errs = append(errs, types.NewValidationError("FieldEmailString must be a valid email")) +} +`, + }, + { + name: "required_string_required", + args: args{ + fieldName: "FieldRequiredString", + fieldType: common.FieldType{ComposedType: "", BaseType: "string", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredString != "") { +errs = append(errs, types.NewValidationError("FieldRequiredString is required")) +} +`, + }, + { + name: "required_int_required", + args: args{ + fieldName: "FieldRequiredInt", + fieldType: common.FieldType{ComposedType: "", BaseType: "int", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt is required")) +} +`, + }, + { + name: "required_int8_required", + args: args{ + fieldName: "FieldRequiredInt8", + fieldType: common.FieldType{ComposedType: "", BaseType: "int8", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt8 != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt8 is required")) +} +`, + }, + { + name: "required_int16_required", + args: args{ + fieldName: "FieldRequiredInt16", + fieldType: common.FieldType{ComposedType: "", BaseType: "int16", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt16 != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt16 is required")) +} +`, + }, + { + name: "required_int32_required", + args: args{ + fieldName: "FieldRequiredInt32", + fieldType: common.FieldType{ComposedType: "", BaseType: "int32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt32 != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt32 is required")) +} +`, + }, + { + name: "required_int64_required", + args: args{ + fieldName: "FieldRequiredInt64", + fieldType: common.FieldType{ComposedType: "", BaseType: "int64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt64 != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt64 is required")) +} +`, + }, + { + name: "required_uint_required", + args: args{ + fieldName: "FieldRequiredUint", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint is required")) +} +`, + }, + { + name: "required_uint8_required", + args: args{ + fieldName: "FieldRequiredUint8", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint8", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint8 != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint8 is required")) +} +`, + }, + { + name: "required_uint16_required", + args: args{ + fieldName: "FieldRequiredUint16", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint16", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint16 != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint16 is required")) +} +`, + }, + { + name: "required_uint32_required", + args: args{ + fieldName: "FieldRequiredUint32", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint32 != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint32 is required")) +} +`, + }, + { + name: "required_uint64_required", + args: args{ + fieldName: "FieldRequiredUint64", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint64 != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint64 is required")) +} +`, + }, + { + name: "required_float32_required", + args: args{ + fieldName: "FieldRequiredFloat32", + fieldType: common.FieldType{ComposedType: "", BaseType: "float32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredFloat32 != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat32 is required")) +} +`, + }, + { + name: "required_float64_required", + args: args{ + fieldName: "FieldRequiredFloat64", + fieldType: common.FieldType{ComposedType: "", BaseType: "float64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredFloat64 != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat64 is required")) +} +`, + }, + { + name: "required_bool_required", + args: args{ + fieldName: "FieldRequiredBool", + fieldType: common.FieldType{ComposedType: "", BaseType: "bool", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredBool != false) { +errs = append(errs, types.NewValidationError("FieldRequiredBool is required")) +} +`, + }, + { + name: "required_stringslice_required", + args: args{ + fieldName: "FieldRequiredStringSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "string", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredStringSlice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredStringSlice must not be empty")) +} +`, + }, + { + name: "required_intslice_required", + args: args{ + fieldName: "FieldRequiredIntSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredIntSlice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredIntSlice must not be empty")) +} +`, + }, + { + name: "required_int8slice_required", + args: args{ + fieldName: "FieldRequiredInt8Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int8", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredInt8Slice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt8Slice must not be empty")) +} +`, + }, + { + name: "required_int16slice_required", + args: args{ + fieldName: "FieldRequiredInt16Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int16", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredInt16Slice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt16Slice must not be empty")) +} +`, + }, + { + name: "required_int32slice_required", + args: args{ + fieldName: "FieldRequiredInt32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredInt32Slice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt32Slice must not be empty")) +} +`, + }, + { + name: "required_int64slice_required", + args: args{ + fieldName: "FieldRequiredInt64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredInt64Slice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt64Slice must not be empty")) +} +`, + }, + { + name: "required_uintslice_required", + args: args{ + fieldName: "FieldRequiredUintSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredUintSlice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUintSlice must not be empty")) +} +`, + }, + { + name: "required_uint8slice_required", + args: args{ + fieldName: "FieldRequiredUint8Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint8", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredUint8Slice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint8Slice must not be empty")) +} +`, + }, + { + name: "required_uint16slice_required", + args: args{ + fieldName: "FieldRequiredUint16Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint16", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredUint16Slice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint16Slice must not be empty")) +} +`, + }, + { + name: "required_uint32slice_required", + args: args{ + fieldName: "FieldRequiredUint32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredUint32Slice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint32Slice must not be empty")) +} +`, + }, + { + name: "required_uint64slice_required", + args: args{ + fieldName: "FieldRequiredUint64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredUint64Slice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint64Slice must not be empty")) +} +`, + }, + { + name: "required_float32slice_required", + args: args{ + fieldName: "FieldRequiredFloat32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "float32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredFloat32Slice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat32Slice must not be empty")) +} +`, + }, + { + name: "required_float64slice_required", + args: args{ + fieldName: "FieldRequiredFloat64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "float64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredFloat64Slice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat64Slice must not be empty")) +} +`, + }, + { + name: "required_boolslice_required", + args: args{ + fieldName: "FieldRequiredBoolSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "bool", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredBoolSlice) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredBoolSlice must not be empty")) +} +`, + }, + { + name: "required_stringmap_required", + args: args{ + fieldName: "FieldRequiredStringMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "string", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredStringMap) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredStringMap must not be empty")) +} +`, + }, + { + name: "required_intmap_required", + args: args{ + fieldName: "FieldRequiredIntMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredIntMap) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredIntMap must not be empty")) +} +`, + }, + { + name: "required_int8map_required", + args: args{ + fieldName: "FieldRequiredInt8Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int8", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredInt8Map) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt8Map must not be empty")) +} +`, + }, + { + name: "required_int16map_required", + args: args{ + fieldName: "FieldRequiredInt16Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int16", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredInt16Map) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt16Map must not be empty")) +} +`, + }, + { + name: "required_int32map_required", + args: args{ + fieldName: "FieldRequiredInt32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredInt32Map) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt32Map must not be empty")) +} +`, + }, + { + name: "required_int64map_required", + args: args{ + fieldName: "FieldRequiredInt64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredInt64Map) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt64Map must not be empty")) +} +`, + }, + { + name: "required_uintmap_required", + args: args{ + fieldName: "FieldRequiredUintMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredUintMap) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUintMap must not be empty")) +} +`, + }, + { + name: "required_uint8map_required", + args: args{ + fieldName: "FieldRequiredUint8Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint8", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredUint8Map) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint8Map must not be empty")) +} +`, + }, + { + name: "required_uint16map_required", + args: args{ + fieldName: "FieldRequiredUint16Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint16", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredUint16Map) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint16Map must not be empty")) +} +`, + }, + { + name: "required_uint32map_required", + args: args{ + fieldName: "FieldRequiredUint32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredUint32Map) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint32Map must not be empty")) +} +`, + }, + { + name: "required_uint64map_required", + args: args{ + fieldName: "FieldRequiredUint64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredUint64Map) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint64Map must not be empty")) +} +`, + }, + { + name: "required_float32map_required", + args: args{ + fieldName: "FieldRequiredFloat32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "float32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredFloat32Map) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat32Map must not be empty")) +} +`, + }, + { + name: "required_float64map_required", + args: args{ + fieldName: "FieldRequiredFloat64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "float64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredFloat64Map) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat64Map must not be empty")) +} +`, + }, + { + name: "required_boolmap_required", + args: args{ + fieldName: "FieldRequiredBoolMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "bool", Size: ""}, + fieldValidation: "required", + }, + want: `if !(len(obj.FieldRequiredBoolMap) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredBoolMap must not be empty")) +} +`, + }, + { + name: "eq_string_eq=abcde", + args: args{ + fieldName: "FieldEqString", + fieldType: common.FieldType{ComposedType: "", BaseType: "string", Size: ""}, + fieldValidation: "eq=abcde", + }, + want: `if !(obj.FieldEqString == "abcde") { +errs = append(errs, types.NewValidationError("FieldEqString must be equal to 'abcde'")) +} +`, + }, + { + name: "eq_int_eq=32", + args: args{ + fieldName: "FieldEqInt", + fieldType: common.FieldType{ComposedType: "", BaseType: "int", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqInt == 32) { +errs = append(errs, types.NewValidationError("FieldEqInt must be equal to 32")) +} +`, + }, + { + name: "eq_int8_eq=32", + args: args{ + fieldName: "FieldEqInt8", + fieldType: common.FieldType{ComposedType: "", BaseType: "int8", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqInt8 == 32) { +errs = append(errs, types.NewValidationError("FieldEqInt8 must be equal to 32")) +} +`, + }, + { + name: "eq_int16_eq=32", + args: args{ + fieldName: "FieldEqInt16", + fieldType: common.FieldType{ComposedType: "", BaseType: "int16", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqInt16 == 32) { +errs = append(errs, types.NewValidationError("FieldEqInt16 must be equal to 32")) +} +`, + }, + { + name: "eq_int32_eq=32", + args: args{ + fieldName: "FieldEqInt32", + fieldType: common.FieldType{ComposedType: "", BaseType: "int32", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqInt32 == 32) { +errs = append(errs, types.NewValidationError("FieldEqInt32 must be equal to 32")) +} +`, + }, + { + name: "eq_int64_eq=32", + args: args{ + fieldName: "FieldEqInt64", + fieldType: common.FieldType{ComposedType: "", BaseType: "int64", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqInt64 == 32) { +errs = append(errs, types.NewValidationError("FieldEqInt64 must be equal to 32")) +} +`, + }, + { + name: "eq_uint_eq=32", + args: args{ + fieldName: "FieldEqUint", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqUint == 32) { +errs = append(errs, types.NewValidationError("FieldEqUint must be equal to 32")) +} +`, + }, + { + name: "eq_uint8_eq=32", + args: args{ + fieldName: "FieldEqUint8", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint8", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqUint8 == 32) { +errs = append(errs, types.NewValidationError("FieldEqUint8 must be equal to 32")) +} +`, + }, + { + name: "eq_uint16_eq=32", + args: args{ + fieldName: "FieldEqUint16", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint16", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqUint16 == 32) { +errs = append(errs, types.NewValidationError("FieldEqUint16 must be equal to 32")) +} +`, + }, + { + name: "eq_uint32_eq=32", + args: args{ + fieldName: "FieldEqUint32", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint32", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqUint32 == 32) { +errs = append(errs, types.NewValidationError("FieldEqUint32 must be equal to 32")) +} +`, + }, + { + name: "eq_uint64_eq=32", + args: args{ + fieldName: "FieldEqUint64", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint64", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqUint64 == 32) { +errs = append(errs, types.NewValidationError("FieldEqUint64 must be equal to 32")) +} +`, + }, + { + name: "eq_float32_eq=12.34", + args: args{ + fieldName: "FieldEqFloat32", + fieldType: common.FieldType{ComposedType: "", BaseType: "float32", Size: ""}, + fieldValidation: "eq=12.34", + }, + want: `if !(obj.FieldEqFloat32 == 12.34) { +errs = append(errs, types.NewValidationError("FieldEqFloat32 must be equal to 12.34")) +} +`, + }, + { + name: "eq_float64_eq=12.34", + args: args{ + fieldName: "FieldEqFloat64", + fieldType: common.FieldType{ComposedType: "", BaseType: "float64", Size: ""}, + fieldValidation: "eq=12.34", + }, + want: `if !(obj.FieldEqFloat64 == 12.34) { +errs = append(errs, types.NewValidationError("FieldEqFloat64 must be equal to 12.34")) +} +`, + }, + { + name: "eq_bool_eq=true", + args: args{ + fieldName: "FieldEqBool", + fieldType: common.FieldType{ComposedType: "", BaseType: "bool", Size: ""}, + fieldValidation: "eq=true", + }, + want: `if !(obj.FieldEqBool == true) { +errs = append(errs, types.NewValidationError("FieldEqBool must be equal to true")) +} +`, + }, + { + name: "neq_string_neq=abcde", + args: args{ + fieldName: "FieldNeqString", + fieldType: common.FieldType{ComposedType: "", BaseType: "string", Size: ""}, + fieldValidation: "neq=abcde", + }, + want: `if !(obj.FieldNeqString != "abcde") { +errs = append(errs, types.NewValidationError("FieldNeqString must not be equal to 'abcde'")) +} +`, + }, + { + name: "neq_int_neq=32", + args: args{ + fieldName: "FieldNeqInt", + fieldType: common.FieldType{ComposedType: "", BaseType: "int", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqInt != 32) { +errs = append(errs, types.NewValidationError("FieldNeqInt must not be equal to 32")) +} +`, + }, + { + name: "neq_int8_neq=32", + args: args{ + fieldName: "FieldNeqInt8", + fieldType: common.FieldType{ComposedType: "", BaseType: "int8", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqInt8 != 32) { +errs = append(errs, types.NewValidationError("FieldNeqInt8 must not be equal to 32")) +} +`, + }, + { + name: "neq_int16_neq=32", + args: args{ + fieldName: "FieldNeqInt16", + fieldType: common.FieldType{ComposedType: "", BaseType: "int16", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqInt16 != 32) { +errs = append(errs, types.NewValidationError("FieldNeqInt16 must not be equal to 32")) +} +`, + }, + { + name: "neq_int32_neq=32", + args: args{ + fieldName: "FieldNeqInt32", + fieldType: common.FieldType{ComposedType: "", BaseType: "int32", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqInt32 != 32) { +errs = append(errs, types.NewValidationError("FieldNeqInt32 must not be equal to 32")) +} +`, + }, + { + name: "neq_int64_neq=32", + args: args{ + fieldName: "FieldNeqInt64", + fieldType: common.FieldType{ComposedType: "", BaseType: "int64", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqInt64 != 32) { +errs = append(errs, types.NewValidationError("FieldNeqInt64 must not be equal to 32")) +} +`, + }, + { + name: "neq_uint_neq=32", + args: args{ + fieldName: "FieldNeqUint", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqUint != 32) { +errs = append(errs, types.NewValidationError("FieldNeqUint must not be equal to 32")) +} +`, + }, + { + name: "neq_uint8_neq=32", + args: args{ + fieldName: "FieldNeqUint8", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint8", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqUint8 != 32) { +errs = append(errs, types.NewValidationError("FieldNeqUint8 must not be equal to 32")) +} +`, + }, + { + name: "neq_uint16_neq=32", + args: args{ + fieldName: "FieldNeqUint16", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint16", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqUint16 != 32) { +errs = append(errs, types.NewValidationError("FieldNeqUint16 must not be equal to 32")) +} +`, + }, + { + name: "neq_uint32_neq=32", + args: args{ + fieldName: "FieldNeqUint32", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint32", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqUint32 != 32) { +errs = append(errs, types.NewValidationError("FieldNeqUint32 must not be equal to 32")) +} +`, + }, + { + name: "neq_uint64_neq=32", + args: args{ + fieldName: "FieldNeqUint64", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint64", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqUint64 != 32) { +errs = append(errs, types.NewValidationError("FieldNeqUint64 must not be equal to 32")) +} +`, + }, + { + name: "neq_float32_neq=12.34", + args: args{ + fieldName: "FieldNeqFloat32", + fieldType: common.FieldType{ComposedType: "", BaseType: "float32", Size: ""}, + fieldValidation: "neq=12.34", + }, + want: `if !(obj.FieldNeqFloat32 != 12.34) { +errs = append(errs, types.NewValidationError("FieldNeqFloat32 must not be equal to 12.34")) +} +`, + }, + { + name: "neq_float64_neq=12.34", + args: args{ + fieldName: "FieldNeqFloat64", + fieldType: common.FieldType{ComposedType: "", BaseType: "float64", Size: ""}, + fieldValidation: "neq=12.34", + }, + want: `if !(obj.FieldNeqFloat64 != 12.34) { +errs = append(errs, types.NewValidationError("FieldNeqFloat64 must not be equal to 12.34")) +} +`, + }, + { + name: "neq_bool_neq=true", + args: args{ + fieldName: "FieldNeqBool", + fieldType: common.FieldType{ComposedType: "", BaseType: "bool", Size: ""}, + fieldValidation: "neq=true", + }, + want: `if !(obj.FieldNeqBool != true) { +errs = append(errs, types.NewValidationError("FieldNeqBool must not be equal to true")) +} +`, + }, + { + name: "gt_int_gt=32", + args: args{ + fieldName: "FieldGtInt", + fieldType: common.FieldType{ComposedType: "", BaseType: "int", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtInt > 32) { +errs = append(errs, types.NewValidationError("FieldGtInt must be > 32")) +} +`, + }, + { + name: "gt_int8_gt=32", + args: args{ + fieldName: "FieldGtInt8", + fieldType: common.FieldType{ComposedType: "", BaseType: "int8", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtInt8 > 32) { +errs = append(errs, types.NewValidationError("FieldGtInt8 must be > 32")) +} +`, + }, + { + name: "gt_int16_gt=32", + args: args{ + fieldName: "FieldGtInt16", + fieldType: common.FieldType{ComposedType: "", BaseType: "int16", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtInt16 > 32) { +errs = append(errs, types.NewValidationError("FieldGtInt16 must be > 32")) +} +`, + }, + { + name: "gt_int32_gt=32", + args: args{ + fieldName: "FieldGtInt32", + fieldType: common.FieldType{ComposedType: "", BaseType: "int32", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtInt32 > 32) { +errs = append(errs, types.NewValidationError("FieldGtInt32 must be > 32")) +} +`, + }, + { + name: "gt_int64_gt=32", + args: args{ + fieldName: "FieldGtInt64", + fieldType: common.FieldType{ComposedType: "", BaseType: "int64", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtInt64 > 32) { +errs = append(errs, types.NewValidationError("FieldGtInt64 must be > 32")) +} +`, + }, + { + name: "gt_uint_gt=32", + args: args{ + fieldName: "FieldGtUint", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtUint > 32) { +errs = append(errs, types.NewValidationError("FieldGtUint must be > 32")) +} +`, + }, + { + name: "gt_uint8_gt=32", + args: args{ + fieldName: "FieldGtUint8", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint8", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtUint8 > 32) { +errs = append(errs, types.NewValidationError("FieldGtUint8 must be > 32")) +} +`, + }, + { + name: "gt_uint16_gt=32", + args: args{ + fieldName: "FieldGtUint16", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint16", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtUint16 > 32) { +errs = append(errs, types.NewValidationError("FieldGtUint16 must be > 32")) +} +`, + }, + { + name: "gt_uint32_gt=32", + args: args{ + fieldName: "FieldGtUint32", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint32", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtUint32 > 32) { +errs = append(errs, types.NewValidationError("FieldGtUint32 must be > 32")) +} +`, + }, + { + name: "gt_uint64_gt=32", + args: args{ + fieldName: "FieldGtUint64", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint64", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtUint64 > 32) { +errs = append(errs, types.NewValidationError("FieldGtUint64 must be > 32")) +} +`, + }, + { + name: "gt_float32_gt=12.34", + args: args{ + fieldName: "FieldGtFloat32", + fieldType: common.FieldType{ComposedType: "", BaseType: "float32", Size: ""}, + fieldValidation: "gt=12.34", + }, + want: `if !(obj.FieldGtFloat32 > 12.34) { +errs = append(errs, types.NewValidationError("FieldGtFloat32 must be > 12.34")) +} +`, + }, + { + name: "gt_float64_gt=12.34", + args: args{ + fieldName: "FieldGtFloat64", + fieldType: common.FieldType{ComposedType: "", BaseType: "float64", Size: ""}, + fieldValidation: "gt=12.34", + }, + want: `if !(obj.FieldGtFloat64 > 12.34) { +errs = append(errs, types.NewValidationError("FieldGtFloat64 must be > 12.34")) +} +`, + }, + { + name: "gte_int_gte=32", + args: args{ + fieldName: "FieldGteInt", + fieldType: common.FieldType{ComposedType: "", BaseType: "int", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteInt >= 32) { +errs = append(errs, types.NewValidationError("FieldGteInt must be >= 32")) +} +`, + }, + { + name: "gte_int8_gte=32", + args: args{ + fieldName: "FieldGteInt8", + fieldType: common.FieldType{ComposedType: "", BaseType: "int8", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteInt8 >= 32) { +errs = append(errs, types.NewValidationError("FieldGteInt8 must be >= 32")) +} +`, + }, + { + name: "gte_int16_gte=32", + args: args{ + fieldName: "FieldGteInt16", + fieldType: common.FieldType{ComposedType: "", BaseType: "int16", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteInt16 >= 32) { +errs = append(errs, types.NewValidationError("FieldGteInt16 must be >= 32")) +} +`, + }, + { + name: "gte_int32_gte=32", + args: args{ + fieldName: "FieldGteInt32", + fieldType: common.FieldType{ComposedType: "", BaseType: "int32", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteInt32 >= 32) { +errs = append(errs, types.NewValidationError("FieldGteInt32 must be >= 32")) +} +`, + }, + { + name: "gte_int64_gte=32", + args: args{ + fieldName: "FieldGteInt64", + fieldType: common.FieldType{ComposedType: "", BaseType: "int64", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteInt64 >= 32) { +errs = append(errs, types.NewValidationError("FieldGteInt64 must be >= 32")) +} +`, + }, + { + name: "gte_uint_gte=32", + args: args{ + fieldName: "FieldGteUint", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteUint >= 32) { +errs = append(errs, types.NewValidationError("FieldGteUint must be >= 32")) +} +`, + }, + { + name: "gte_uint8_gte=32", + args: args{ + fieldName: "FieldGteUint8", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint8", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteUint8 >= 32) { +errs = append(errs, types.NewValidationError("FieldGteUint8 must be >= 32")) +} +`, + }, + { + name: "gte_uint16_gte=32", + args: args{ + fieldName: "FieldGteUint16", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint16", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteUint16 >= 32) { +errs = append(errs, types.NewValidationError("FieldGteUint16 must be >= 32")) +} +`, + }, + { + name: "gte_uint32_gte=32", + args: args{ + fieldName: "FieldGteUint32", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint32", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteUint32 >= 32) { +errs = append(errs, types.NewValidationError("FieldGteUint32 must be >= 32")) +} +`, + }, + { + name: "gte_uint64_gte=32", + args: args{ + fieldName: "FieldGteUint64", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint64", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteUint64 >= 32) { +errs = append(errs, types.NewValidationError("FieldGteUint64 must be >= 32")) +} +`, + }, + { + name: "gte_float32_gte=12.34", + args: args{ + fieldName: "FieldGteFloat32", + fieldType: common.FieldType{ComposedType: "", BaseType: "float32", Size: ""}, + fieldValidation: "gte=12.34", + }, + want: `if !(obj.FieldGteFloat32 >= 12.34) { +errs = append(errs, types.NewValidationError("FieldGteFloat32 must be >= 12.34")) +} +`, + }, + { + name: "gte_float64_gte=12.34", + args: args{ + fieldName: "FieldGteFloat64", + fieldType: common.FieldType{ComposedType: "", BaseType: "float64", Size: ""}, + fieldValidation: "gte=12.34", + }, + want: `if !(obj.FieldGteFloat64 >= 12.34) { +errs = append(errs, types.NewValidationError("FieldGteFloat64 must be >= 12.34")) +} +`, + }, + { + name: "lt_int_lt=32", + args: args{ + fieldName: "FieldLtInt", + fieldType: common.FieldType{ComposedType: "", BaseType: "int", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtInt < 32) { +errs = append(errs, types.NewValidationError("FieldLtInt must be < 32")) +} +`, + }, + { + name: "lt_int8_lt=32", + args: args{ + fieldName: "FieldLtInt8", + fieldType: common.FieldType{ComposedType: "", BaseType: "int8", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtInt8 < 32) { +errs = append(errs, types.NewValidationError("FieldLtInt8 must be < 32")) +} +`, + }, + { + name: "lt_int16_lt=32", + args: args{ + fieldName: "FieldLtInt16", + fieldType: common.FieldType{ComposedType: "", BaseType: "int16", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtInt16 < 32) { +errs = append(errs, types.NewValidationError("FieldLtInt16 must be < 32")) +} +`, + }, + { + name: "lt_int32_lt=32", + args: args{ + fieldName: "FieldLtInt32", + fieldType: common.FieldType{ComposedType: "", BaseType: "int32", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtInt32 < 32) { +errs = append(errs, types.NewValidationError("FieldLtInt32 must be < 32")) +} +`, + }, + { + name: "lt_int64_lt=32", + args: args{ + fieldName: "FieldLtInt64", + fieldType: common.FieldType{ComposedType: "", BaseType: "int64", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtInt64 < 32) { +errs = append(errs, types.NewValidationError("FieldLtInt64 must be < 32")) +} +`, + }, + { + name: "lt_uint_lt=32", + args: args{ + fieldName: "FieldLtUint", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtUint < 32) { +errs = append(errs, types.NewValidationError("FieldLtUint must be < 32")) +} +`, + }, + { + name: "lt_uint8_lt=32", + args: args{ + fieldName: "FieldLtUint8", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint8", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtUint8 < 32) { +errs = append(errs, types.NewValidationError("FieldLtUint8 must be < 32")) +} +`, + }, + { + name: "lt_uint16_lt=32", + args: args{ + fieldName: "FieldLtUint16", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint16", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtUint16 < 32) { +errs = append(errs, types.NewValidationError("FieldLtUint16 must be < 32")) +} +`, + }, + { + name: "lt_uint32_lt=32", + args: args{ + fieldName: "FieldLtUint32", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint32", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtUint32 < 32) { +errs = append(errs, types.NewValidationError("FieldLtUint32 must be < 32")) +} +`, + }, + { + name: "lt_uint64_lt=32", + args: args{ + fieldName: "FieldLtUint64", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint64", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtUint64 < 32) { +errs = append(errs, types.NewValidationError("FieldLtUint64 must be < 32")) +} +`, + }, + { + name: "lt_float32_lt=12.34", + args: args{ + fieldName: "FieldLtFloat32", + fieldType: common.FieldType{ComposedType: "", BaseType: "float32", Size: ""}, + fieldValidation: "lt=12.34", + }, + want: `if !(obj.FieldLtFloat32 < 12.34) { +errs = append(errs, types.NewValidationError("FieldLtFloat32 must be < 12.34")) +} +`, + }, + { + name: "lt_float64_lt=12.34", + args: args{ + fieldName: "FieldLtFloat64", + fieldType: common.FieldType{ComposedType: "", BaseType: "float64", Size: ""}, + fieldValidation: "lt=12.34", + }, + want: `if !(obj.FieldLtFloat64 < 12.34) { +errs = append(errs, types.NewValidationError("FieldLtFloat64 must be < 12.34")) +} +`, + }, + { + name: "lte_int_lte=32", + args: args{ + fieldName: "FieldLteInt", + fieldType: common.FieldType{ComposedType: "", BaseType: "int", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteInt <= 32) { +errs = append(errs, types.NewValidationError("FieldLteInt must be <= 32")) +} +`, + }, + { + name: "lte_int8_lte=32", + args: args{ + fieldName: "FieldLteInt8", + fieldType: common.FieldType{ComposedType: "", BaseType: "int8", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteInt8 <= 32) { +errs = append(errs, types.NewValidationError("FieldLteInt8 must be <= 32")) +} +`, + }, + { + name: "lte_int16_lte=32", + args: args{ + fieldName: "FieldLteInt16", + fieldType: common.FieldType{ComposedType: "", BaseType: "int16", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteInt16 <= 32) { +errs = append(errs, types.NewValidationError("FieldLteInt16 must be <= 32")) +} +`, + }, + { + name: "lte_int32_lte=32", + args: args{ + fieldName: "FieldLteInt32", + fieldType: common.FieldType{ComposedType: "", BaseType: "int32", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteInt32 <= 32) { +errs = append(errs, types.NewValidationError("FieldLteInt32 must be <= 32")) +} +`, + }, + { + name: "lte_int64_lte=32", + args: args{ + fieldName: "FieldLteInt64", + fieldType: common.FieldType{ComposedType: "", BaseType: "int64", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteInt64 <= 32) { +errs = append(errs, types.NewValidationError("FieldLteInt64 must be <= 32")) +} +`, + }, + { + name: "lte_uint_lte=32", + args: args{ + fieldName: "FieldLteUint", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteUint <= 32) { +errs = append(errs, types.NewValidationError("FieldLteUint must be <= 32")) +} +`, + }, + { + name: "lte_uint8_lte=32", + args: args{ + fieldName: "FieldLteUint8", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint8", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteUint8 <= 32) { +errs = append(errs, types.NewValidationError("FieldLteUint8 must be <= 32")) +} +`, + }, + { + name: "lte_uint16_lte=32", + args: args{ + fieldName: "FieldLteUint16", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint16", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteUint16 <= 32) { +errs = append(errs, types.NewValidationError("FieldLteUint16 must be <= 32")) +} +`, + }, + { + name: "lte_uint32_lte=32", + args: args{ + fieldName: "FieldLteUint32", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint32", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteUint32 <= 32) { +errs = append(errs, types.NewValidationError("FieldLteUint32 must be <= 32")) +} +`, + }, + { + name: "lte_uint64_lte=32", + args: args{ + fieldName: "FieldLteUint64", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint64", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteUint64 <= 32) { +errs = append(errs, types.NewValidationError("FieldLteUint64 must be <= 32")) +} +`, + }, + { + name: "lte_float32_lte=12.34", + args: args{ + fieldName: "FieldLteFloat32", + fieldType: common.FieldType{ComposedType: "", BaseType: "float32", Size: ""}, + fieldValidation: "lte=12.34", + }, + want: `if !(obj.FieldLteFloat32 <= 12.34) { +errs = append(errs, types.NewValidationError("FieldLteFloat32 must be <= 12.34")) +} +`, + }, + { + name: "lte_float64_lte=12.34", + args: args{ + fieldName: "FieldLteFloat64", + fieldType: common.FieldType{ComposedType: "", BaseType: "float64", Size: ""}, + fieldValidation: "lte=12.34", + }, + want: `if !(obj.FieldLteFloat64 <= 12.34) { +errs = append(errs, types.NewValidationError("FieldLteFloat64 must be <= 12.34")) +} +`, + }, + { + name: "min_string_min=5", + args: args{ + fieldName: "FieldMinString", + fieldType: common.FieldType{ComposedType: "", BaseType: "string", Size: ""}, + fieldValidation: "min=5", + }, + want: `if !(len(obj.FieldMinString) >= 5) { +errs = append(errs, types.NewValidationError("FieldMinString length must be >= 5")) +} +`, + }, + { + name: "min_stringslice_min=2", + args: args{ + fieldName: "FieldMinStringSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "string", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinStringSlice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinStringSlice must have at least 2 elements")) +} +`, + }, + { + name: "min_intslice_min=2", + args: args{ + fieldName: "FieldMinIntSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinIntSlice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinIntSlice must have at least 2 elements")) +} +`, + }, + { + name: "min_int8slice_min=2", + args: args{ + fieldName: "FieldMinInt8Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int8", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinInt8Slice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt8Slice must have at least 2 elements")) +} +`, + }, + { + name: "min_int16slice_min=2", + args: args{ + fieldName: "FieldMinInt16Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int16", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinInt16Slice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt16Slice must have at least 2 elements")) +} +`, + }, + { + name: "min_int32slice_min=2", + args: args{ + fieldName: "FieldMinInt32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int32", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinInt32Slice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt32Slice must have at least 2 elements")) +} +`, + }, + { + name: "min_int64slice_min=2", + args: args{ + fieldName: "FieldMinInt64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int64", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinInt64Slice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt64Slice must have at least 2 elements")) +} +`, + }, + { + name: "min_uintslice_min=2", + args: args{ + fieldName: "FieldMinUintSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinUintSlice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUintSlice must have at least 2 elements")) +} +`, + }, + { + name: "min_uint8slice_min=2", + args: args{ + fieldName: "FieldMinUint8Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint8", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinUint8Slice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint8Slice must have at least 2 elements")) +} +`, + }, + { + name: "min_uint16slice_min=2", + args: args{ + fieldName: "FieldMinUint16Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint16", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinUint16Slice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint16Slice must have at least 2 elements")) +} +`, + }, + { + name: "min_uint32slice_min=2", + args: args{ + fieldName: "FieldMinUint32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint32", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinUint32Slice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint32Slice must have at least 2 elements")) +} +`, + }, + { + name: "min_uint64slice_min=2", + args: args{ + fieldName: "FieldMinUint64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint64", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinUint64Slice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint64Slice must have at least 2 elements")) +} +`, + }, + { + name: "min_float32slice_min=2", + args: args{ + fieldName: "FieldMinFloat32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "float32", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinFloat32Slice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinFloat32Slice must have at least 2 elements")) +} +`, + }, + { + name: "min_float64slice_min=2", + args: args{ + fieldName: "FieldMinFloat64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "float64", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinFloat64Slice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinFloat64Slice must have at least 2 elements")) +} +`, + }, + { + name: "min_boolslice_min=2", + args: args{ + fieldName: "FieldMinBoolSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "bool", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinBoolSlice) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinBoolSlice must have at least 2 elements")) +} +`, + }, + { + name: "min_stringmap_min=2", + args: args{ + fieldName: "FieldMinStringMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "string", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinStringMap) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinStringMap must have at least 2 elements")) +} +`, + }, + { + name: "min_intmap_min=2", + args: args{ + fieldName: "FieldMinIntMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinIntMap) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinIntMap must have at least 2 elements")) +} +`, + }, + { + name: "min_int8map_min=2", + args: args{ + fieldName: "FieldMinInt8Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int8", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinInt8Map) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt8Map must have at least 2 elements")) +} +`, + }, + { + name: "min_int16map_min=2", + args: args{ + fieldName: "FieldMinInt16Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int16", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinInt16Map) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt16Map must have at least 2 elements")) +} +`, + }, + { + name: "min_int32map_min=2", + args: args{ + fieldName: "FieldMinInt32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int32", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinInt32Map) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt32Map must have at least 2 elements")) +} +`, + }, + { + name: "min_int64map_min=2", + args: args{ + fieldName: "FieldMinInt64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int64", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinInt64Map) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt64Map must have at least 2 elements")) +} +`, + }, + { + name: "min_uintmap_min=2", + args: args{ + fieldName: "FieldMinUintMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinUintMap) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUintMap must have at least 2 elements")) +} +`, + }, + { + name: "min_uint8map_min=2", + args: args{ + fieldName: "FieldMinUint8Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint8", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinUint8Map) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint8Map must have at least 2 elements")) +} +`, + }, + { + name: "min_uint16map_min=2", + args: args{ + fieldName: "FieldMinUint16Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint16", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinUint16Map) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint16Map must have at least 2 elements")) +} +`, + }, + { + name: "min_uint32map_min=2", + args: args{ + fieldName: "FieldMinUint32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint32", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinUint32Map) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint32Map must have at least 2 elements")) +} +`, + }, + { + name: "min_uint64map_min=2", + args: args{ + fieldName: "FieldMinUint64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint64", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinUint64Map) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint64Map must have at least 2 elements")) +} +`, + }, + { + name: "min_float32map_min=2", + args: args{ + fieldName: "FieldMinFloat32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "float32", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinFloat32Map) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinFloat32Map must have at least 2 elements")) +} +`, + }, + { + name: "min_float64map_min=2", + args: args{ + fieldName: "FieldMinFloat64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "float64", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinFloat64Map) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinFloat64Map must have at least 2 elements")) +} +`, + }, + { + name: "min_boolmap_min=2", + args: args{ + fieldName: "FieldMinBoolMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "bool", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(len(obj.FieldMinBoolMap) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinBoolMap must have at least 2 elements")) +} +`, + }, + { + name: "max_string_max=3", + args: args{ + fieldName: "FieldMaxString", + fieldType: common.FieldType{ComposedType: "", BaseType: "string", Size: ""}, + fieldValidation: "max=3", + }, + want: `if !(len(obj.FieldMaxString) <= 3) { +errs = append(errs, types.NewValidationError("FieldMaxString length must be <= 3")) +} +`, + }, + { + name: "max_stringslice_max=2", + args: args{ + fieldName: "FieldMaxStringSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "string", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxStringSlice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxStringSlice must have at most 2 elements")) +} +`, + }, + { + name: "max_intslice_max=2", + args: args{ + fieldName: "FieldMaxIntSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxIntSlice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxIntSlice must have at most 2 elements")) +} +`, + }, + { + name: "max_int8slice_max=2", + args: args{ + fieldName: "FieldMaxInt8Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int8", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxInt8Slice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt8Slice must have at most 2 elements")) +} +`, + }, + { + name: "max_int16slice_max=2", + args: args{ + fieldName: "FieldMaxInt16Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int16", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxInt16Slice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt16Slice must have at most 2 elements")) +} +`, + }, + { + name: "max_int32slice_max=2", + args: args{ + fieldName: "FieldMaxInt32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int32", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxInt32Slice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt32Slice must have at most 2 elements")) +} +`, + }, + { + name: "max_int64slice_max=2", + args: args{ + fieldName: "FieldMaxInt64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int64", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxInt64Slice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt64Slice must have at most 2 elements")) +} +`, + }, + { + name: "max_uintslice_max=2", + args: args{ + fieldName: "FieldMaxUintSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxUintSlice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUintSlice must have at most 2 elements")) +} +`, + }, + { + name: "max_uint8slice_max=2", + args: args{ + fieldName: "FieldMaxUint8Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint8", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxUint8Slice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint8Slice must have at most 2 elements")) +} +`, + }, + { + name: "max_uint16slice_max=2", + args: args{ + fieldName: "FieldMaxUint16Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint16", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxUint16Slice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint16Slice must have at most 2 elements")) +} +`, + }, + { + name: "max_uint32slice_max=2", + args: args{ + fieldName: "FieldMaxUint32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint32", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxUint32Slice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint32Slice must have at most 2 elements")) +} +`, + }, + { + name: "max_uint64slice_max=2", + args: args{ + fieldName: "FieldMaxUint64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint64", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxUint64Slice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint64Slice must have at most 2 elements")) +} +`, + }, + { + name: "max_float32slice_max=2", + args: args{ + fieldName: "FieldMaxFloat32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "float32", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxFloat32Slice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxFloat32Slice must have at most 2 elements")) +} +`, + }, + { + name: "max_float64slice_max=2", + args: args{ + fieldName: "FieldMaxFloat64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "float64", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxFloat64Slice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxFloat64Slice must have at most 2 elements")) +} +`, + }, + { + name: "max_boolslice_max=2", + args: args{ + fieldName: "FieldMaxBoolSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "bool", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxBoolSlice) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxBoolSlice must have at most 2 elements")) +} +`, + }, + { + name: "max_stringmap_max=2", + args: args{ + fieldName: "FieldMaxStringMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "string", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxStringMap) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxStringMap must have at most 2 elements")) +} +`, + }, + { + name: "max_intmap_max=2", + args: args{ + fieldName: "FieldMaxIntMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxIntMap) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxIntMap must have at most 2 elements")) +} +`, + }, + { + name: "max_int8map_max=2", + args: args{ + fieldName: "FieldMaxInt8Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int8", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxInt8Map) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt8Map must have at most 2 elements")) +} +`, + }, + { + name: "max_int16map_max=2", + args: args{ + fieldName: "FieldMaxInt16Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int16", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxInt16Map) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt16Map must have at most 2 elements")) +} +`, + }, + { + name: "max_int32map_max=2", + args: args{ + fieldName: "FieldMaxInt32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int32", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxInt32Map) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt32Map must have at most 2 elements")) +} +`, + }, + { + name: "max_int64map_max=2", + args: args{ + fieldName: "FieldMaxInt64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int64", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxInt64Map) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt64Map must have at most 2 elements")) +} +`, + }, + { + name: "max_uintmap_max=2", + args: args{ + fieldName: "FieldMaxUintMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxUintMap) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUintMap must have at most 2 elements")) +} +`, + }, + { + name: "max_uint8map_max=2", + args: args{ + fieldName: "FieldMaxUint8Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint8", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxUint8Map) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint8Map must have at most 2 elements")) +} +`, + }, + { + name: "max_uint16map_max=2", + args: args{ + fieldName: "FieldMaxUint16Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint16", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxUint16Map) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint16Map must have at most 2 elements")) +} +`, + }, + { + name: "max_uint32map_max=2", + args: args{ + fieldName: "FieldMaxUint32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint32", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxUint32Map) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint32Map must have at most 2 elements")) +} +`, + }, + { + name: "max_uint64map_max=2", + args: args{ + fieldName: "FieldMaxUint64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint64", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxUint64Map) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint64Map must have at most 2 elements")) +} +`, + }, + { + name: "max_float32map_max=2", + args: args{ + fieldName: "FieldMaxFloat32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "float32", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxFloat32Map) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxFloat32Map must have at most 2 elements")) +} +`, + }, + { + name: "max_float64map_max=2", + args: args{ + fieldName: "FieldMaxFloat64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "float64", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(len(obj.FieldMaxFloat64Map) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxFloat64Map must have at most 2 elements")) +} +`, + }, + { + name: "max_boolmap_max=1", + args: args{ + fieldName: "FieldMaxBoolMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "bool", Size: ""}, + fieldValidation: "max=1", + }, + want: `if !(len(obj.FieldMaxBoolMap) <= 1) { +errs = append(errs, types.NewValidationError("FieldMaxBoolMap must have at most 1 elements")) +} +`, + }, + { + name: "eq_ignore_case_string_eq_ignore_case=abcde", + args: args{ + fieldName: "FieldEq_ignore_caseString", + fieldType: common.FieldType{ComposedType: "", BaseType: "string", Size: ""}, + fieldValidation: "eq_ignore_case=abcde", + }, + want: `if !(types.EqualFold(obj.FieldEq_ignore_caseString, "abcde")) { +errs = append(errs, types.NewValidationError("FieldEq_ignore_caseString must be equal to 'abcde'")) +} +`, + }, + { + name: "neq_ignore_case_string_neq_ignore_case=abcde", + args: args{ + fieldName: "FieldNeq_ignore_caseString", + fieldType: common.FieldType{ComposedType: "", BaseType: "string", Size: ""}, + fieldValidation: "neq_ignore_case=abcde", + }, + want: `if !(!types.EqualFold(obj.FieldNeq_ignore_caseString, "abcde")) { +errs = append(errs, types.NewValidationError("FieldNeq_ignore_caseString must not be equal to 'abcde'")) +} +`, + }, + { + name: "len_string_len=2", + args: args{ + fieldName: "FieldLenString", + fieldType: common.FieldType{ComposedType: "", BaseType: "string", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenString) == 2) { +errs = append(errs, types.NewValidationError("FieldLenString length must be 2")) +} +`, + }, + { + name: "len_stringslice_len=2", + args: args{ + fieldName: "FieldLenStringSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "string", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenStringSlice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenStringSlice must have exactly 2 elements")) +} +`, + }, + { + name: "len_intslice_len=2", + args: args{ + fieldName: "FieldLenIntSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenIntSlice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenIntSlice must have exactly 2 elements")) +} +`, + }, + { + name: "len_int8slice_len=2", + args: args{ + fieldName: "FieldLenInt8Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int8", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenInt8Slice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt8Slice must have exactly 2 elements")) +} +`, + }, + { + name: "len_int16slice_len=2", + args: args{ + fieldName: "FieldLenInt16Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int16", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenInt16Slice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt16Slice must have exactly 2 elements")) +} +`, + }, + { + name: "len_int32slice_len=2", + args: args{ + fieldName: "FieldLenInt32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int32", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenInt32Slice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt32Slice must have exactly 2 elements")) +} +`, + }, + { + name: "len_int64slice_len=2", + args: args{ + fieldName: "FieldLenInt64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int64", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenInt64Slice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt64Slice must have exactly 2 elements")) +} +`, + }, + { + name: "len_uintslice_len=2", + args: args{ + fieldName: "FieldLenUintSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenUintSlice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUintSlice must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint8slice_len=2", + args: args{ + fieldName: "FieldLenUint8Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint8", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenUint8Slice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint8Slice must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint16slice_len=2", + args: args{ + fieldName: "FieldLenUint16Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint16", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenUint16Slice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint16Slice must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint32slice_len=2", + args: args{ + fieldName: "FieldLenUint32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint32", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenUint32Slice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint32Slice must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint64slice_len=2", + args: args{ + fieldName: "FieldLenUint64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint64", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenUint64Slice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint64Slice must have exactly 2 elements")) +} +`, + }, + { + name: "len_float32slice_len=2", + args: args{ + fieldName: "FieldLenFloat32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "float32", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenFloat32Slice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenFloat32Slice must have exactly 2 elements")) +} +`, + }, + { + name: "len_float64slice_len=2", + args: args{ + fieldName: "FieldLenFloat64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "float64", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenFloat64Slice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenFloat64Slice must have exactly 2 elements")) +} +`, + }, + { + name: "len_boolslice_len=2", + args: args{ + fieldName: "FieldLenBoolSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "bool", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenBoolSlice) == 2) { +errs = append(errs, types.NewValidationError("FieldLenBoolSlice must have exactly 2 elements")) +} +`, + }, + { + name: "len_stringmap_len=2", + args: args{ + fieldName: "FieldLenStringMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "string", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenStringMap) == 2) { +errs = append(errs, types.NewValidationError("FieldLenStringMap must have exactly 2 elements")) +} +`, + }, + { + name: "len_intmap_len=2", + args: args{ + fieldName: "FieldLenIntMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenIntMap) == 2) { +errs = append(errs, types.NewValidationError("FieldLenIntMap must have exactly 2 elements")) +} +`, + }, + { + name: "len_int8map_len=2", + args: args{ + fieldName: "FieldLenInt8Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int8", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenInt8Map) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt8Map must have exactly 2 elements")) +} +`, + }, + { + name: "len_int16map_len=2", + args: args{ + fieldName: "FieldLenInt16Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int16", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenInt16Map) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt16Map must have exactly 2 elements")) +} +`, + }, + { + name: "len_int32map_len=2", + args: args{ + fieldName: "FieldLenInt32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int32", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenInt32Map) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt32Map must have exactly 2 elements")) +} +`, + }, + { + name: "len_int64map_len=2", + args: args{ + fieldName: "FieldLenInt64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int64", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenInt64Map) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt64Map must have exactly 2 elements")) +} +`, + }, + { + name: "len_uintmap_len=2", + args: args{ + fieldName: "FieldLenUintMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenUintMap) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUintMap must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint8map_len=2", + args: args{ + fieldName: "FieldLenUint8Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint8", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenUint8Map) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint8Map must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint16map_len=2", + args: args{ + fieldName: "FieldLenUint16Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint16", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenUint16Map) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint16Map must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint32map_len=2", + args: args{ + fieldName: "FieldLenUint32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint32", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenUint32Map) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint32Map must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint64map_len=2", + args: args{ + fieldName: "FieldLenUint64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint64", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenUint64Map) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint64Map must have exactly 2 elements")) +} +`, + }, + { + name: "len_float32map_len=2", + args: args{ + fieldName: "FieldLenFloat32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "float32", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenFloat32Map) == 2) { +errs = append(errs, types.NewValidationError("FieldLenFloat32Map must have exactly 2 elements")) +} +`, + }, + { + name: "len_float64map_len=2", + args: args{ + fieldName: "FieldLenFloat64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "float64", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenFloat64Map) == 2) { +errs = append(errs, types.NewValidationError("FieldLenFloat64Map must have exactly 2 elements")) +} +`, + }, + { + name: "len_boolmap_len=2", + args: args{ + fieldName: "FieldLenBoolMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "bool", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(len(obj.FieldLenBoolMap) == 2) { +errs = append(errs, types.NewValidationError("FieldLenBoolMap must have exactly 2 elements")) +} +`, + }, + { + name: "in_string_in=ab cd ef", + args: args{ + fieldName: "FieldInString", + fieldType: common.FieldType{ComposedType: "", BaseType: "string", Size: ""}, + fieldValidation: "in=ab cd ef", + }, + want: `if !(obj.FieldInString == "ab" || obj.FieldInString == "cd" || obj.FieldInString == "ef") { +errs = append(errs, types.NewValidationError("FieldInString must be one of 'ab' 'cd' 'ef'")) +} +`, + }, + { + name: "in_int_in=12 34 56", + args: args{ + fieldName: "FieldInInt", + fieldType: common.FieldType{ComposedType: "", BaseType: "int", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt == 12 || obj.FieldInInt == 34 || obj.FieldInInt == 56) { +errs = append(errs, types.NewValidationError("FieldInInt must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int8_in=12 34 56", + args: args{ + fieldName: "FieldInInt8", + fieldType: common.FieldType{ComposedType: "", BaseType: "int8", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt8 == 12 || obj.FieldInInt8 == 34 || obj.FieldInInt8 == 56) { +errs = append(errs, types.NewValidationError("FieldInInt8 must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int16_in=12 34 56", + args: args{ + fieldName: "FieldInInt16", + fieldType: common.FieldType{ComposedType: "", BaseType: "int16", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt16 == 12 || obj.FieldInInt16 == 34 || obj.FieldInInt16 == 56) { +errs = append(errs, types.NewValidationError("FieldInInt16 must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int32_in=12 34 56", + args: args{ + fieldName: "FieldInInt32", + fieldType: common.FieldType{ComposedType: "", BaseType: "int32", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt32 == 12 || obj.FieldInInt32 == 34 || obj.FieldInInt32 == 56) { +errs = append(errs, types.NewValidationError("FieldInInt32 must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int64_in=12 34 56", + args: args{ + fieldName: "FieldInInt64", + fieldType: common.FieldType{ComposedType: "", BaseType: "int64", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt64 == 12 || obj.FieldInInt64 == 34 || obj.FieldInInt64 == 56) { +errs = append(errs, types.NewValidationError("FieldInInt64 must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint_in=12 34 56", + args: args{ + fieldName: "FieldInUint", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint == 12 || obj.FieldInUint == 34 || obj.FieldInUint == 56) { +errs = append(errs, types.NewValidationError("FieldInUint must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint8_in=12 34 56", + args: args{ + fieldName: "FieldInUint8", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint8", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint8 == 12 || obj.FieldInUint8 == 34 || obj.FieldInUint8 == 56) { +errs = append(errs, types.NewValidationError("FieldInUint8 must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint16_in=12 34 56", + args: args{ + fieldName: "FieldInUint16", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint16", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint16 == 12 || obj.FieldInUint16 == 34 || obj.FieldInUint16 == 56) { +errs = append(errs, types.NewValidationError("FieldInUint16 must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint32_in=12 34 56", + args: args{ + fieldName: "FieldInUint32", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint32", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint32 == 12 || obj.FieldInUint32 == 34 || obj.FieldInUint32 == 56) { +errs = append(errs, types.NewValidationError("FieldInUint32 must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint64_in=12 34 56", + args: args{ + fieldName: "FieldInUint64", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint64", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint64 == 12 || obj.FieldInUint64 == 34 || obj.FieldInUint64 == 56) { +errs = append(errs, types.NewValidationError("FieldInUint64 must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_float32_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat32", + fieldType: common.FieldType{ComposedType: "", BaseType: "float32", Size: ""}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(obj.FieldInFloat32 == 11.11 || obj.FieldInFloat32 == 22.22 || obj.FieldInFloat32 == 33.33) { +errs = append(errs, types.NewValidationError("FieldInFloat32 must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_float64_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat64", + fieldType: common.FieldType{ComposedType: "", BaseType: "float64", Size: ""}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(obj.FieldInFloat64 == 11.11 || obj.FieldInFloat64 == 22.22 || obj.FieldInFloat64 == 33.33) { +errs = append(errs, types.NewValidationError("FieldInFloat64 must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_bool_in=true", + args: args{ + fieldName: "FieldInBool", + fieldType: common.FieldType{ComposedType: "", BaseType: "bool", Size: ""}, + fieldValidation: "in=true", + }, + want: `if !(obj.FieldInBool == true) { +errs = append(errs, types.NewValidationError("FieldInBool must be one of 'true'")) +} +`, + }, + { + name: "in_stringslice_in=ab cd ef", + args: args{ + fieldName: "FieldInStringSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "string", Size: ""}, + fieldValidation: "in=ab cd ef", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInStringSlice, []string{"ab", "cd", "ef"})) { +errs = append(errs, types.NewValidationError("FieldInStringSlice elements must be one of 'ab' 'cd' 'ef'")) +} +`, + }, + { + name: "in_intslice_in=12 34 56", + args: args{ + fieldName: "FieldInIntSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInIntSlice, []int{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInIntSlice elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int8slice_in=12 34 56", + args: args{ + fieldName: "FieldInInt8Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int8", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInInt8Slice, []int8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt8Slice elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int16slice_in=12 34 56", + args: args{ + fieldName: "FieldInInt16Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int16", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInInt16Slice, []int16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt16Slice elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int32slice_in=12 34 56", + args: args{ + fieldName: "FieldInInt32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int32", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInInt32Slice, []int32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt32Slice elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int64slice_in=12 34 56", + args: args{ + fieldName: "FieldInInt64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int64", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInInt64Slice, []int64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt64Slice elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uintslice_in=12 34 56", + args: args{ + fieldName: "FieldInUintSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInUintSlice, []uint{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUintSlice elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint8slice_in=12 34 56", + args: args{ + fieldName: "FieldInUint8Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint8", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInUint8Slice, []uint8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint8Slice elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint16slice_in=12 34 56", + args: args{ + fieldName: "FieldInUint16Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint16", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInUint16Slice, []uint16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint16Slice elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint32slice_in=12 34 56", + args: args{ + fieldName: "FieldInUint32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint32", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInUint32Slice, []uint32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint32Slice elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint64slice_in=12 34 56", + args: args{ + fieldName: "FieldInUint64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint64", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInUint64Slice, []uint64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint64Slice elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_float32slice_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "float32", Size: ""}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInFloat32Slice, []float32{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldInFloat32Slice elements must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_float64slice_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "float64", Size: ""}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInFloat64Slice, []float64{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldInFloat64Slice elements must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_boolslice_in=true", + args: args{ + fieldName: "FieldInBoolSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "bool", Size: ""}, + fieldValidation: "in=true", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInBoolSlice, []bool{true})) { +errs = append(errs, types.NewValidationError("FieldInBoolSlice elements must be one of 'true'")) +} +`, + }, + { + name: "in_stringarray_in=ab cd ef", + args: args{ + fieldName: "FieldInStringArray", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "string", Size: "3"}, + fieldValidation: "in=ab cd ef", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInStringArray[:], []string{"ab", "cd", "ef"})) { +errs = append(errs, types.NewValidationError("FieldInStringArray elements must be one of 'ab' 'cd' 'ef'")) +} +`, + }, + { + name: "in_intarray_in=12 34 56", + args: args{ + fieldName: "FieldInIntArray", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "int", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInIntArray[:], []int{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInIntArray elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int8array_in=12 34 56", + args: args{ + fieldName: "FieldInInt8Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "int8", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInInt8Array[:], []int8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt8Array elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int16array_in=12 34 56", + args: args{ + fieldName: "FieldInInt16Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "int16", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInInt16Array[:], []int16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt16Array elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int32array_in=12 34 56", + args: args{ + fieldName: "FieldInInt32Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "int32", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInInt32Array[:], []int32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt32Array elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int64array_in=12 34 56", + args: args{ + fieldName: "FieldInInt64Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "int64", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInInt64Array[:], []int64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt64Array elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uintarray_in=12 34 56", + args: args{ + fieldName: "FieldInUintArray", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "uint", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInUintArray[:], []uint{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUintArray elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint8array_in=12 34 56", + args: args{ + fieldName: "FieldInUint8Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "uint8", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInUint8Array[:], []uint8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint8Array elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint16array_in=12 34 56", + args: args{ + fieldName: "FieldInUint16Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "uint16", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInUint16Array[:], []uint16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint16Array elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint32array_in=12 34 56", + args: args{ + fieldName: "FieldInUint32Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "uint32", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInUint32Array[:], []uint32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint32Array elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint64array_in=12 34 56", + args: args{ + fieldName: "FieldInUint64Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "uint64", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInUint64Array[:], []uint64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint64Array elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_float32array_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat32Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "float32", Size: "3"}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInFloat32Array[:], []float32{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldInFloat32Array elements must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_float64array_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat64Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "float64", Size: "3"}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInFloat64Array[:], []float64{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldInFloat64Array elements must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_boolarray_in=true", + args: args{ + fieldName: "FieldInBoolArray", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "bool", Size: "3"}, + fieldValidation: "in=true", + }, + want: `if !(types.SliceOnlyContains(obj.FieldInBoolArray[:], []bool{true})) { +errs = append(errs, types.NewValidationError("FieldInBoolArray elements must be one of 'true'")) +} +`, + }, + { + name: "in_stringmap_in=a b c", + args: args{ + fieldName: "FieldInStringMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "string", Size: ""}, + fieldValidation: "in=a b c", + }, + want: `if !(types.MapOnlyContains(obj.FieldInStringMap, []string{"a", "b", "c"})) { +errs = append(errs, types.NewValidationError("FieldInStringMap elements must be one of 'a' 'b' 'c'")) +} +`, + }, + { + name: "in_intmap_in=1 2 3", + args: args{ + fieldName: "FieldInIntMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(types.MapOnlyContains(obj.FieldInIntMap, []int{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInIntMap elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_int8map_in=1 2 3", + args: args{ + fieldName: "FieldInInt8Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int8", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(types.MapOnlyContains(obj.FieldInInt8Map, []int8{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInInt8Map elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_int16map_in=1 2 3", + args: args{ + fieldName: "FieldInInt16Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int16", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(types.MapOnlyContains(obj.FieldInInt16Map, []int16{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInInt16Map elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_int32map_in=1 2 3", + args: args{ + fieldName: "FieldInInt32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int32", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(types.MapOnlyContains(obj.FieldInInt32Map, []int32{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInInt32Map elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_int64map_in=1 2 3", + args: args{ + fieldName: "FieldInInt64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int64", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(types.MapOnlyContains(obj.FieldInInt64Map, []int64{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInInt64Map elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_uintmap_in=1 2 3", + args: args{ + fieldName: "FieldInUintMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(types.MapOnlyContains(obj.FieldInUintMap, []uint{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInUintMap elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_uint8map_in=1 2 3", + args: args{ + fieldName: "FieldInUint8Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint8", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(types.MapOnlyContains(obj.FieldInUint8Map, []uint8{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInUint8Map elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_uint16map_in=1 2 3", + args: args{ + fieldName: "FieldInUint16Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint16", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(types.MapOnlyContains(obj.FieldInUint16Map, []uint16{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInUint16Map elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_uint32map_in=1 2 3", + args: args{ + fieldName: "FieldInUint32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint32", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(types.MapOnlyContains(obj.FieldInUint32Map, []uint32{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInUint32Map elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_uint64map_in=1 2 3", + args: args{ + fieldName: "FieldInUint64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint64", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(types.MapOnlyContains(obj.FieldInUint64Map, []uint64{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInUint64Map elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_float32map_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "float32", Size: ""}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(types.MapOnlyContains(obj.FieldInFloat32Map, []float32{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldInFloat32Map elements must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_float64map_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "float64", Size: ""}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(types.MapOnlyContains(obj.FieldInFloat64Map, []float64{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldInFloat64Map elements must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_boolmap_in=false", + args: args{ + fieldName: "FieldInBoolMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "bool", Size: ""}, + fieldValidation: "in=false", + }, + want: `if !(types.MapOnlyContains(obj.FieldInBoolMap, []bool{false})) { +errs = append(errs, types.NewValidationError("FieldInBoolMap elements must be one of 'false'")) +} +`, + }, + { + name: "nin_string_nin=ab cd ef", + args: args{ + fieldName: "FieldNinString", + fieldType: common.FieldType{ComposedType: "", BaseType: "string", Size: ""}, + fieldValidation: "nin=ab cd ef", + }, + want: `if !(obj.FieldNinString != "ab" && obj.FieldNinString != "cd" && obj.FieldNinString != "ef") { +errs = append(errs, types.NewValidationError("FieldNinString must not be one of 'ab' 'cd' 'ef'")) +} +`, + }, + { + name: "nin_int_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt", + fieldType: common.FieldType{ComposedType: "", BaseType: "int", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt != 12 && obj.FieldNinInt != 34 && obj.FieldNinInt != 56) { +errs = append(errs, types.NewValidationError("FieldNinInt must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int8_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt8", + fieldType: common.FieldType{ComposedType: "", BaseType: "int8", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt8 != 12 && obj.FieldNinInt8 != 34 && obj.FieldNinInt8 != 56) { +errs = append(errs, types.NewValidationError("FieldNinInt8 must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int16_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt16", + fieldType: common.FieldType{ComposedType: "", BaseType: "int16", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt16 != 12 && obj.FieldNinInt16 != 34 && obj.FieldNinInt16 != 56) { +errs = append(errs, types.NewValidationError("FieldNinInt16 must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int32_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt32", + fieldType: common.FieldType{ComposedType: "", BaseType: "int32", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt32 != 12 && obj.FieldNinInt32 != 34 && obj.FieldNinInt32 != 56) { +errs = append(errs, types.NewValidationError("FieldNinInt32 must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int64_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt64", + fieldType: common.FieldType{ComposedType: "", BaseType: "int64", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt64 != 12 && obj.FieldNinInt64 != 34 && obj.FieldNinInt64 != 56) { +errs = append(errs, types.NewValidationError("FieldNinInt64 must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint != 12 && obj.FieldNinUint != 34 && obj.FieldNinUint != 56) { +errs = append(errs, types.NewValidationError("FieldNinUint must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint8_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint8", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint8", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint8 != 12 && obj.FieldNinUint8 != 34 && obj.FieldNinUint8 != 56) { +errs = append(errs, types.NewValidationError("FieldNinUint8 must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint16_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint16", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint16", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint16 != 12 && obj.FieldNinUint16 != 34 && obj.FieldNinUint16 != 56) { +errs = append(errs, types.NewValidationError("FieldNinUint16 must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint32_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint32", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint32", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint32 != 12 && obj.FieldNinUint32 != 34 && obj.FieldNinUint32 != 56) { +errs = append(errs, types.NewValidationError("FieldNinUint32 must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint64_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint64", + fieldType: common.FieldType{ComposedType: "", BaseType: "uint64", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint64 != 12 && obj.FieldNinUint64 != 34 && obj.FieldNinUint64 != 56) { +errs = append(errs, types.NewValidationError("FieldNinUint64 must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_float32_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat32", + fieldType: common.FieldType{ComposedType: "", BaseType: "float32", Size: ""}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(obj.FieldNinFloat32 != 11.11 && obj.FieldNinFloat32 != 22.22 && obj.FieldNinFloat32 != 33.33) { +errs = append(errs, types.NewValidationError("FieldNinFloat32 must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_float64_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat64", + fieldType: common.FieldType{ComposedType: "", BaseType: "float64", Size: ""}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(obj.FieldNinFloat64 != 11.11 && obj.FieldNinFloat64 != 22.22 && obj.FieldNinFloat64 != 33.33) { +errs = append(errs, types.NewValidationError("FieldNinFloat64 must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_bool_nin=true", + args: args{ + fieldName: "FieldNinBool", + fieldType: common.FieldType{ComposedType: "", BaseType: "bool", Size: ""}, + fieldValidation: "nin=true", + }, + want: `if !(obj.FieldNinBool != true) { +errs = append(errs, types.NewValidationError("FieldNinBool must not be one of 'true'")) +} +`, + }, + { + name: "nin_stringslice_nin=ab cd ef", + args: args{ + fieldName: "FieldNinStringSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "string", Size: ""}, + fieldValidation: "nin=ab cd ef", + }, + want: `if !(types.SliceNotContains(obj.FieldNinStringSlice, []string{"ab", "cd", "ef"})) { +errs = append(errs, types.NewValidationError("FieldNinStringSlice elements must not be one of 'ab' 'cd' 'ef'")) +} +`, + }, + { + name: "nin_intslice_nin=12 34 56", + args: args{ + fieldName: "FieldNinIntSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinIntSlice, []int{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinIntSlice elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int8slice_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt8Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int8", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinInt8Slice, []int8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt8Slice elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int16slice_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt16Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int16", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinInt16Slice, []int16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt16Slice elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int32slice_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int32", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinInt32Slice, []int32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt32Slice elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int64slice_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "int64", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinInt64Slice, []int64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt64Slice elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uintslice_nin=12 34 56", + args: args{ + fieldName: "FieldNinUintSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinUintSlice, []uint{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUintSlice elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint8slice_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint8Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint8", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinUint8Slice, []uint8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint8Slice elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint16slice_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint16Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint16", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinUint16Slice, []uint16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint16Slice elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint32slice_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint32", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinUint32Slice, []uint32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint32Slice elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint64slice_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "uint64", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinUint64Slice, []uint64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint64Slice elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_float32slice_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat32Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "float32", Size: ""}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(types.SliceNotContains(obj.FieldNinFloat32Slice, []float32{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldNinFloat32Slice elements must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_float64slice_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat64Slice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "float64", Size: ""}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(types.SliceNotContains(obj.FieldNinFloat64Slice, []float64{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldNinFloat64Slice elements must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_boolslice_nin=true", + args: args{ + fieldName: "FieldNinBoolSlice", + fieldType: common.FieldType{ComposedType: "[]", BaseType: "bool", Size: ""}, + fieldValidation: "nin=true", + }, + want: `if !(types.SliceNotContains(obj.FieldNinBoolSlice, []bool{true})) { +errs = append(errs, types.NewValidationError("FieldNinBoolSlice elements must not be one of 'true'")) +} +`, + }, + { + name: "nin_stringarray_nin=ab cd ef", + args: args{ + fieldName: "FieldNinStringArray", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "string", Size: "3"}, + fieldValidation: "nin=ab cd ef", + }, + want: `if !(types.SliceNotContains(obj.FieldNinStringArray[:], []string{"ab", "cd", "ef"})) { +errs = append(errs, types.NewValidationError("FieldNinStringArray elements must not be one of 'ab' 'cd' 'ef'")) +} +`, + }, + { + name: "nin_intarray_nin=12 34 56", + args: args{ + fieldName: "FieldNinIntArray", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "int", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinIntArray[:], []int{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinIntArray elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int8array_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt8Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "int8", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinInt8Array[:], []int8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt8Array elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int16array_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt16Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "int16", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinInt16Array[:], []int16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt16Array elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int32array_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt32Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "int32", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinInt32Array[:], []int32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt32Array elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int64array_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt64Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "int64", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinInt64Array[:], []int64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt64Array elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uintarray_nin=12 34 56", + args: args{ + fieldName: "FieldNinUintArray", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "uint", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinUintArray[:], []uint{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUintArray elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint8array_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint8Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "uint8", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinUint8Array[:], []uint8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint8Array elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint16array_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint16Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "uint16", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinUint16Array[:], []uint16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint16Array elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint32array_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint32Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "uint32", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinUint32Array[:], []uint32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint32Array elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint64array_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint64Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "uint64", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(types.SliceNotContains(obj.FieldNinUint64Array[:], []uint64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint64Array elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_float32array_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat32Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "float32", Size: "3"}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(types.SliceNotContains(obj.FieldNinFloat32Array[:], []float32{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldNinFloat32Array elements must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_float64array_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat64Array", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "float64", Size: "3"}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(types.SliceNotContains(obj.FieldNinFloat64Array[:], []float64{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldNinFloat64Array elements must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_boolarray_nin=true", + args: args{ + fieldName: "FieldNinBoolArray", + fieldType: common.FieldType{ComposedType: "[N]", BaseType: "bool", Size: "3"}, + fieldValidation: "nin=true", + }, + want: `if !(types.SliceNotContains(obj.FieldNinBoolArray[:], []bool{true})) { +errs = append(errs, types.NewValidationError("FieldNinBoolArray elements must not be one of 'true'")) +} +`, + }, + { + name: "nin_stringmap_nin=a b c", + args: args{ + fieldName: "FieldNinStringMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "string", Size: ""}, + fieldValidation: "nin=a b c", + }, + want: `if !(types.MapNotContains(obj.FieldNinStringMap, []string{"a", "b", "c"})) { +errs = append(errs, types.NewValidationError("FieldNinStringMap elements must not be one of 'a' 'b' 'c'")) +} +`, + }, + { + name: "nin_intmap_nin=1 2 3", + args: args{ + fieldName: "FieldNinIntMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(types.MapNotContains(obj.FieldNinIntMap, []int{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinIntMap elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_int8map_nin=1 2 3", + args: args{ + fieldName: "FieldNinInt8Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int8", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(types.MapNotContains(obj.FieldNinInt8Map, []int8{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinInt8Map elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_int16map_nin=1 2 3", + args: args{ + fieldName: "FieldNinInt16Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int16", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(types.MapNotContains(obj.FieldNinInt16Map, []int16{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinInt16Map elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_int32map_nin=1 2 3", + args: args{ + fieldName: "FieldNinInt32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int32", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(types.MapNotContains(obj.FieldNinInt32Map, []int32{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinInt32Map elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_int64map_nin=1 2 3", + args: args{ + fieldName: "FieldNinInt64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "int64", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(types.MapNotContains(obj.FieldNinInt64Map, []int64{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinInt64Map elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_uintmap_nin=1 2 3", + args: args{ + fieldName: "FieldNinUintMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(types.MapNotContains(obj.FieldNinUintMap, []uint{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinUintMap elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_uint8map_nin=1 2 3", + args: args{ + fieldName: "FieldNinUint8Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint8", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(types.MapNotContains(obj.FieldNinUint8Map, []uint8{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinUint8Map elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_uint16map_nin=1 2 3", + args: args{ + fieldName: "FieldNinUint16Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint16", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(types.MapNotContains(obj.FieldNinUint16Map, []uint16{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinUint16Map elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_uint32map_nin=1 2 3", + args: args{ + fieldName: "FieldNinUint32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint32", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(types.MapNotContains(obj.FieldNinUint32Map, []uint32{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinUint32Map elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_uint64map_nin=1 2 3", + args: args{ + fieldName: "FieldNinUint64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "uint64", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(types.MapNotContains(obj.FieldNinUint64Map, []uint64{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinUint64Map elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_float32map_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat32Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "float32", Size: ""}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(types.MapNotContains(obj.FieldNinFloat32Map, []float32{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldNinFloat32Map elements must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_float64map_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat64Map", + fieldType: common.FieldType{ComposedType: "map", BaseType: "float64", Size: ""}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(types.MapNotContains(obj.FieldNinFloat64Map, []float64{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldNinFloat64Map elements must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_boolmap_nin=false", + args: args{ + fieldName: "FieldNinBoolMap", + fieldType: common.FieldType{ComposedType: "map", BaseType: "bool", Size: ""}, + fieldValidation: "nin=false", + }, + want: `if !(types.MapNotContains(obj.FieldNinBoolMap, []bool{false})) { +errs = append(errs, types.NewValidationError("FieldNinBoolMap elements must not be one of 'false'")) +} +`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gv := GenValidations{} + validation := AssertParserValidation(t, tt.args.fieldValidation) + got, err := gv.BuildValidationCode(tt.args.fieldName, tt.args.fieldType, []*analyzer.Validation{validation}) + if err != nil { + t.Errorf("BuildValidationCode() error = %v, wantErr %v", err, nil) + return + } + if got != tt.want { + t.Errorf("BuildValidationCode() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/codegenerator/generated_validation_code_pointer_test.go b/internal/codegenerator/generated_validation_code_pointer_test.go new file mode 100644 index 0000000..2ac92e6 --- /dev/null +++ b/internal/codegenerator/generated_validation_code_pointer_test.go @@ -0,0 +1,4045 @@ +package codegenerator + +import ( + "testing" + + "github.com/opencodeco/validgen/internal/analyzer" + "github.com/opencodeco/validgen/internal/common" +) + +func TestBuildValidationCodePointer(t *testing.T) { + type args struct { + fieldName string + fieldType common.FieldType + fieldValidation string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "email_stringpointer_email", + args: args{ + fieldName: "FieldEmailStringPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "string", Size: ""}, + fieldValidation: "email", + }, + want: `if !(obj.FieldEmailStringPointer != nil && types.IsValidEmail(*obj.FieldEmailStringPointer)) { +errs = append(errs, types.NewValidationError("FieldEmailStringPointer must be a valid email")) +} +`, + }, + { + name: "required_stringpointer_required", + args: args{ + fieldName: "FieldRequiredStringPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "string", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredStringPointer != nil && *obj.FieldRequiredStringPointer != "") { +errs = append(errs, types.NewValidationError("FieldRequiredStringPointer is required")) +} +`, + }, + { + name: "required_intpointer_required", + args: args{ + fieldName: "FieldRequiredIntPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredIntPointer != nil && *obj.FieldRequiredIntPointer != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredIntPointer is required")) +} +`, + }, + { + name: "required_int8pointer_required", + args: args{ + fieldName: "FieldRequiredInt8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int8", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt8Pointer != nil && *obj.FieldRequiredInt8Pointer != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt8Pointer is required")) +} +`, + }, + { + name: "required_int16pointer_required", + args: args{ + fieldName: "FieldRequiredInt16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int16", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt16Pointer != nil && *obj.FieldRequiredInt16Pointer != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt16Pointer is required")) +} +`, + }, + { + name: "required_int32pointer_required", + args: args{ + fieldName: "FieldRequiredInt32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt32Pointer != nil && *obj.FieldRequiredInt32Pointer != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt32Pointer is required")) +} +`, + }, + { + name: "required_int64pointer_required", + args: args{ + fieldName: "FieldRequiredInt64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt64Pointer != nil && *obj.FieldRequiredInt64Pointer != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt64Pointer is required")) +} +`, + }, + { + name: "required_uintpointer_required", + args: args{ + fieldName: "FieldRequiredUintPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUintPointer != nil && *obj.FieldRequiredUintPointer != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUintPointer is required")) +} +`, + }, + { + name: "required_uint8pointer_required", + args: args{ + fieldName: "FieldRequiredUint8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint8", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint8Pointer != nil && *obj.FieldRequiredUint8Pointer != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint8Pointer is required")) +} +`, + }, + { + name: "required_uint16pointer_required", + args: args{ + fieldName: "FieldRequiredUint16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint16", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint16Pointer != nil && *obj.FieldRequiredUint16Pointer != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint16Pointer is required")) +} +`, + }, + { + name: "required_uint32pointer_required", + args: args{ + fieldName: "FieldRequiredUint32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint32Pointer != nil && *obj.FieldRequiredUint32Pointer != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint32Pointer is required")) +} +`, + }, + { + name: "required_uint64pointer_required", + args: args{ + fieldName: "FieldRequiredUint64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint64Pointer != nil && *obj.FieldRequiredUint64Pointer != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint64Pointer is required")) +} +`, + }, + { + name: "required_float32pointer_required", + args: args{ + fieldName: "FieldRequiredFloat32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredFloat32Pointer != nil && *obj.FieldRequiredFloat32Pointer != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat32Pointer is required")) +} +`, + }, + { + name: "required_float64pointer_required", + args: args{ + fieldName: "FieldRequiredFloat64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredFloat64Pointer != nil && *obj.FieldRequiredFloat64Pointer != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat64Pointer is required")) +} +`, + }, + { + name: "required_boolpointer_required", + args: args{ + fieldName: "FieldRequiredBoolPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "bool", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredBoolPointer != nil && *obj.FieldRequiredBoolPointer != false) { +errs = append(errs, types.NewValidationError("FieldRequiredBoolPointer is required")) +} +`, + }, + { + name: "required_stringslicepointer_required", + args: args{ + fieldName: "FieldRequiredStringSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "string", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredStringSlicePointer != nil && len(*obj.FieldRequiredStringSlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredStringSlicePointer must not be empty")) +} +`, + }, + { + name: "required_intslicepointer_required", + args: args{ + fieldName: "FieldRequiredIntSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredIntSlicePointer != nil && len(*obj.FieldRequiredIntSlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredIntSlicePointer must not be empty")) +} +`, + }, + { + name: "required_int8slicepointer_required", + args: args{ + fieldName: "FieldRequiredInt8SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int8", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt8SlicePointer != nil && len(*obj.FieldRequiredInt8SlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt8SlicePointer must not be empty")) +} +`, + }, + { + name: "required_int16slicepointer_required", + args: args{ + fieldName: "FieldRequiredInt16SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int16", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt16SlicePointer != nil && len(*obj.FieldRequiredInt16SlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt16SlicePointer must not be empty")) +} +`, + }, + { + name: "required_int32slicepointer_required", + args: args{ + fieldName: "FieldRequiredInt32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt32SlicePointer != nil && len(*obj.FieldRequiredInt32SlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt32SlicePointer must not be empty")) +} +`, + }, + { + name: "required_int64slicepointer_required", + args: args{ + fieldName: "FieldRequiredInt64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt64SlicePointer != nil && len(*obj.FieldRequiredInt64SlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt64SlicePointer must not be empty")) +} +`, + }, + { + name: "required_uintslicepointer_required", + args: args{ + fieldName: "FieldRequiredUintSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUintSlicePointer != nil && len(*obj.FieldRequiredUintSlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUintSlicePointer must not be empty")) +} +`, + }, + { + name: "required_uint8slicepointer_required", + args: args{ + fieldName: "FieldRequiredUint8SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint8", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint8SlicePointer != nil && len(*obj.FieldRequiredUint8SlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint8SlicePointer must not be empty")) +} +`, + }, + { + name: "required_uint16slicepointer_required", + args: args{ + fieldName: "FieldRequiredUint16SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint16", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint16SlicePointer != nil && len(*obj.FieldRequiredUint16SlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint16SlicePointer must not be empty")) +} +`, + }, + { + name: "required_uint32slicepointer_required", + args: args{ + fieldName: "FieldRequiredUint32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint32SlicePointer != nil && len(*obj.FieldRequiredUint32SlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint32SlicePointer must not be empty")) +} +`, + }, + { + name: "required_uint64slicepointer_required", + args: args{ + fieldName: "FieldRequiredUint64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint64SlicePointer != nil && len(*obj.FieldRequiredUint64SlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint64SlicePointer must not be empty")) +} +`, + }, + { + name: "required_float32slicepointer_required", + args: args{ + fieldName: "FieldRequiredFloat32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "float32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredFloat32SlicePointer != nil && len(*obj.FieldRequiredFloat32SlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat32SlicePointer must not be empty")) +} +`, + }, + { + name: "required_float64slicepointer_required", + args: args{ + fieldName: "FieldRequiredFloat64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "float64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredFloat64SlicePointer != nil && len(*obj.FieldRequiredFloat64SlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat64SlicePointer must not be empty")) +} +`, + }, + { + name: "required_boolslicepointer_required", + args: args{ + fieldName: "FieldRequiredBoolSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "bool", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredBoolSlicePointer != nil && len(*obj.FieldRequiredBoolSlicePointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredBoolSlicePointer must not be empty")) +} +`, + }, + { + name: "required_stringarraypointer_required", + args: args{ + fieldName: "FieldRequiredStringArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "string", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredStringArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredStringArrayPointer must not be empty")) +} +`, + }, + { + name: "required_intarraypointer_required", + args: args{ + fieldName: "FieldRequiredIntArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredIntArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredIntArrayPointer must not be empty")) +} +`, + }, + { + name: "required_int8arraypointer_required", + args: args{ + fieldName: "FieldRequiredInt8ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int8", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt8ArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredInt8ArrayPointer must not be empty")) +} +`, + }, + { + name: "required_int16arraypointer_required", + args: args{ + fieldName: "FieldRequiredInt16ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int16", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt16ArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredInt16ArrayPointer must not be empty")) +} +`, + }, + { + name: "required_int32arraypointer_required", + args: args{ + fieldName: "FieldRequiredInt32ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int32", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt32ArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredInt32ArrayPointer must not be empty")) +} +`, + }, + { + name: "required_int64arraypointer_required", + args: args{ + fieldName: "FieldRequiredInt64ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int64", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt64ArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredInt64ArrayPointer must not be empty")) +} +`, + }, + { + name: "required_uintarraypointer_required", + args: args{ + fieldName: "FieldRequiredUintArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUintArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredUintArrayPointer must not be empty")) +} +`, + }, + { + name: "required_uint8arraypointer_required", + args: args{ + fieldName: "FieldRequiredUint8ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint8", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint8ArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredUint8ArrayPointer must not be empty")) +} +`, + }, + { + name: "required_uint16arraypointer_required", + args: args{ + fieldName: "FieldRequiredUint16ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint16", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint16ArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredUint16ArrayPointer must not be empty")) +} +`, + }, + { + name: "required_uint32arraypointer_required", + args: args{ + fieldName: "FieldRequiredUint32ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint32", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint32ArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredUint32ArrayPointer must not be empty")) +} +`, + }, + { + name: "required_uint64arraypointer_required", + args: args{ + fieldName: "FieldRequiredUint64ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint64", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint64ArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredUint64ArrayPointer must not be empty")) +} +`, + }, + { + name: "required_float32arraypointer_required", + args: args{ + fieldName: "FieldRequiredFloat32ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "float32", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredFloat32ArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat32ArrayPointer must not be empty")) +} +`, + }, + { + name: "required_float64arraypointer_required", + args: args{ + fieldName: "FieldRequiredFloat64ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "float64", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredFloat64ArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat64ArrayPointer must not be empty")) +} +`, + }, + { + name: "required_boolarraypointer_required", + args: args{ + fieldName: "FieldRequiredBoolArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "bool", Size: "3"}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredBoolArrayPointer != nil) { +errs = append(errs, types.NewValidationError("FieldRequiredBoolArrayPointer must not be empty")) +} +`, + }, + { + name: "required_stringmappointer_required", + args: args{ + fieldName: "FieldRequiredStringMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "string", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredStringMapPointer != nil && len(*obj.FieldRequiredStringMapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredStringMapPointer must not be empty")) +} +`, + }, + { + name: "required_intmappointer_required", + args: args{ + fieldName: "FieldRequiredIntMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredIntMapPointer != nil && len(*obj.FieldRequiredIntMapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredIntMapPointer must not be empty")) +} +`, + }, + { + name: "required_int8mappointer_required", + args: args{ + fieldName: "FieldRequiredInt8MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int8", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt8MapPointer != nil && len(*obj.FieldRequiredInt8MapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt8MapPointer must not be empty")) +} +`, + }, + { + name: "required_int16mappointer_required", + args: args{ + fieldName: "FieldRequiredInt16MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int16", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt16MapPointer != nil && len(*obj.FieldRequiredInt16MapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt16MapPointer must not be empty")) +} +`, + }, + { + name: "required_int32mappointer_required", + args: args{ + fieldName: "FieldRequiredInt32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt32MapPointer != nil && len(*obj.FieldRequiredInt32MapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt32MapPointer must not be empty")) +} +`, + }, + { + name: "required_int64mappointer_required", + args: args{ + fieldName: "FieldRequiredInt64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredInt64MapPointer != nil && len(*obj.FieldRequiredInt64MapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredInt64MapPointer must not be empty")) +} +`, + }, + { + name: "required_uintmappointer_required", + args: args{ + fieldName: "FieldRequiredUintMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUintMapPointer != nil && len(*obj.FieldRequiredUintMapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUintMapPointer must not be empty")) +} +`, + }, + { + name: "required_uint8mappointer_required", + args: args{ + fieldName: "FieldRequiredUint8MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint8", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint8MapPointer != nil && len(*obj.FieldRequiredUint8MapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint8MapPointer must not be empty")) +} +`, + }, + { + name: "required_uint16mappointer_required", + args: args{ + fieldName: "FieldRequiredUint16MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint16", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint16MapPointer != nil && len(*obj.FieldRequiredUint16MapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint16MapPointer must not be empty")) +} +`, + }, + { + name: "required_uint32mappointer_required", + args: args{ + fieldName: "FieldRequiredUint32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint32MapPointer != nil && len(*obj.FieldRequiredUint32MapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint32MapPointer must not be empty")) +} +`, + }, + { + name: "required_uint64mappointer_required", + args: args{ + fieldName: "FieldRequiredUint64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredUint64MapPointer != nil && len(*obj.FieldRequiredUint64MapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredUint64MapPointer must not be empty")) +} +`, + }, + { + name: "required_float32mappointer_required", + args: args{ + fieldName: "FieldRequiredFloat32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "float32", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredFloat32MapPointer != nil && len(*obj.FieldRequiredFloat32MapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat32MapPointer must not be empty")) +} +`, + }, + { + name: "required_float64mappointer_required", + args: args{ + fieldName: "FieldRequiredFloat64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "float64", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredFloat64MapPointer != nil && len(*obj.FieldRequiredFloat64MapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredFloat64MapPointer must not be empty")) +} +`, + }, + { + name: "required_boolmappointer_required", + args: args{ + fieldName: "FieldRequiredBoolMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "bool", Size: ""}, + fieldValidation: "required", + }, + want: `if !(obj.FieldRequiredBoolMapPointer != nil && len(*obj.FieldRequiredBoolMapPointer) != 0) { +errs = append(errs, types.NewValidationError("FieldRequiredBoolMapPointer must not be empty")) +} +`, + }, + { + name: "eq_stringpointer_eq=abcde", + args: args{ + fieldName: "FieldEqStringPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "string", Size: ""}, + fieldValidation: "eq=abcde", + }, + want: `if !(obj.FieldEqStringPointer != nil && *obj.FieldEqStringPointer == "abcde") { +errs = append(errs, types.NewValidationError("FieldEqStringPointer must be equal to 'abcde'")) +} +`, + }, + { + name: "eq_intpointer_eq=32", + args: args{ + fieldName: "FieldEqIntPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqIntPointer != nil && *obj.FieldEqIntPointer == 32) { +errs = append(errs, types.NewValidationError("FieldEqIntPointer must be equal to 32")) +} +`, + }, + { + name: "eq_int8pointer_eq=32", + args: args{ + fieldName: "FieldEqInt8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int8", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqInt8Pointer != nil && *obj.FieldEqInt8Pointer == 32) { +errs = append(errs, types.NewValidationError("FieldEqInt8Pointer must be equal to 32")) +} +`, + }, + { + name: "eq_int16pointer_eq=32", + args: args{ + fieldName: "FieldEqInt16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int16", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqInt16Pointer != nil && *obj.FieldEqInt16Pointer == 32) { +errs = append(errs, types.NewValidationError("FieldEqInt16Pointer must be equal to 32")) +} +`, + }, + { + name: "eq_int32pointer_eq=32", + args: args{ + fieldName: "FieldEqInt32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int32", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqInt32Pointer != nil && *obj.FieldEqInt32Pointer == 32) { +errs = append(errs, types.NewValidationError("FieldEqInt32Pointer must be equal to 32")) +} +`, + }, + { + name: "eq_int64pointer_eq=32", + args: args{ + fieldName: "FieldEqInt64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int64", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqInt64Pointer != nil && *obj.FieldEqInt64Pointer == 32) { +errs = append(errs, types.NewValidationError("FieldEqInt64Pointer must be equal to 32")) +} +`, + }, + { + name: "eq_uintpointer_eq=32", + args: args{ + fieldName: "FieldEqUintPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqUintPointer != nil && *obj.FieldEqUintPointer == 32) { +errs = append(errs, types.NewValidationError("FieldEqUintPointer must be equal to 32")) +} +`, + }, + { + name: "eq_uint8pointer_eq=32", + args: args{ + fieldName: "FieldEqUint8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint8", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqUint8Pointer != nil && *obj.FieldEqUint8Pointer == 32) { +errs = append(errs, types.NewValidationError("FieldEqUint8Pointer must be equal to 32")) +} +`, + }, + { + name: "eq_uint16pointer_eq=32", + args: args{ + fieldName: "FieldEqUint16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint16", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqUint16Pointer != nil && *obj.FieldEqUint16Pointer == 32) { +errs = append(errs, types.NewValidationError("FieldEqUint16Pointer must be equal to 32")) +} +`, + }, + { + name: "eq_uint32pointer_eq=32", + args: args{ + fieldName: "FieldEqUint32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint32", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqUint32Pointer != nil && *obj.FieldEqUint32Pointer == 32) { +errs = append(errs, types.NewValidationError("FieldEqUint32Pointer must be equal to 32")) +} +`, + }, + { + name: "eq_uint64pointer_eq=32", + args: args{ + fieldName: "FieldEqUint64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint64", Size: ""}, + fieldValidation: "eq=32", + }, + want: `if !(obj.FieldEqUint64Pointer != nil && *obj.FieldEqUint64Pointer == 32) { +errs = append(errs, types.NewValidationError("FieldEqUint64Pointer must be equal to 32")) +} +`, + }, + { + name: "eq_float32pointer_eq=12.34", + args: args{ + fieldName: "FieldEqFloat32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float32", Size: ""}, + fieldValidation: "eq=12.34", + }, + want: `if !(obj.FieldEqFloat32Pointer != nil && *obj.FieldEqFloat32Pointer == 12.34) { +errs = append(errs, types.NewValidationError("FieldEqFloat32Pointer must be equal to 12.34")) +} +`, + }, + { + name: "eq_float64pointer_eq=12.34", + args: args{ + fieldName: "FieldEqFloat64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float64", Size: ""}, + fieldValidation: "eq=12.34", + }, + want: `if !(obj.FieldEqFloat64Pointer != nil && *obj.FieldEqFloat64Pointer == 12.34) { +errs = append(errs, types.NewValidationError("FieldEqFloat64Pointer must be equal to 12.34")) +} +`, + }, + { + name: "eq_boolpointer_eq=true", + args: args{ + fieldName: "FieldEqBoolPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "bool", Size: ""}, + fieldValidation: "eq=true", + }, + want: `if !(obj.FieldEqBoolPointer != nil && *obj.FieldEqBoolPointer == true) { +errs = append(errs, types.NewValidationError("FieldEqBoolPointer must be equal to true")) +} +`, + }, + { + name: "neq_stringpointer_neq=abcde", + args: args{ + fieldName: "FieldNeqStringPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "string", Size: ""}, + fieldValidation: "neq=abcde", + }, + want: `if !(obj.FieldNeqStringPointer != nil && *obj.FieldNeqStringPointer != "abcde") { +errs = append(errs, types.NewValidationError("FieldNeqStringPointer must not be equal to 'abcde'")) +} +`, + }, + { + name: "neq_intpointer_neq=32", + args: args{ + fieldName: "FieldNeqIntPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqIntPointer != nil && *obj.FieldNeqIntPointer != 32) { +errs = append(errs, types.NewValidationError("FieldNeqIntPointer must not be equal to 32")) +} +`, + }, + { + name: "neq_int8pointer_neq=32", + args: args{ + fieldName: "FieldNeqInt8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int8", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqInt8Pointer != nil && *obj.FieldNeqInt8Pointer != 32) { +errs = append(errs, types.NewValidationError("FieldNeqInt8Pointer must not be equal to 32")) +} +`, + }, + { + name: "neq_int16pointer_neq=32", + args: args{ + fieldName: "FieldNeqInt16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int16", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqInt16Pointer != nil && *obj.FieldNeqInt16Pointer != 32) { +errs = append(errs, types.NewValidationError("FieldNeqInt16Pointer must not be equal to 32")) +} +`, + }, + { + name: "neq_int32pointer_neq=32", + args: args{ + fieldName: "FieldNeqInt32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int32", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqInt32Pointer != nil && *obj.FieldNeqInt32Pointer != 32) { +errs = append(errs, types.NewValidationError("FieldNeqInt32Pointer must not be equal to 32")) +} +`, + }, + { + name: "neq_int64pointer_neq=32", + args: args{ + fieldName: "FieldNeqInt64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int64", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqInt64Pointer != nil && *obj.FieldNeqInt64Pointer != 32) { +errs = append(errs, types.NewValidationError("FieldNeqInt64Pointer must not be equal to 32")) +} +`, + }, + { + name: "neq_uintpointer_neq=32", + args: args{ + fieldName: "FieldNeqUintPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqUintPointer != nil && *obj.FieldNeqUintPointer != 32) { +errs = append(errs, types.NewValidationError("FieldNeqUintPointer must not be equal to 32")) +} +`, + }, + { + name: "neq_uint8pointer_neq=32", + args: args{ + fieldName: "FieldNeqUint8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint8", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqUint8Pointer != nil && *obj.FieldNeqUint8Pointer != 32) { +errs = append(errs, types.NewValidationError("FieldNeqUint8Pointer must not be equal to 32")) +} +`, + }, + { + name: "neq_uint16pointer_neq=32", + args: args{ + fieldName: "FieldNeqUint16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint16", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqUint16Pointer != nil && *obj.FieldNeqUint16Pointer != 32) { +errs = append(errs, types.NewValidationError("FieldNeqUint16Pointer must not be equal to 32")) +} +`, + }, + { + name: "neq_uint32pointer_neq=32", + args: args{ + fieldName: "FieldNeqUint32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint32", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqUint32Pointer != nil && *obj.FieldNeqUint32Pointer != 32) { +errs = append(errs, types.NewValidationError("FieldNeqUint32Pointer must not be equal to 32")) +} +`, + }, + { + name: "neq_uint64pointer_neq=32", + args: args{ + fieldName: "FieldNeqUint64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint64", Size: ""}, + fieldValidation: "neq=32", + }, + want: `if !(obj.FieldNeqUint64Pointer != nil && *obj.FieldNeqUint64Pointer != 32) { +errs = append(errs, types.NewValidationError("FieldNeqUint64Pointer must not be equal to 32")) +} +`, + }, + { + name: "neq_float32pointer_neq=12.34", + args: args{ + fieldName: "FieldNeqFloat32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float32", Size: ""}, + fieldValidation: "neq=12.34", + }, + want: `if !(obj.FieldNeqFloat32Pointer != nil && *obj.FieldNeqFloat32Pointer != 12.34) { +errs = append(errs, types.NewValidationError("FieldNeqFloat32Pointer must not be equal to 12.34")) +} +`, + }, + { + name: "neq_float64pointer_neq=12.34", + args: args{ + fieldName: "FieldNeqFloat64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float64", Size: ""}, + fieldValidation: "neq=12.34", + }, + want: `if !(obj.FieldNeqFloat64Pointer != nil && *obj.FieldNeqFloat64Pointer != 12.34) { +errs = append(errs, types.NewValidationError("FieldNeqFloat64Pointer must not be equal to 12.34")) +} +`, + }, + { + name: "neq_boolpointer_neq=true", + args: args{ + fieldName: "FieldNeqBoolPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "bool", Size: ""}, + fieldValidation: "neq=true", + }, + want: `if !(obj.FieldNeqBoolPointer != nil && *obj.FieldNeqBoolPointer != true) { +errs = append(errs, types.NewValidationError("FieldNeqBoolPointer must not be equal to true")) +} +`, + }, + { + name: "gt_intpointer_gt=32", + args: args{ + fieldName: "FieldGtIntPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtIntPointer != nil && *obj.FieldGtIntPointer > 32) { +errs = append(errs, types.NewValidationError("FieldGtIntPointer must be > 32")) +} +`, + }, + { + name: "gt_int8pointer_gt=32", + args: args{ + fieldName: "FieldGtInt8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int8", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtInt8Pointer != nil && *obj.FieldGtInt8Pointer > 32) { +errs = append(errs, types.NewValidationError("FieldGtInt8Pointer must be > 32")) +} +`, + }, + { + name: "gt_int16pointer_gt=32", + args: args{ + fieldName: "FieldGtInt16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int16", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtInt16Pointer != nil && *obj.FieldGtInt16Pointer > 32) { +errs = append(errs, types.NewValidationError("FieldGtInt16Pointer must be > 32")) +} +`, + }, + { + name: "gt_int32pointer_gt=32", + args: args{ + fieldName: "FieldGtInt32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int32", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtInt32Pointer != nil && *obj.FieldGtInt32Pointer > 32) { +errs = append(errs, types.NewValidationError("FieldGtInt32Pointer must be > 32")) +} +`, + }, + { + name: "gt_int64pointer_gt=32", + args: args{ + fieldName: "FieldGtInt64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int64", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtInt64Pointer != nil && *obj.FieldGtInt64Pointer > 32) { +errs = append(errs, types.NewValidationError("FieldGtInt64Pointer must be > 32")) +} +`, + }, + { + name: "gt_uintpointer_gt=32", + args: args{ + fieldName: "FieldGtUintPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtUintPointer != nil && *obj.FieldGtUintPointer > 32) { +errs = append(errs, types.NewValidationError("FieldGtUintPointer must be > 32")) +} +`, + }, + { + name: "gt_uint8pointer_gt=32", + args: args{ + fieldName: "FieldGtUint8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint8", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtUint8Pointer != nil && *obj.FieldGtUint8Pointer > 32) { +errs = append(errs, types.NewValidationError("FieldGtUint8Pointer must be > 32")) +} +`, + }, + { + name: "gt_uint16pointer_gt=32", + args: args{ + fieldName: "FieldGtUint16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint16", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtUint16Pointer != nil && *obj.FieldGtUint16Pointer > 32) { +errs = append(errs, types.NewValidationError("FieldGtUint16Pointer must be > 32")) +} +`, + }, + { + name: "gt_uint32pointer_gt=32", + args: args{ + fieldName: "FieldGtUint32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint32", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtUint32Pointer != nil && *obj.FieldGtUint32Pointer > 32) { +errs = append(errs, types.NewValidationError("FieldGtUint32Pointer must be > 32")) +} +`, + }, + { + name: "gt_uint64pointer_gt=32", + args: args{ + fieldName: "FieldGtUint64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint64", Size: ""}, + fieldValidation: "gt=32", + }, + want: `if !(obj.FieldGtUint64Pointer != nil && *obj.FieldGtUint64Pointer > 32) { +errs = append(errs, types.NewValidationError("FieldGtUint64Pointer must be > 32")) +} +`, + }, + { + name: "gt_float32pointer_gt=12.34", + args: args{ + fieldName: "FieldGtFloat32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float32", Size: ""}, + fieldValidation: "gt=12.34", + }, + want: `if !(obj.FieldGtFloat32Pointer != nil && *obj.FieldGtFloat32Pointer > 12.34) { +errs = append(errs, types.NewValidationError("FieldGtFloat32Pointer must be > 12.34")) +} +`, + }, + { + name: "gt_float64pointer_gt=12.34", + args: args{ + fieldName: "FieldGtFloat64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float64", Size: ""}, + fieldValidation: "gt=12.34", + }, + want: `if !(obj.FieldGtFloat64Pointer != nil && *obj.FieldGtFloat64Pointer > 12.34) { +errs = append(errs, types.NewValidationError("FieldGtFloat64Pointer must be > 12.34")) +} +`, + }, + { + name: "gte_intpointer_gte=32", + args: args{ + fieldName: "FieldGteIntPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteIntPointer != nil && *obj.FieldGteIntPointer >= 32) { +errs = append(errs, types.NewValidationError("FieldGteIntPointer must be >= 32")) +} +`, + }, + { + name: "gte_int8pointer_gte=32", + args: args{ + fieldName: "FieldGteInt8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int8", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteInt8Pointer != nil && *obj.FieldGteInt8Pointer >= 32) { +errs = append(errs, types.NewValidationError("FieldGteInt8Pointer must be >= 32")) +} +`, + }, + { + name: "gte_int16pointer_gte=32", + args: args{ + fieldName: "FieldGteInt16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int16", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteInt16Pointer != nil && *obj.FieldGteInt16Pointer >= 32) { +errs = append(errs, types.NewValidationError("FieldGteInt16Pointer must be >= 32")) +} +`, + }, + { + name: "gte_int32pointer_gte=32", + args: args{ + fieldName: "FieldGteInt32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int32", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteInt32Pointer != nil && *obj.FieldGteInt32Pointer >= 32) { +errs = append(errs, types.NewValidationError("FieldGteInt32Pointer must be >= 32")) +} +`, + }, + { + name: "gte_int64pointer_gte=32", + args: args{ + fieldName: "FieldGteInt64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int64", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteInt64Pointer != nil && *obj.FieldGteInt64Pointer >= 32) { +errs = append(errs, types.NewValidationError("FieldGteInt64Pointer must be >= 32")) +} +`, + }, + { + name: "gte_uintpointer_gte=32", + args: args{ + fieldName: "FieldGteUintPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteUintPointer != nil && *obj.FieldGteUintPointer >= 32) { +errs = append(errs, types.NewValidationError("FieldGteUintPointer must be >= 32")) +} +`, + }, + { + name: "gte_uint8pointer_gte=32", + args: args{ + fieldName: "FieldGteUint8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint8", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteUint8Pointer != nil && *obj.FieldGteUint8Pointer >= 32) { +errs = append(errs, types.NewValidationError("FieldGteUint8Pointer must be >= 32")) +} +`, + }, + { + name: "gte_uint16pointer_gte=32", + args: args{ + fieldName: "FieldGteUint16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint16", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteUint16Pointer != nil && *obj.FieldGteUint16Pointer >= 32) { +errs = append(errs, types.NewValidationError("FieldGteUint16Pointer must be >= 32")) +} +`, + }, + { + name: "gte_uint32pointer_gte=32", + args: args{ + fieldName: "FieldGteUint32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint32", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteUint32Pointer != nil && *obj.FieldGteUint32Pointer >= 32) { +errs = append(errs, types.NewValidationError("FieldGteUint32Pointer must be >= 32")) +} +`, + }, + { + name: "gte_uint64pointer_gte=32", + args: args{ + fieldName: "FieldGteUint64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint64", Size: ""}, + fieldValidation: "gte=32", + }, + want: `if !(obj.FieldGteUint64Pointer != nil && *obj.FieldGteUint64Pointer >= 32) { +errs = append(errs, types.NewValidationError("FieldGteUint64Pointer must be >= 32")) +} +`, + }, + { + name: "gte_float32pointer_gte=12.34", + args: args{ + fieldName: "FieldGteFloat32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float32", Size: ""}, + fieldValidation: "gte=12.34", + }, + want: `if !(obj.FieldGteFloat32Pointer != nil && *obj.FieldGteFloat32Pointer >= 12.34) { +errs = append(errs, types.NewValidationError("FieldGteFloat32Pointer must be >= 12.34")) +} +`, + }, + { + name: "gte_float64pointer_gte=12.34", + args: args{ + fieldName: "FieldGteFloat64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float64", Size: ""}, + fieldValidation: "gte=12.34", + }, + want: `if !(obj.FieldGteFloat64Pointer != nil && *obj.FieldGteFloat64Pointer >= 12.34) { +errs = append(errs, types.NewValidationError("FieldGteFloat64Pointer must be >= 12.34")) +} +`, + }, + { + name: "lt_intpointer_lt=32", + args: args{ + fieldName: "FieldLtIntPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtIntPointer != nil && *obj.FieldLtIntPointer < 32) { +errs = append(errs, types.NewValidationError("FieldLtIntPointer must be < 32")) +} +`, + }, + { + name: "lt_int8pointer_lt=32", + args: args{ + fieldName: "FieldLtInt8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int8", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtInt8Pointer != nil && *obj.FieldLtInt8Pointer < 32) { +errs = append(errs, types.NewValidationError("FieldLtInt8Pointer must be < 32")) +} +`, + }, + { + name: "lt_int16pointer_lt=32", + args: args{ + fieldName: "FieldLtInt16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int16", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtInt16Pointer != nil && *obj.FieldLtInt16Pointer < 32) { +errs = append(errs, types.NewValidationError("FieldLtInt16Pointer must be < 32")) +} +`, + }, + { + name: "lt_int32pointer_lt=32", + args: args{ + fieldName: "FieldLtInt32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int32", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtInt32Pointer != nil && *obj.FieldLtInt32Pointer < 32) { +errs = append(errs, types.NewValidationError("FieldLtInt32Pointer must be < 32")) +} +`, + }, + { + name: "lt_int64pointer_lt=32", + args: args{ + fieldName: "FieldLtInt64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int64", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtInt64Pointer != nil && *obj.FieldLtInt64Pointer < 32) { +errs = append(errs, types.NewValidationError("FieldLtInt64Pointer must be < 32")) +} +`, + }, + { + name: "lt_uintpointer_lt=32", + args: args{ + fieldName: "FieldLtUintPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtUintPointer != nil && *obj.FieldLtUintPointer < 32) { +errs = append(errs, types.NewValidationError("FieldLtUintPointer must be < 32")) +} +`, + }, + { + name: "lt_uint8pointer_lt=32", + args: args{ + fieldName: "FieldLtUint8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint8", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtUint8Pointer != nil && *obj.FieldLtUint8Pointer < 32) { +errs = append(errs, types.NewValidationError("FieldLtUint8Pointer must be < 32")) +} +`, + }, + { + name: "lt_uint16pointer_lt=32", + args: args{ + fieldName: "FieldLtUint16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint16", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtUint16Pointer != nil && *obj.FieldLtUint16Pointer < 32) { +errs = append(errs, types.NewValidationError("FieldLtUint16Pointer must be < 32")) +} +`, + }, + { + name: "lt_uint32pointer_lt=32", + args: args{ + fieldName: "FieldLtUint32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint32", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtUint32Pointer != nil && *obj.FieldLtUint32Pointer < 32) { +errs = append(errs, types.NewValidationError("FieldLtUint32Pointer must be < 32")) +} +`, + }, + { + name: "lt_uint64pointer_lt=32", + args: args{ + fieldName: "FieldLtUint64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint64", Size: ""}, + fieldValidation: "lt=32", + }, + want: `if !(obj.FieldLtUint64Pointer != nil && *obj.FieldLtUint64Pointer < 32) { +errs = append(errs, types.NewValidationError("FieldLtUint64Pointer must be < 32")) +} +`, + }, + { + name: "lt_float32pointer_lt=12.34", + args: args{ + fieldName: "FieldLtFloat32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float32", Size: ""}, + fieldValidation: "lt=12.34", + }, + want: `if !(obj.FieldLtFloat32Pointer != nil && *obj.FieldLtFloat32Pointer < 12.34) { +errs = append(errs, types.NewValidationError("FieldLtFloat32Pointer must be < 12.34")) +} +`, + }, + { + name: "lt_float64pointer_lt=12.34", + args: args{ + fieldName: "FieldLtFloat64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float64", Size: ""}, + fieldValidation: "lt=12.34", + }, + want: `if !(obj.FieldLtFloat64Pointer != nil && *obj.FieldLtFloat64Pointer < 12.34) { +errs = append(errs, types.NewValidationError("FieldLtFloat64Pointer must be < 12.34")) +} +`, + }, + { + name: "lte_intpointer_lte=32", + args: args{ + fieldName: "FieldLteIntPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteIntPointer != nil && *obj.FieldLteIntPointer <= 32) { +errs = append(errs, types.NewValidationError("FieldLteIntPointer must be <= 32")) +} +`, + }, + { + name: "lte_int8pointer_lte=32", + args: args{ + fieldName: "FieldLteInt8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int8", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteInt8Pointer != nil && *obj.FieldLteInt8Pointer <= 32) { +errs = append(errs, types.NewValidationError("FieldLteInt8Pointer must be <= 32")) +} +`, + }, + { + name: "lte_int16pointer_lte=32", + args: args{ + fieldName: "FieldLteInt16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int16", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteInt16Pointer != nil && *obj.FieldLteInt16Pointer <= 32) { +errs = append(errs, types.NewValidationError("FieldLteInt16Pointer must be <= 32")) +} +`, + }, + { + name: "lte_int32pointer_lte=32", + args: args{ + fieldName: "FieldLteInt32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int32", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteInt32Pointer != nil && *obj.FieldLteInt32Pointer <= 32) { +errs = append(errs, types.NewValidationError("FieldLteInt32Pointer must be <= 32")) +} +`, + }, + { + name: "lte_int64pointer_lte=32", + args: args{ + fieldName: "FieldLteInt64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int64", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteInt64Pointer != nil && *obj.FieldLteInt64Pointer <= 32) { +errs = append(errs, types.NewValidationError("FieldLteInt64Pointer must be <= 32")) +} +`, + }, + { + name: "lte_uintpointer_lte=32", + args: args{ + fieldName: "FieldLteUintPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteUintPointer != nil && *obj.FieldLteUintPointer <= 32) { +errs = append(errs, types.NewValidationError("FieldLteUintPointer must be <= 32")) +} +`, + }, + { + name: "lte_uint8pointer_lte=32", + args: args{ + fieldName: "FieldLteUint8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint8", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteUint8Pointer != nil && *obj.FieldLteUint8Pointer <= 32) { +errs = append(errs, types.NewValidationError("FieldLteUint8Pointer must be <= 32")) +} +`, + }, + { + name: "lte_uint16pointer_lte=32", + args: args{ + fieldName: "FieldLteUint16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint16", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteUint16Pointer != nil && *obj.FieldLteUint16Pointer <= 32) { +errs = append(errs, types.NewValidationError("FieldLteUint16Pointer must be <= 32")) +} +`, + }, + { + name: "lte_uint32pointer_lte=32", + args: args{ + fieldName: "FieldLteUint32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint32", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteUint32Pointer != nil && *obj.FieldLteUint32Pointer <= 32) { +errs = append(errs, types.NewValidationError("FieldLteUint32Pointer must be <= 32")) +} +`, + }, + { + name: "lte_uint64pointer_lte=32", + args: args{ + fieldName: "FieldLteUint64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint64", Size: ""}, + fieldValidation: "lte=32", + }, + want: `if !(obj.FieldLteUint64Pointer != nil && *obj.FieldLteUint64Pointer <= 32) { +errs = append(errs, types.NewValidationError("FieldLteUint64Pointer must be <= 32")) +} +`, + }, + { + name: "lte_float32pointer_lte=12.34", + args: args{ + fieldName: "FieldLteFloat32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float32", Size: ""}, + fieldValidation: "lte=12.34", + }, + want: `if !(obj.FieldLteFloat32Pointer != nil && *obj.FieldLteFloat32Pointer <= 12.34) { +errs = append(errs, types.NewValidationError("FieldLteFloat32Pointer must be <= 12.34")) +} +`, + }, + { + name: "lte_float64pointer_lte=12.34", + args: args{ + fieldName: "FieldLteFloat64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float64", Size: ""}, + fieldValidation: "lte=12.34", + }, + want: `if !(obj.FieldLteFloat64Pointer != nil && *obj.FieldLteFloat64Pointer <= 12.34) { +errs = append(errs, types.NewValidationError("FieldLteFloat64Pointer must be <= 12.34")) +} +`, + }, + { + name: "min_stringpointer_min=5", + args: args{ + fieldName: "FieldMinStringPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "string", Size: ""}, + fieldValidation: "min=5", + }, + want: `if !(obj.FieldMinStringPointer != nil && len(*obj.FieldMinStringPointer) >= 5) { +errs = append(errs, types.NewValidationError("FieldMinStringPointer length must be >= 5")) +} +`, + }, + { + name: "min_stringslicepointer_min=2", + args: args{ + fieldName: "FieldMinStringSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "string", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinStringSlicePointer != nil && len(*obj.FieldMinStringSlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinStringSlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_intslicepointer_min=2", + args: args{ + fieldName: "FieldMinIntSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinIntSlicePointer != nil && len(*obj.FieldMinIntSlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinIntSlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_int8slicepointer_min=2", + args: args{ + fieldName: "FieldMinInt8SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int8", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinInt8SlicePointer != nil && len(*obj.FieldMinInt8SlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt8SlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_int16slicepointer_min=2", + args: args{ + fieldName: "FieldMinInt16SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int16", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinInt16SlicePointer != nil && len(*obj.FieldMinInt16SlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt16SlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_int32slicepointer_min=2", + args: args{ + fieldName: "FieldMinInt32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int32", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinInt32SlicePointer != nil && len(*obj.FieldMinInt32SlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt32SlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_int64slicepointer_min=2", + args: args{ + fieldName: "FieldMinInt64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int64", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinInt64SlicePointer != nil && len(*obj.FieldMinInt64SlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt64SlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_uintslicepointer_min=2", + args: args{ + fieldName: "FieldMinUintSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinUintSlicePointer != nil && len(*obj.FieldMinUintSlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUintSlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_uint8slicepointer_min=2", + args: args{ + fieldName: "FieldMinUint8SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint8", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinUint8SlicePointer != nil && len(*obj.FieldMinUint8SlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint8SlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_uint16slicepointer_min=2", + args: args{ + fieldName: "FieldMinUint16SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint16", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinUint16SlicePointer != nil && len(*obj.FieldMinUint16SlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint16SlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_uint32slicepointer_min=2", + args: args{ + fieldName: "FieldMinUint32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint32", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinUint32SlicePointer != nil && len(*obj.FieldMinUint32SlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint32SlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_uint64slicepointer_min=2", + args: args{ + fieldName: "FieldMinUint64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint64", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinUint64SlicePointer != nil && len(*obj.FieldMinUint64SlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint64SlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_float32slicepointer_min=2", + args: args{ + fieldName: "FieldMinFloat32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "float32", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinFloat32SlicePointer != nil && len(*obj.FieldMinFloat32SlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinFloat32SlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_float64slicepointer_min=2", + args: args{ + fieldName: "FieldMinFloat64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "float64", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinFloat64SlicePointer != nil && len(*obj.FieldMinFloat64SlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinFloat64SlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_boolslicepointer_min=2", + args: args{ + fieldName: "FieldMinBoolSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "bool", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinBoolSlicePointer != nil && len(*obj.FieldMinBoolSlicePointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinBoolSlicePointer must have at least 2 elements")) +} +`, + }, + { + name: "min_stringmappointer_min=2", + args: args{ + fieldName: "FieldMinStringMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "string", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinStringMapPointer != nil && len(*obj.FieldMinStringMapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinStringMapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_intmappointer_min=2", + args: args{ + fieldName: "FieldMinIntMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinIntMapPointer != nil && len(*obj.FieldMinIntMapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinIntMapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_int8mappointer_min=2", + args: args{ + fieldName: "FieldMinInt8MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int8", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinInt8MapPointer != nil && len(*obj.FieldMinInt8MapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt8MapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_int16mappointer_min=2", + args: args{ + fieldName: "FieldMinInt16MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int16", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinInt16MapPointer != nil && len(*obj.FieldMinInt16MapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt16MapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_int32mappointer_min=2", + args: args{ + fieldName: "FieldMinInt32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int32", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinInt32MapPointer != nil && len(*obj.FieldMinInt32MapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt32MapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_int64mappointer_min=2", + args: args{ + fieldName: "FieldMinInt64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int64", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinInt64MapPointer != nil && len(*obj.FieldMinInt64MapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinInt64MapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_uintmappointer_min=2", + args: args{ + fieldName: "FieldMinUintMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinUintMapPointer != nil && len(*obj.FieldMinUintMapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUintMapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_uint8mappointer_min=2", + args: args{ + fieldName: "FieldMinUint8MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint8", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinUint8MapPointer != nil && len(*obj.FieldMinUint8MapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint8MapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_uint16mappointer_min=2", + args: args{ + fieldName: "FieldMinUint16MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint16", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinUint16MapPointer != nil && len(*obj.FieldMinUint16MapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint16MapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_uint32mappointer_min=2", + args: args{ + fieldName: "FieldMinUint32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint32", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinUint32MapPointer != nil && len(*obj.FieldMinUint32MapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint32MapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_uint64mappointer_min=2", + args: args{ + fieldName: "FieldMinUint64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint64", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinUint64MapPointer != nil && len(*obj.FieldMinUint64MapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinUint64MapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_float32mappointer_min=2", + args: args{ + fieldName: "FieldMinFloat32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "float32", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinFloat32MapPointer != nil && len(*obj.FieldMinFloat32MapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinFloat32MapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_float64mappointer_min=2", + args: args{ + fieldName: "FieldMinFloat64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "float64", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinFloat64MapPointer != nil && len(*obj.FieldMinFloat64MapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinFloat64MapPointer must have at least 2 elements")) +} +`, + }, + { + name: "min_boolmappointer_min=2", + args: args{ + fieldName: "FieldMinBoolMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "bool", Size: ""}, + fieldValidation: "min=2", + }, + want: `if !(obj.FieldMinBoolMapPointer != nil && len(*obj.FieldMinBoolMapPointer) >= 2) { +errs = append(errs, types.NewValidationError("FieldMinBoolMapPointer must have at least 2 elements")) +} +`, + }, + { + name: "max_stringpointer_max=3", + args: args{ + fieldName: "FieldMaxStringPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "string", Size: ""}, + fieldValidation: "max=3", + }, + want: `if !(obj.FieldMaxStringPointer != nil && len(*obj.FieldMaxStringPointer) <= 3) { +errs = append(errs, types.NewValidationError("FieldMaxStringPointer length must be <= 3")) +} +`, + }, + { + name: "max_stringslicepointer_max=2", + args: args{ + fieldName: "FieldMaxStringSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "string", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxStringSlicePointer != nil && len(*obj.FieldMaxStringSlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxStringSlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_intslicepointer_max=2", + args: args{ + fieldName: "FieldMaxIntSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxIntSlicePointer != nil && len(*obj.FieldMaxIntSlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxIntSlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_int8slicepointer_max=2", + args: args{ + fieldName: "FieldMaxInt8SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int8", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxInt8SlicePointer != nil && len(*obj.FieldMaxInt8SlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt8SlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_int16slicepointer_max=2", + args: args{ + fieldName: "FieldMaxInt16SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int16", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxInt16SlicePointer != nil && len(*obj.FieldMaxInt16SlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt16SlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_int32slicepointer_max=2", + args: args{ + fieldName: "FieldMaxInt32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int32", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxInt32SlicePointer != nil && len(*obj.FieldMaxInt32SlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt32SlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_int64slicepointer_max=2", + args: args{ + fieldName: "FieldMaxInt64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int64", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxInt64SlicePointer != nil && len(*obj.FieldMaxInt64SlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt64SlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_uintslicepointer_max=2", + args: args{ + fieldName: "FieldMaxUintSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxUintSlicePointer != nil && len(*obj.FieldMaxUintSlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUintSlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_uint8slicepointer_max=2", + args: args{ + fieldName: "FieldMaxUint8SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint8", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxUint8SlicePointer != nil && len(*obj.FieldMaxUint8SlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint8SlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_uint16slicepointer_max=2", + args: args{ + fieldName: "FieldMaxUint16SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint16", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxUint16SlicePointer != nil && len(*obj.FieldMaxUint16SlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint16SlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_uint32slicepointer_max=2", + args: args{ + fieldName: "FieldMaxUint32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint32", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxUint32SlicePointer != nil && len(*obj.FieldMaxUint32SlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint32SlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_uint64slicepointer_max=2", + args: args{ + fieldName: "FieldMaxUint64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint64", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxUint64SlicePointer != nil && len(*obj.FieldMaxUint64SlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint64SlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_float32slicepointer_max=2", + args: args{ + fieldName: "FieldMaxFloat32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "float32", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxFloat32SlicePointer != nil && len(*obj.FieldMaxFloat32SlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxFloat32SlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_float64slicepointer_max=2", + args: args{ + fieldName: "FieldMaxFloat64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "float64", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxFloat64SlicePointer != nil && len(*obj.FieldMaxFloat64SlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxFloat64SlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_boolslicepointer_max=2", + args: args{ + fieldName: "FieldMaxBoolSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "bool", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxBoolSlicePointer != nil && len(*obj.FieldMaxBoolSlicePointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxBoolSlicePointer must have at most 2 elements")) +} +`, + }, + { + name: "max_stringmappointer_max=2", + args: args{ + fieldName: "FieldMaxStringMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "string", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxStringMapPointer != nil && len(*obj.FieldMaxStringMapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxStringMapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_intmappointer_max=2", + args: args{ + fieldName: "FieldMaxIntMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxIntMapPointer != nil && len(*obj.FieldMaxIntMapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxIntMapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_int8mappointer_max=2", + args: args{ + fieldName: "FieldMaxInt8MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int8", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxInt8MapPointer != nil && len(*obj.FieldMaxInt8MapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt8MapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_int16mappointer_max=2", + args: args{ + fieldName: "FieldMaxInt16MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int16", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxInt16MapPointer != nil && len(*obj.FieldMaxInt16MapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt16MapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_int32mappointer_max=2", + args: args{ + fieldName: "FieldMaxInt32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int32", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxInt32MapPointer != nil && len(*obj.FieldMaxInt32MapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt32MapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_int64mappointer_max=2", + args: args{ + fieldName: "FieldMaxInt64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int64", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxInt64MapPointer != nil && len(*obj.FieldMaxInt64MapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxInt64MapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_uintmappointer_max=2", + args: args{ + fieldName: "FieldMaxUintMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxUintMapPointer != nil && len(*obj.FieldMaxUintMapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUintMapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_uint8mappointer_max=2", + args: args{ + fieldName: "FieldMaxUint8MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint8", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxUint8MapPointer != nil && len(*obj.FieldMaxUint8MapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint8MapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_uint16mappointer_max=2", + args: args{ + fieldName: "FieldMaxUint16MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint16", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxUint16MapPointer != nil && len(*obj.FieldMaxUint16MapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint16MapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_uint32mappointer_max=2", + args: args{ + fieldName: "FieldMaxUint32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint32", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxUint32MapPointer != nil && len(*obj.FieldMaxUint32MapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint32MapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_uint64mappointer_max=2", + args: args{ + fieldName: "FieldMaxUint64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint64", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxUint64MapPointer != nil && len(*obj.FieldMaxUint64MapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxUint64MapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_float32mappointer_max=2", + args: args{ + fieldName: "FieldMaxFloat32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "float32", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxFloat32MapPointer != nil && len(*obj.FieldMaxFloat32MapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxFloat32MapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_float64mappointer_max=2", + args: args{ + fieldName: "FieldMaxFloat64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "float64", Size: ""}, + fieldValidation: "max=2", + }, + want: `if !(obj.FieldMaxFloat64MapPointer != nil && len(*obj.FieldMaxFloat64MapPointer) <= 2) { +errs = append(errs, types.NewValidationError("FieldMaxFloat64MapPointer must have at most 2 elements")) +} +`, + }, + { + name: "max_boolmappointer_max=1", + args: args{ + fieldName: "FieldMaxBoolMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "bool", Size: ""}, + fieldValidation: "max=1", + }, + want: `if !(obj.FieldMaxBoolMapPointer != nil && len(*obj.FieldMaxBoolMapPointer) <= 1) { +errs = append(errs, types.NewValidationError("FieldMaxBoolMapPointer must have at most 1 elements")) +} +`, + }, + { + name: "eq_ignore_case_stringpointer_eq_ignore_case=abcde", + args: args{ + fieldName: "FieldEq_ignore_caseStringPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "string", Size: ""}, + fieldValidation: "eq_ignore_case=abcde", + }, + want: `if !(obj.FieldEq_ignore_caseStringPointer != nil && types.EqualFold(*obj.FieldEq_ignore_caseStringPointer, "abcde")) { +errs = append(errs, types.NewValidationError("FieldEq_ignore_caseStringPointer must be equal to 'abcde'")) +} +`, + }, + { + name: "neq_ignore_case_stringpointer_neq_ignore_case=abcde", + args: args{ + fieldName: "FieldNeq_ignore_caseStringPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "string", Size: ""}, + fieldValidation: "neq_ignore_case=abcde", + }, + want: `if !(obj.FieldNeq_ignore_caseStringPointer != nil && !types.EqualFold(*obj.FieldNeq_ignore_caseStringPointer, "abcde")) { +errs = append(errs, types.NewValidationError("FieldNeq_ignore_caseStringPointer must not be equal to 'abcde'")) +} +`, + }, + { + name: "len_stringpointer_len=2", + args: args{ + fieldName: "FieldLenStringPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "string", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenStringPointer != nil && len(*obj.FieldLenStringPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenStringPointer length must be 2")) +} +`, + }, + { + name: "len_stringslicepointer_len=2", + args: args{ + fieldName: "FieldLenStringSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "string", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenStringSlicePointer != nil && len(*obj.FieldLenStringSlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenStringSlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_intslicepointer_len=2", + args: args{ + fieldName: "FieldLenIntSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenIntSlicePointer != nil && len(*obj.FieldLenIntSlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenIntSlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_int8slicepointer_len=2", + args: args{ + fieldName: "FieldLenInt8SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int8", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenInt8SlicePointer != nil && len(*obj.FieldLenInt8SlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt8SlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_int16slicepointer_len=2", + args: args{ + fieldName: "FieldLenInt16SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int16", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenInt16SlicePointer != nil && len(*obj.FieldLenInt16SlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt16SlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_int32slicepointer_len=2", + args: args{ + fieldName: "FieldLenInt32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int32", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenInt32SlicePointer != nil && len(*obj.FieldLenInt32SlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt32SlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_int64slicepointer_len=2", + args: args{ + fieldName: "FieldLenInt64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int64", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenInt64SlicePointer != nil && len(*obj.FieldLenInt64SlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt64SlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_uintslicepointer_len=2", + args: args{ + fieldName: "FieldLenUintSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenUintSlicePointer != nil && len(*obj.FieldLenUintSlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUintSlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint8slicepointer_len=2", + args: args{ + fieldName: "FieldLenUint8SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint8", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenUint8SlicePointer != nil && len(*obj.FieldLenUint8SlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint8SlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint16slicepointer_len=2", + args: args{ + fieldName: "FieldLenUint16SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint16", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenUint16SlicePointer != nil && len(*obj.FieldLenUint16SlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint16SlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint32slicepointer_len=2", + args: args{ + fieldName: "FieldLenUint32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint32", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenUint32SlicePointer != nil && len(*obj.FieldLenUint32SlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint32SlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint64slicepointer_len=2", + args: args{ + fieldName: "FieldLenUint64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint64", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenUint64SlicePointer != nil && len(*obj.FieldLenUint64SlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint64SlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_float32slicepointer_len=2", + args: args{ + fieldName: "FieldLenFloat32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "float32", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenFloat32SlicePointer != nil && len(*obj.FieldLenFloat32SlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenFloat32SlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_float64slicepointer_len=2", + args: args{ + fieldName: "FieldLenFloat64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "float64", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenFloat64SlicePointer != nil && len(*obj.FieldLenFloat64SlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenFloat64SlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_boolslicepointer_len=2", + args: args{ + fieldName: "FieldLenBoolSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "bool", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenBoolSlicePointer != nil && len(*obj.FieldLenBoolSlicePointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenBoolSlicePointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_stringmappointer_len=2", + args: args{ + fieldName: "FieldLenStringMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "string", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenStringMapPointer != nil && len(*obj.FieldLenStringMapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenStringMapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_intmappointer_len=2", + args: args{ + fieldName: "FieldLenIntMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenIntMapPointer != nil && len(*obj.FieldLenIntMapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenIntMapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_int8mappointer_len=2", + args: args{ + fieldName: "FieldLenInt8MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int8", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenInt8MapPointer != nil && len(*obj.FieldLenInt8MapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt8MapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_int16mappointer_len=2", + args: args{ + fieldName: "FieldLenInt16MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int16", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenInt16MapPointer != nil && len(*obj.FieldLenInt16MapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt16MapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_int32mappointer_len=2", + args: args{ + fieldName: "FieldLenInt32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int32", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenInt32MapPointer != nil && len(*obj.FieldLenInt32MapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt32MapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_int64mappointer_len=2", + args: args{ + fieldName: "FieldLenInt64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int64", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenInt64MapPointer != nil && len(*obj.FieldLenInt64MapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenInt64MapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_uintmappointer_len=2", + args: args{ + fieldName: "FieldLenUintMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenUintMapPointer != nil && len(*obj.FieldLenUintMapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUintMapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint8mappointer_len=2", + args: args{ + fieldName: "FieldLenUint8MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint8", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenUint8MapPointer != nil && len(*obj.FieldLenUint8MapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint8MapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint16mappointer_len=2", + args: args{ + fieldName: "FieldLenUint16MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint16", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenUint16MapPointer != nil && len(*obj.FieldLenUint16MapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint16MapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint32mappointer_len=2", + args: args{ + fieldName: "FieldLenUint32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint32", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenUint32MapPointer != nil && len(*obj.FieldLenUint32MapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint32MapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_uint64mappointer_len=2", + args: args{ + fieldName: "FieldLenUint64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint64", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenUint64MapPointer != nil && len(*obj.FieldLenUint64MapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenUint64MapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_float32mappointer_len=2", + args: args{ + fieldName: "FieldLenFloat32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "float32", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenFloat32MapPointer != nil && len(*obj.FieldLenFloat32MapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenFloat32MapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_float64mappointer_len=2", + args: args{ + fieldName: "FieldLenFloat64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "float64", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenFloat64MapPointer != nil && len(*obj.FieldLenFloat64MapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenFloat64MapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "len_boolmappointer_len=2", + args: args{ + fieldName: "FieldLenBoolMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "bool", Size: ""}, + fieldValidation: "len=2", + }, + want: `if !(obj.FieldLenBoolMapPointer != nil && len(*obj.FieldLenBoolMapPointer) == 2) { +errs = append(errs, types.NewValidationError("FieldLenBoolMapPointer must have exactly 2 elements")) +} +`, + }, + { + name: "in_stringpointer_in=ab cd ef", + args: args{ + fieldName: "FieldInStringPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "string", Size: ""}, + fieldValidation: "in=ab cd ef", + }, + want: `if !((obj.FieldInStringPointer != nil && *obj.FieldInStringPointer == "ab") || (obj.FieldInStringPointer != nil && *obj.FieldInStringPointer == "cd") || (obj.FieldInStringPointer != nil && *obj.FieldInStringPointer == "ef")) { +errs = append(errs, types.NewValidationError("FieldInStringPointer must be one of 'ab' 'cd' 'ef'")) +} +`, + }, + { + name: "in_intpointer_in=12 34 56", + args: args{ + fieldName: "FieldInIntPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !((obj.FieldInIntPointer != nil && *obj.FieldInIntPointer == 12) || (obj.FieldInIntPointer != nil && *obj.FieldInIntPointer == 34) || (obj.FieldInIntPointer != nil && *obj.FieldInIntPointer == 56)) { +errs = append(errs, types.NewValidationError("FieldInIntPointer must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int8pointer_in=12 34 56", + args: args{ + fieldName: "FieldInInt8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int8", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !((obj.FieldInInt8Pointer != nil && *obj.FieldInInt8Pointer == 12) || (obj.FieldInInt8Pointer != nil && *obj.FieldInInt8Pointer == 34) || (obj.FieldInInt8Pointer != nil && *obj.FieldInInt8Pointer == 56)) { +errs = append(errs, types.NewValidationError("FieldInInt8Pointer must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int16pointer_in=12 34 56", + args: args{ + fieldName: "FieldInInt16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int16", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !((obj.FieldInInt16Pointer != nil && *obj.FieldInInt16Pointer == 12) || (obj.FieldInInt16Pointer != nil && *obj.FieldInInt16Pointer == 34) || (obj.FieldInInt16Pointer != nil && *obj.FieldInInt16Pointer == 56)) { +errs = append(errs, types.NewValidationError("FieldInInt16Pointer must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int32pointer_in=12 34 56", + args: args{ + fieldName: "FieldInInt32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int32", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !((obj.FieldInInt32Pointer != nil && *obj.FieldInInt32Pointer == 12) || (obj.FieldInInt32Pointer != nil && *obj.FieldInInt32Pointer == 34) || (obj.FieldInInt32Pointer != nil && *obj.FieldInInt32Pointer == 56)) { +errs = append(errs, types.NewValidationError("FieldInInt32Pointer must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int64pointer_in=12 34 56", + args: args{ + fieldName: "FieldInInt64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int64", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !((obj.FieldInInt64Pointer != nil && *obj.FieldInInt64Pointer == 12) || (obj.FieldInInt64Pointer != nil && *obj.FieldInInt64Pointer == 34) || (obj.FieldInInt64Pointer != nil && *obj.FieldInInt64Pointer == 56)) { +errs = append(errs, types.NewValidationError("FieldInInt64Pointer must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uintpointer_in=12 34 56", + args: args{ + fieldName: "FieldInUintPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !((obj.FieldInUintPointer != nil && *obj.FieldInUintPointer == 12) || (obj.FieldInUintPointer != nil && *obj.FieldInUintPointer == 34) || (obj.FieldInUintPointer != nil && *obj.FieldInUintPointer == 56)) { +errs = append(errs, types.NewValidationError("FieldInUintPointer must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint8pointer_in=12 34 56", + args: args{ + fieldName: "FieldInUint8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint8", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !((obj.FieldInUint8Pointer != nil && *obj.FieldInUint8Pointer == 12) || (obj.FieldInUint8Pointer != nil && *obj.FieldInUint8Pointer == 34) || (obj.FieldInUint8Pointer != nil && *obj.FieldInUint8Pointer == 56)) { +errs = append(errs, types.NewValidationError("FieldInUint8Pointer must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint16pointer_in=12 34 56", + args: args{ + fieldName: "FieldInUint16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint16", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !((obj.FieldInUint16Pointer != nil && *obj.FieldInUint16Pointer == 12) || (obj.FieldInUint16Pointer != nil && *obj.FieldInUint16Pointer == 34) || (obj.FieldInUint16Pointer != nil && *obj.FieldInUint16Pointer == 56)) { +errs = append(errs, types.NewValidationError("FieldInUint16Pointer must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint32pointer_in=12 34 56", + args: args{ + fieldName: "FieldInUint32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint32", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !((obj.FieldInUint32Pointer != nil && *obj.FieldInUint32Pointer == 12) || (obj.FieldInUint32Pointer != nil && *obj.FieldInUint32Pointer == 34) || (obj.FieldInUint32Pointer != nil && *obj.FieldInUint32Pointer == 56)) { +errs = append(errs, types.NewValidationError("FieldInUint32Pointer must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint64pointer_in=12 34 56", + args: args{ + fieldName: "FieldInUint64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint64", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !((obj.FieldInUint64Pointer != nil && *obj.FieldInUint64Pointer == 12) || (obj.FieldInUint64Pointer != nil && *obj.FieldInUint64Pointer == 34) || (obj.FieldInUint64Pointer != nil && *obj.FieldInUint64Pointer == 56)) { +errs = append(errs, types.NewValidationError("FieldInUint64Pointer must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_float32pointer_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float32", Size: ""}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !((obj.FieldInFloat32Pointer != nil && *obj.FieldInFloat32Pointer == 11.11) || (obj.FieldInFloat32Pointer != nil && *obj.FieldInFloat32Pointer == 22.22) || (obj.FieldInFloat32Pointer != nil && *obj.FieldInFloat32Pointer == 33.33)) { +errs = append(errs, types.NewValidationError("FieldInFloat32Pointer must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_float64pointer_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float64", Size: ""}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !((obj.FieldInFloat64Pointer != nil && *obj.FieldInFloat64Pointer == 11.11) || (obj.FieldInFloat64Pointer != nil && *obj.FieldInFloat64Pointer == 22.22) || (obj.FieldInFloat64Pointer != nil && *obj.FieldInFloat64Pointer == 33.33)) { +errs = append(errs, types.NewValidationError("FieldInFloat64Pointer must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_boolpointer_in=true", + args: args{ + fieldName: "FieldInBoolPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "bool", Size: ""}, + fieldValidation: "in=true", + }, + want: `if !((obj.FieldInBoolPointer != nil && *obj.FieldInBoolPointer == true)) { +errs = append(errs, types.NewValidationError("FieldInBoolPointer must be one of 'true'")) +} +`, + }, + { + name: "in_stringslicepointer_in=ab cd ef", + args: args{ + fieldName: "FieldInStringSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "string", Size: ""}, + fieldValidation: "in=ab cd ef", + }, + want: `if !(obj.FieldInStringSlicePointer != nil && types.SliceOnlyContains(*obj.FieldInStringSlicePointer, []string{"ab", "cd", "ef"})) { +errs = append(errs, types.NewValidationError("FieldInStringSlicePointer elements must be one of 'ab' 'cd' 'ef'")) +} +`, + }, + { + name: "in_intslicepointer_in=12 34 56", + args: args{ + fieldName: "FieldInIntSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInIntSlicePointer != nil && types.SliceOnlyContains(*obj.FieldInIntSlicePointer, []int{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInIntSlicePointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int8slicepointer_in=12 34 56", + args: args{ + fieldName: "FieldInInt8SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int8", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt8SlicePointer != nil && types.SliceOnlyContains(*obj.FieldInInt8SlicePointer, []int8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt8SlicePointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int16slicepointer_in=12 34 56", + args: args{ + fieldName: "FieldInInt16SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int16", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt16SlicePointer != nil && types.SliceOnlyContains(*obj.FieldInInt16SlicePointer, []int16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt16SlicePointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int32slicepointer_in=12 34 56", + args: args{ + fieldName: "FieldInInt32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int32", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt32SlicePointer != nil && types.SliceOnlyContains(*obj.FieldInInt32SlicePointer, []int32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt32SlicePointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int64slicepointer_in=12 34 56", + args: args{ + fieldName: "FieldInInt64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int64", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt64SlicePointer != nil && types.SliceOnlyContains(*obj.FieldInInt64SlicePointer, []int64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt64SlicePointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uintslicepointer_in=12 34 56", + args: args{ + fieldName: "FieldInUintSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUintSlicePointer != nil && types.SliceOnlyContains(*obj.FieldInUintSlicePointer, []uint{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUintSlicePointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint8slicepointer_in=12 34 56", + args: args{ + fieldName: "FieldInUint8SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint8", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint8SlicePointer != nil && types.SliceOnlyContains(*obj.FieldInUint8SlicePointer, []uint8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint8SlicePointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint16slicepointer_in=12 34 56", + args: args{ + fieldName: "FieldInUint16SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint16", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint16SlicePointer != nil && types.SliceOnlyContains(*obj.FieldInUint16SlicePointer, []uint16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint16SlicePointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint32slicepointer_in=12 34 56", + args: args{ + fieldName: "FieldInUint32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint32", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint32SlicePointer != nil && types.SliceOnlyContains(*obj.FieldInUint32SlicePointer, []uint32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint32SlicePointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint64slicepointer_in=12 34 56", + args: args{ + fieldName: "FieldInUint64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint64", Size: ""}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint64SlicePointer != nil && types.SliceOnlyContains(*obj.FieldInUint64SlicePointer, []uint64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint64SlicePointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_float32slicepointer_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "float32", Size: ""}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(obj.FieldInFloat32SlicePointer != nil && types.SliceOnlyContains(*obj.FieldInFloat32SlicePointer, []float32{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldInFloat32SlicePointer elements must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_float64slicepointer_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "float64", Size: ""}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(obj.FieldInFloat64SlicePointer != nil && types.SliceOnlyContains(*obj.FieldInFloat64SlicePointer, []float64{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldInFloat64SlicePointer elements must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_boolslicepointer_in=true", + args: args{ + fieldName: "FieldInBoolSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "bool", Size: ""}, + fieldValidation: "in=true", + }, + want: `if !(obj.FieldInBoolSlicePointer != nil && types.SliceOnlyContains(*obj.FieldInBoolSlicePointer, []bool{true})) { +errs = append(errs, types.NewValidationError("FieldInBoolSlicePointer elements must be one of 'true'")) +} +`, + }, + { + name: "in_stringarraypointer_in=ab cd ef", + args: args{ + fieldName: "FieldInStringArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "string", Size: "3"}, + fieldValidation: "in=ab cd ef", + }, + want: `if !(obj.FieldInStringArrayPointer != nil && types.SliceOnlyContains(obj.FieldInStringArrayPointer[:], []string{"ab", "cd", "ef"})) { +errs = append(errs, types.NewValidationError("FieldInStringArrayPointer elements must be one of 'ab' 'cd' 'ef'")) +} +`, + }, + { + name: "in_intarraypointer_in=12 34 56", + args: args{ + fieldName: "FieldInIntArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInIntArrayPointer != nil && types.SliceOnlyContains(obj.FieldInIntArrayPointer[:], []int{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInIntArrayPointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int8arraypointer_in=12 34 56", + args: args{ + fieldName: "FieldInInt8ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int8", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt8ArrayPointer != nil && types.SliceOnlyContains(obj.FieldInInt8ArrayPointer[:], []int8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt8ArrayPointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int16arraypointer_in=12 34 56", + args: args{ + fieldName: "FieldInInt16ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int16", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt16ArrayPointer != nil && types.SliceOnlyContains(obj.FieldInInt16ArrayPointer[:], []int16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt16ArrayPointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int32arraypointer_in=12 34 56", + args: args{ + fieldName: "FieldInInt32ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int32", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt32ArrayPointer != nil && types.SliceOnlyContains(obj.FieldInInt32ArrayPointer[:], []int32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt32ArrayPointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_int64arraypointer_in=12 34 56", + args: args{ + fieldName: "FieldInInt64ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int64", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInInt64ArrayPointer != nil && types.SliceOnlyContains(obj.FieldInInt64ArrayPointer[:], []int64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInInt64ArrayPointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uintarraypointer_in=12 34 56", + args: args{ + fieldName: "FieldInUintArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUintArrayPointer != nil && types.SliceOnlyContains(obj.FieldInUintArrayPointer[:], []uint{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUintArrayPointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint8arraypointer_in=12 34 56", + args: args{ + fieldName: "FieldInUint8ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint8", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint8ArrayPointer != nil && types.SliceOnlyContains(obj.FieldInUint8ArrayPointer[:], []uint8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint8ArrayPointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint16arraypointer_in=12 34 56", + args: args{ + fieldName: "FieldInUint16ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint16", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint16ArrayPointer != nil && types.SliceOnlyContains(obj.FieldInUint16ArrayPointer[:], []uint16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint16ArrayPointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint32arraypointer_in=12 34 56", + args: args{ + fieldName: "FieldInUint32ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint32", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint32ArrayPointer != nil && types.SliceOnlyContains(obj.FieldInUint32ArrayPointer[:], []uint32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint32ArrayPointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_uint64arraypointer_in=12 34 56", + args: args{ + fieldName: "FieldInUint64ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint64", Size: "3"}, + fieldValidation: "in=12 34 56", + }, + want: `if !(obj.FieldInUint64ArrayPointer != nil && types.SliceOnlyContains(obj.FieldInUint64ArrayPointer[:], []uint64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldInUint64ArrayPointer elements must be one of '12' '34' '56'")) +} +`, + }, + { + name: "in_float32arraypointer_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat32ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "float32", Size: "3"}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(obj.FieldInFloat32ArrayPointer != nil && types.SliceOnlyContains(obj.FieldInFloat32ArrayPointer[:], []float32{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldInFloat32ArrayPointer elements must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_float64arraypointer_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat64ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "float64", Size: "3"}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(obj.FieldInFloat64ArrayPointer != nil && types.SliceOnlyContains(obj.FieldInFloat64ArrayPointer[:], []float64{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldInFloat64ArrayPointer elements must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_boolarraypointer_in=true", + args: args{ + fieldName: "FieldInBoolArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "bool", Size: "3"}, + fieldValidation: "in=true", + }, + want: `if !(obj.FieldInBoolArrayPointer != nil && types.SliceOnlyContains(obj.FieldInBoolArrayPointer[:], []bool{true})) { +errs = append(errs, types.NewValidationError("FieldInBoolArrayPointer elements must be one of 'true'")) +} +`, + }, + { + name: "in_stringmappointer_in=a b c", + args: args{ + fieldName: "FieldInStringMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "string", Size: ""}, + fieldValidation: "in=a b c", + }, + want: `if !(obj.FieldInStringMapPointer != nil && types.MapOnlyContains(*obj.FieldInStringMapPointer, []string{"a", "b", "c"})) { +errs = append(errs, types.NewValidationError("FieldInStringMapPointer elements must be one of 'a' 'b' 'c'")) +} +`, + }, + { + name: "in_intmappointer_in=1 2 3", + args: args{ + fieldName: "FieldInIntMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(obj.FieldInIntMapPointer != nil && types.MapOnlyContains(*obj.FieldInIntMapPointer, []int{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInIntMapPointer elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_int8mappointer_in=1 2 3", + args: args{ + fieldName: "FieldInInt8MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int8", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(obj.FieldInInt8MapPointer != nil && types.MapOnlyContains(*obj.FieldInInt8MapPointer, []int8{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInInt8MapPointer elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_int16mappointer_in=1 2 3", + args: args{ + fieldName: "FieldInInt16MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int16", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(obj.FieldInInt16MapPointer != nil && types.MapOnlyContains(*obj.FieldInInt16MapPointer, []int16{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInInt16MapPointer elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_int32mappointer_in=1 2 3", + args: args{ + fieldName: "FieldInInt32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int32", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(obj.FieldInInt32MapPointer != nil && types.MapOnlyContains(*obj.FieldInInt32MapPointer, []int32{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInInt32MapPointer elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_int64mappointer_in=1 2 3", + args: args{ + fieldName: "FieldInInt64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int64", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(obj.FieldInInt64MapPointer != nil && types.MapOnlyContains(*obj.FieldInInt64MapPointer, []int64{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInInt64MapPointer elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_uintmappointer_in=1 2 3", + args: args{ + fieldName: "FieldInUintMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(obj.FieldInUintMapPointer != nil && types.MapOnlyContains(*obj.FieldInUintMapPointer, []uint{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInUintMapPointer elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_uint8mappointer_in=1 2 3", + args: args{ + fieldName: "FieldInUint8MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint8", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(obj.FieldInUint8MapPointer != nil && types.MapOnlyContains(*obj.FieldInUint8MapPointer, []uint8{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInUint8MapPointer elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_uint16mappointer_in=1 2 3", + args: args{ + fieldName: "FieldInUint16MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint16", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(obj.FieldInUint16MapPointer != nil && types.MapOnlyContains(*obj.FieldInUint16MapPointer, []uint16{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInUint16MapPointer elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_uint32mappointer_in=1 2 3", + args: args{ + fieldName: "FieldInUint32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint32", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(obj.FieldInUint32MapPointer != nil && types.MapOnlyContains(*obj.FieldInUint32MapPointer, []uint32{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInUint32MapPointer elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_uint64mappointer_in=1 2 3", + args: args{ + fieldName: "FieldInUint64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint64", Size: ""}, + fieldValidation: "in=1 2 3", + }, + want: `if !(obj.FieldInUint64MapPointer != nil && types.MapOnlyContains(*obj.FieldInUint64MapPointer, []uint64{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldInUint64MapPointer elements must be one of '1' '2' '3'")) +} +`, + }, + { + name: "in_float32mappointer_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "float32", Size: ""}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(obj.FieldInFloat32MapPointer != nil && types.MapOnlyContains(*obj.FieldInFloat32MapPointer, []float32{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldInFloat32MapPointer elements must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_float64mappointer_in=11.11 22.22 33.33", + args: args{ + fieldName: "FieldInFloat64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "float64", Size: ""}, + fieldValidation: "in=11.11 22.22 33.33", + }, + want: `if !(obj.FieldInFloat64MapPointer != nil && types.MapOnlyContains(*obj.FieldInFloat64MapPointer, []float64{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldInFloat64MapPointer elements must be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "in_boolmappointer_in=false", + args: args{ + fieldName: "FieldInBoolMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "bool", Size: ""}, + fieldValidation: "in=false", + }, + want: `if !(obj.FieldInBoolMapPointer != nil && types.MapOnlyContains(*obj.FieldInBoolMapPointer, []bool{false})) { +errs = append(errs, types.NewValidationError("FieldInBoolMapPointer elements must be one of 'false'")) +} +`, + }, + { + name: "nin_stringpointer_nin=ab cd ef", + args: args{ + fieldName: "FieldNinStringPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "string", Size: ""}, + fieldValidation: "nin=ab cd ef", + }, + want: `if !((obj.FieldNinStringPointer != nil && *obj.FieldNinStringPointer != "ab") && (obj.FieldNinStringPointer != nil && *obj.FieldNinStringPointer != "cd") && (obj.FieldNinStringPointer != nil && *obj.FieldNinStringPointer != "ef")) { +errs = append(errs, types.NewValidationError("FieldNinStringPointer must not be one of 'ab' 'cd' 'ef'")) +} +`, + }, + { + name: "nin_intpointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinIntPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !((obj.FieldNinIntPointer != nil && *obj.FieldNinIntPointer != 12) && (obj.FieldNinIntPointer != nil && *obj.FieldNinIntPointer != 34) && (obj.FieldNinIntPointer != nil && *obj.FieldNinIntPointer != 56)) { +errs = append(errs, types.NewValidationError("FieldNinIntPointer must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int8pointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int8", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !((obj.FieldNinInt8Pointer != nil && *obj.FieldNinInt8Pointer != 12) && (obj.FieldNinInt8Pointer != nil && *obj.FieldNinInt8Pointer != 34) && (obj.FieldNinInt8Pointer != nil && *obj.FieldNinInt8Pointer != 56)) { +errs = append(errs, types.NewValidationError("FieldNinInt8Pointer must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int16pointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int16", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !((obj.FieldNinInt16Pointer != nil && *obj.FieldNinInt16Pointer != 12) && (obj.FieldNinInt16Pointer != nil && *obj.FieldNinInt16Pointer != 34) && (obj.FieldNinInt16Pointer != nil && *obj.FieldNinInt16Pointer != 56)) { +errs = append(errs, types.NewValidationError("FieldNinInt16Pointer must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int32pointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int32", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !((obj.FieldNinInt32Pointer != nil && *obj.FieldNinInt32Pointer != 12) && (obj.FieldNinInt32Pointer != nil && *obj.FieldNinInt32Pointer != 34) && (obj.FieldNinInt32Pointer != nil && *obj.FieldNinInt32Pointer != 56)) { +errs = append(errs, types.NewValidationError("FieldNinInt32Pointer must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int64pointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "int64", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !((obj.FieldNinInt64Pointer != nil && *obj.FieldNinInt64Pointer != 12) && (obj.FieldNinInt64Pointer != nil && *obj.FieldNinInt64Pointer != 34) && (obj.FieldNinInt64Pointer != nil && *obj.FieldNinInt64Pointer != 56)) { +errs = append(errs, types.NewValidationError("FieldNinInt64Pointer must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uintpointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUintPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !((obj.FieldNinUintPointer != nil && *obj.FieldNinUintPointer != 12) && (obj.FieldNinUintPointer != nil && *obj.FieldNinUintPointer != 34) && (obj.FieldNinUintPointer != nil && *obj.FieldNinUintPointer != 56)) { +errs = append(errs, types.NewValidationError("FieldNinUintPointer must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint8pointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint8Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint8", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !((obj.FieldNinUint8Pointer != nil && *obj.FieldNinUint8Pointer != 12) && (obj.FieldNinUint8Pointer != nil && *obj.FieldNinUint8Pointer != 34) && (obj.FieldNinUint8Pointer != nil && *obj.FieldNinUint8Pointer != 56)) { +errs = append(errs, types.NewValidationError("FieldNinUint8Pointer must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint16pointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint16Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint16", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !((obj.FieldNinUint16Pointer != nil && *obj.FieldNinUint16Pointer != 12) && (obj.FieldNinUint16Pointer != nil && *obj.FieldNinUint16Pointer != 34) && (obj.FieldNinUint16Pointer != nil && *obj.FieldNinUint16Pointer != 56)) { +errs = append(errs, types.NewValidationError("FieldNinUint16Pointer must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint32pointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint32", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !((obj.FieldNinUint32Pointer != nil && *obj.FieldNinUint32Pointer != 12) && (obj.FieldNinUint32Pointer != nil && *obj.FieldNinUint32Pointer != 34) && (obj.FieldNinUint32Pointer != nil && *obj.FieldNinUint32Pointer != 56)) { +errs = append(errs, types.NewValidationError("FieldNinUint32Pointer must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint64pointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "uint64", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !((obj.FieldNinUint64Pointer != nil && *obj.FieldNinUint64Pointer != 12) && (obj.FieldNinUint64Pointer != nil && *obj.FieldNinUint64Pointer != 34) && (obj.FieldNinUint64Pointer != nil && *obj.FieldNinUint64Pointer != 56)) { +errs = append(errs, types.NewValidationError("FieldNinUint64Pointer must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_float32pointer_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat32Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float32", Size: ""}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !((obj.FieldNinFloat32Pointer != nil && *obj.FieldNinFloat32Pointer != 11.11) && (obj.FieldNinFloat32Pointer != nil && *obj.FieldNinFloat32Pointer != 22.22) && (obj.FieldNinFloat32Pointer != nil && *obj.FieldNinFloat32Pointer != 33.33)) { +errs = append(errs, types.NewValidationError("FieldNinFloat32Pointer must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_float64pointer_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat64Pointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "float64", Size: ""}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !((obj.FieldNinFloat64Pointer != nil && *obj.FieldNinFloat64Pointer != 11.11) && (obj.FieldNinFloat64Pointer != nil && *obj.FieldNinFloat64Pointer != 22.22) && (obj.FieldNinFloat64Pointer != nil && *obj.FieldNinFloat64Pointer != 33.33)) { +errs = append(errs, types.NewValidationError("FieldNinFloat64Pointer must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_boolpointer_nin=true", + args: args{ + fieldName: "FieldNinBoolPointer", + fieldType: common.FieldType{ComposedType: "*", BaseType: "bool", Size: ""}, + fieldValidation: "nin=true", + }, + want: `if !((obj.FieldNinBoolPointer != nil && *obj.FieldNinBoolPointer != true)) { +errs = append(errs, types.NewValidationError("FieldNinBoolPointer must not be one of 'true'")) +} +`, + }, + { + name: "nin_stringslicepointer_nin=ab cd ef", + args: args{ + fieldName: "FieldNinStringSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "string", Size: ""}, + fieldValidation: "nin=ab cd ef", + }, + want: `if !(obj.FieldNinStringSlicePointer != nil && types.SliceNotContains(*obj.FieldNinStringSlicePointer, []string{"ab", "cd", "ef"})) { +errs = append(errs, types.NewValidationError("FieldNinStringSlicePointer elements must not be one of 'ab' 'cd' 'ef'")) +} +`, + }, + { + name: "nin_intslicepointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinIntSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinIntSlicePointer != nil && types.SliceNotContains(*obj.FieldNinIntSlicePointer, []int{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinIntSlicePointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int8slicepointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt8SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int8", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt8SlicePointer != nil && types.SliceNotContains(*obj.FieldNinInt8SlicePointer, []int8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt8SlicePointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int16slicepointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt16SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int16", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt16SlicePointer != nil && types.SliceNotContains(*obj.FieldNinInt16SlicePointer, []int16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt16SlicePointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int32slicepointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int32", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt32SlicePointer != nil && types.SliceNotContains(*obj.FieldNinInt32SlicePointer, []int32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt32SlicePointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int64slicepointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "int64", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt64SlicePointer != nil && types.SliceNotContains(*obj.FieldNinInt64SlicePointer, []int64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt64SlicePointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uintslicepointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUintSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUintSlicePointer != nil && types.SliceNotContains(*obj.FieldNinUintSlicePointer, []uint{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUintSlicePointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint8slicepointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint8SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint8", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint8SlicePointer != nil && types.SliceNotContains(*obj.FieldNinUint8SlicePointer, []uint8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint8SlicePointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint16slicepointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint16SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint16", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint16SlicePointer != nil && types.SliceNotContains(*obj.FieldNinUint16SlicePointer, []uint16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint16SlicePointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint32slicepointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint32", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint32SlicePointer != nil && types.SliceNotContains(*obj.FieldNinUint32SlicePointer, []uint32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint32SlicePointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint64slicepointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "uint64", Size: ""}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint64SlicePointer != nil && types.SliceNotContains(*obj.FieldNinUint64SlicePointer, []uint64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint64SlicePointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_float32slicepointer_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat32SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "float32", Size: ""}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(obj.FieldNinFloat32SlicePointer != nil && types.SliceNotContains(*obj.FieldNinFloat32SlicePointer, []float32{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldNinFloat32SlicePointer elements must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_float64slicepointer_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat64SlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "float64", Size: ""}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(obj.FieldNinFloat64SlicePointer != nil && types.SliceNotContains(*obj.FieldNinFloat64SlicePointer, []float64{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldNinFloat64SlicePointer elements must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_boolslicepointer_nin=true", + args: args{ + fieldName: "FieldNinBoolSlicePointer", + fieldType: common.FieldType{ComposedType: "*[]", BaseType: "bool", Size: ""}, + fieldValidation: "nin=true", + }, + want: `if !(obj.FieldNinBoolSlicePointer != nil && types.SliceNotContains(*obj.FieldNinBoolSlicePointer, []bool{true})) { +errs = append(errs, types.NewValidationError("FieldNinBoolSlicePointer elements must not be one of 'true'")) +} +`, + }, + { + name: "nin_stringarraypointer_nin=ab cd ef", + args: args{ + fieldName: "FieldNinStringArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "string", Size: "3"}, + fieldValidation: "nin=ab cd ef", + }, + want: `if !(obj.FieldNinStringArrayPointer != nil && types.SliceNotContains(obj.FieldNinStringArrayPointer[:], []string{"ab", "cd", "ef"})) { +errs = append(errs, types.NewValidationError("FieldNinStringArrayPointer elements must not be one of 'ab' 'cd' 'ef'")) +} +`, + }, + { + name: "nin_intarraypointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinIntArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinIntArrayPointer != nil && types.SliceNotContains(obj.FieldNinIntArrayPointer[:], []int{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinIntArrayPointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int8arraypointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt8ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int8", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt8ArrayPointer != nil && types.SliceNotContains(obj.FieldNinInt8ArrayPointer[:], []int8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt8ArrayPointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int16arraypointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt16ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int16", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt16ArrayPointer != nil && types.SliceNotContains(obj.FieldNinInt16ArrayPointer[:], []int16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt16ArrayPointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int32arraypointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt32ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int32", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt32ArrayPointer != nil && types.SliceNotContains(obj.FieldNinInt32ArrayPointer[:], []int32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt32ArrayPointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_int64arraypointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinInt64ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "int64", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinInt64ArrayPointer != nil && types.SliceNotContains(obj.FieldNinInt64ArrayPointer[:], []int64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinInt64ArrayPointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uintarraypointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUintArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUintArrayPointer != nil && types.SliceNotContains(obj.FieldNinUintArrayPointer[:], []uint{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUintArrayPointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint8arraypointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint8ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint8", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint8ArrayPointer != nil && types.SliceNotContains(obj.FieldNinUint8ArrayPointer[:], []uint8{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint8ArrayPointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint16arraypointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint16ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint16", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint16ArrayPointer != nil && types.SliceNotContains(obj.FieldNinUint16ArrayPointer[:], []uint16{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint16ArrayPointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint32arraypointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint32ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint32", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint32ArrayPointer != nil && types.SliceNotContains(obj.FieldNinUint32ArrayPointer[:], []uint32{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint32ArrayPointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_uint64arraypointer_nin=12 34 56", + args: args{ + fieldName: "FieldNinUint64ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "uint64", Size: "3"}, + fieldValidation: "nin=12 34 56", + }, + want: `if !(obj.FieldNinUint64ArrayPointer != nil && types.SliceNotContains(obj.FieldNinUint64ArrayPointer[:], []uint64{12, 34, 56})) { +errs = append(errs, types.NewValidationError("FieldNinUint64ArrayPointer elements must not be one of '12' '34' '56'")) +} +`, + }, + { + name: "nin_float32arraypointer_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat32ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "float32", Size: "3"}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(obj.FieldNinFloat32ArrayPointer != nil && types.SliceNotContains(obj.FieldNinFloat32ArrayPointer[:], []float32{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldNinFloat32ArrayPointer elements must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_float64arraypointer_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat64ArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "float64", Size: "3"}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(obj.FieldNinFloat64ArrayPointer != nil && types.SliceNotContains(obj.FieldNinFloat64ArrayPointer[:], []float64{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldNinFloat64ArrayPointer elements must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_boolarraypointer_nin=true", + args: args{ + fieldName: "FieldNinBoolArrayPointer", + fieldType: common.FieldType{ComposedType: "*[N]", BaseType: "bool", Size: "3"}, + fieldValidation: "nin=true", + }, + want: `if !(obj.FieldNinBoolArrayPointer != nil && types.SliceNotContains(obj.FieldNinBoolArrayPointer[:], []bool{true})) { +errs = append(errs, types.NewValidationError("FieldNinBoolArrayPointer elements must not be one of 'true'")) +} +`, + }, + { + name: "nin_stringmappointer_nin=a b c", + args: args{ + fieldName: "FieldNinStringMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "string", Size: ""}, + fieldValidation: "nin=a b c", + }, + want: `if !(obj.FieldNinStringMapPointer != nil && types.MapNotContains(*obj.FieldNinStringMapPointer, []string{"a", "b", "c"})) { +errs = append(errs, types.NewValidationError("FieldNinStringMapPointer elements must not be one of 'a' 'b' 'c'")) +} +`, + }, + { + name: "nin_intmappointer_nin=1 2 3", + args: args{ + fieldName: "FieldNinIntMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(obj.FieldNinIntMapPointer != nil && types.MapNotContains(*obj.FieldNinIntMapPointer, []int{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinIntMapPointer elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_int8mappointer_nin=1 2 3", + args: args{ + fieldName: "FieldNinInt8MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int8", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(obj.FieldNinInt8MapPointer != nil && types.MapNotContains(*obj.FieldNinInt8MapPointer, []int8{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinInt8MapPointer elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_int16mappointer_nin=1 2 3", + args: args{ + fieldName: "FieldNinInt16MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int16", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(obj.FieldNinInt16MapPointer != nil && types.MapNotContains(*obj.FieldNinInt16MapPointer, []int16{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinInt16MapPointer elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_int32mappointer_nin=1 2 3", + args: args{ + fieldName: "FieldNinInt32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int32", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(obj.FieldNinInt32MapPointer != nil && types.MapNotContains(*obj.FieldNinInt32MapPointer, []int32{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinInt32MapPointer elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_int64mappointer_nin=1 2 3", + args: args{ + fieldName: "FieldNinInt64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "int64", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(obj.FieldNinInt64MapPointer != nil && types.MapNotContains(*obj.FieldNinInt64MapPointer, []int64{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinInt64MapPointer elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_uintmappointer_nin=1 2 3", + args: args{ + fieldName: "FieldNinUintMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(obj.FieldNinUintMapPointer != nil && types.MapNotContains(*obj.FieldNinUintMapPointer, []uint{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinUintMapPointer elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_uint8mappointer_nin=1 2 3", + args: args{ + fieldName: "FieldNinUint8MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint8", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(obj.FieldNinUint8MapPointer != nil && types.MapNotContains(*obj.FieldNinUint8MapPointer, []uint8{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinUint8MapPointer elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_uint16mappointer_nin=1 2 3", + args: args{ + fieldName: "FieldNinUint16MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint16", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(obj.FieldNinUint16MapPointer != nil && types.MapNotContains(*obj.FieldNinUint16MapPointer, []uint16{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinUint16MapPointer elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_uint32mappointer_nin=1 2 3", + args: args{ + fieldName: "FieldNinUint32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint32", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(obj.FieldNinUint32MapPointer != nil && types.MapNotContains(*obj.FieldNinUint32MapPointer, []uint32{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinUint32MapPointer elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_uint64mappointer_nin=1 2 3", + args: args{ + fieldName: "FieldNinUint64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "uint64", Size: ""}, + fieldValidation: "nin=1 2 3", + }, + want: `if !(obj.FieldNinUint64MapPointer != nil && types.MapNotContains(*obj.FieldNinUint64MapPointer, []uint64{1, 2, 3})) { +errs = append(errs, types.NewValidationError("FieldNinUint64MapPointer elements must not be one of '1' '2' '3'")) +} +`, + }, + { + name: "nin_float32mappointer_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat32MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "float32", Size: ""}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(obj.FieldNinFloat32MapPointer != nil && types.MapNotContains(*obj.FieldNinFloat32MapPointer, []float32{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldNinFloat32MapPointer elements must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_float64mappointer_nin=11.11 22.22 33.33", + args: args{ + fieldName: "FieldNinFloat64MapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "float64", Size: ""}, + fieldValidation: "nin=11.11 22.22 33.33", + }, + want: `if !(obj.FieldNinFloat64MapPointer != nil && types.MapNotContains(*obj.FieldNinFloat64MapPointer, []float64{11.11, 22.22, 33.33})) { +errs = append(errs, types.NewValidationError("FieldNinFloat64MapPointer elements must not be one of '11.11' '22.22' '33.33'")) +} +`, + }, + { + name: "nin_boolmappointer_nin=false", + args: args{ + fieldName: "FieldNinBoolMapPointer", + fieldType: common.FieldType{ComposedType: "*map", BaseType: "bool", Size: ""}, + fieldValidation: "nin=false", + }, + want: `if !(obj.FieldNinBoolMapPointer != nil && types.MapNotContains(*obj.FieldNinBoolMapPointer, []bool{false})) { +errs = append(errs, types.NewValidationError("FieldNinBoolMapPointer elements must not be one of 'false'")) +} +`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gv := GenValidations{} + validation := AssertParserValidation(t, tt.args.fieldValidation) + got, err := gv.BuildValidationCode(tt.args.fieldName, tt.args.fieldType, []*analyzer.Validation{validation}) + if err != nil { + t.Errorf("BuildValidationCode() error = %v, wantErr %v", err, nil) + return + } + if got != tt.want { + t.Errorf("BuildValidationCode() = %v, want %v", got, tt.want) + } + }) + } +} From 581fa9a3edda74e0786f015153e238424f059b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=2E=20Garz=C3=A3o?= Date: Sun, 26 Oct 2025 13:07:21 -0300 Subject: [PATCH 06/11] chore: makefile rule to build generated tests and move to the correct path --- Makefile | 7 +++++-- ...ter_tests.go => generated_endtoend_no_pointer_tests.go} | 0 ...ointer_tests.go => generated_endtoend_pointer_tests.go} | 0 3 files changed, 5 insertions(+), 2 deletions(-) rename tests/endtoend/{generated_no_pointer_tests.go => generated_endtoend_no_pointer_tests.go} (100%) rename tests/endtoend/{generated_pointer_tests.go => generated_endtoend_pointer_tests.go} (100%) diff --git a/Makefile b/Makefile index d0b36e5..c85b537 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: clean unittests benchtests build endtoendtests cmpbenchtests +.PHONY: clean unittests benchtests build endtoendtests cmpbenchtests testgen setup lint BIN_DIR=bin BIN_NAME=validgen @@ -29,10 +29,13 @@ build: clean @echo "Building" go build -o $(VALIDGEN_BIN) . +testgen: + @echo "Generating tests" + cd testgen/; rm -f generated_*.go; go run *.go; mv generated_endtoend_*tests.go ../tests/endtoend/; mv generated_validation_*_test.go ../internal/codegenerator/ + endtoendtests: build @echo "Running endtoend tests" find tests/endtoend/ -name 'validator__.go' -exec rm \{} \; - cd tests/endtoend/generate_tests/; rm -f generated*tests.go; go run *.go; mv generated*tests.go .. $(VALIDGEN_BIN) tests/endtoend cd tests/endtoend; go run . diff --git a/tests/endtoend/generated_no_pointer_tests.go b/tests/endtoend/generated_endtoend_no_pointer_tests.go similarity index 100% rename from tests/endtoend/generated_no_pointer_tests.go rename to tests/endtoend/generated_endtoend_no_pointer_tests.go diff --git a/tests/endtoend/generated_pointer_tests.go b/tests/endtoend/generated_endtoend_pointer_tests.go similarity index 100% rename from tests/endtoend/generated_pointer_tests.go rename to tests/endtoend/generated_endtoend_pointer_tests.go From 98b323abf1d8018a6844f1c246d2a86e11ef10a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=2E=20Garz=C3=A3o?= Date: Sun, 26 Oct 2025 19:14:13 -0300 Subject: [PATCH 07/11] chore: add DO NOT EDIT to all templates --- .../codegenerator/generated_validation_code_no_pointer_test.go | 2 ++ .../codegenerator/generated_validation_code_pointer_test.go | 2 ++ testgen/build_validation_code_test.tpl | 2 ++ 3 files changed, 6 insertions(+) diff --git a/internal/codegenerator/generated_validation_code_no_pointer_test.go b/internal/codegenerator/generated_validation_code_no_pointer_test.go index ed605a7..7920045 100644 --- a/internal/codegenerator/generated_validation_code_no_pointer_test.go +++ b/internal/codegenerator/generated_validation_code_no_pointer_test.go @@ -1,3 +1,5 @@ +// Code generated by TestGen. DO NOT EDIT. + package codegenerator import ( diff --git a/internal/codegenerator/generated_validation_code_pointer_test.go b/internal/codegenerator/generated_validation_code_pointer_test.go index 2ac92e6..6fa3895 100644 --- a/internal/codegenerator/generated_validation_code_pointer_test.go +++ b/internal/codegenerator/generated_validation_code_pointer_test.go @@ -1,3 +1,5 @@ +// Code generated by TestGen. DO NOT EDIT. + package codegenerator import ( diff --git a/testgen/build_validation_code_test.tpl b/testgen/build_validation_code_test.tpl index c80c514..2068329 100644 --- a/testgen/build_validation_code_test.tpl +++ b/testgen/build_validation_code_test.tpl @@ -1,3 +1,5 @@ +// Code generated by TestGen. DO NOT EDIT. + package codegenerator import ( From 55919422fa2b9f59ded95ad9e9d1a55a9cb375f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=2E=20Garz=C3=A3o?= Date: Sun, 26 Oct 2025 19:16:25 -0300 Subject: [PATCH 08/11] chore: fix DO NOT EDIT header --- testgen/no_pointer_tests.tpl | 2 +- testgen/pointer_tests.tpl | 2 +- tests/endtoend/generated_endtoend_no_pointer_tests.go | 2 +- tests/endtoend/generated_endtoend_pointer_tests.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/testgen/no_pointer_tests.tpl b/testgen/no_pointer_tests.tpl index 8badfdf..4686e3d 100644 --- a/testgen/no_pointer_tests.tpl +++ b/testgen/no_pointer_tests.tpl @@ -1,4 +1,4 @@ -// Code generated by TestGenerator. DO NOT EDIT. +// Code generated by TestGen. DO NOT EDIT. package main diff --git a/testgen/pointer_tests.tpl b/testgen/pointer_tests.tpl index 6528758..d67bddc 100644 --- a/testgen/pointer_tests.tpl +++ b/testgen/pointer_tests.tpl @@ -1,4 +1,4 @@ -// Code generated by TestGenerator. DO NOT EDIT. +// Code generated by TestGen. DO NOT EDIT. package main diff --git a/tests/endtoend/generated_endtoend_no_pointer_tests.go b/tests/endtoend/generated_endtoend_no_pointer_tests.go index cc8c5b6..30d6531 100644 --- a/tests/endtoend/generated_endtoend_no_pointer_tests.go +++ b/tests/endtoend/generated_endtoend_no_pointer_tests.go @@ -1,4 +1,4 @@ -// Code generated by TestGenerator. DO NOT EDIT. +// Code generated by TestGen. DO NOT EDIT. package main diff --git a/tests/endtoend/generated_endtoend_pointer_tests.go b/tests/endtoend/generated_endtoend_pointer_tests.go index 778456c..fadd056 100644 --- a/tests/endtoend/generated_endtoend_pointer_tests.go +++ b/tests/endtoend/generated_endtoend_pointer_tests.go @@ -1,4 +1,4 @@ -// Code generated by TestGenerator. DO NOT EDIT. +// Code generated by TestGen. DO NOT EDIT. package main From 47d14f65f5daecba937f3736ce85a90ca962d376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=2E=20Garz=C3=A3o?= Date: Sun, 26 Oct 2025 19:17:34 -0300 Subject: [PATCH 09/11] chore: better func name --- testgen/generate_validation_code_tests.go | 2 +- testgen/generate_validation_types_tests.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/testgen/generate_validation_code_tests.go b/testgen/generate_validation_code_tests.go index 6eadbcc..44531a3 100644 --- a/testgen/generate_validation_code_tests.go +++ b/testgen/generate_validation_code_tests.go @@ -28,7 +28,7 @@ type ValidationCodeTestCase struct { ExpectedCode string } -func generateValidationCodeTests() { +func generateValidationCodeUnitTests() { generateValidationCodeTestsFile("build_validation_code_test.tpl", "generated_validation_code_no_pointer_test.go", false) generateValidationCodeTestsFile("build_validation_code_test.tpl", "generated_validation_code_pointer_test.go", true) } diff --git a/testgen/generate_validation_types_tests.go b/testgen/generate_validation_types_tests.go index 3c84647..3984617 100644 --- a/testgen/generate_validation_types_tests.go +++ b/testgen/generate_validation_types_tests.go @@ -33,7 +33,7 @@ type TestCase struct { ErrorMessage string } -func generateValidationTypesTests() { +func generateValidationTypesEndToEndTests() { generateValidationTypesTestsFile("no_pointer_tests.tpl", "generated_endtoend_no_pointer_tests.go", false) generateValidationTypesTestsFile("pointer_tests.tpl", "generated_endtoend_pointer_tests.go", true) } @@ -100,7 +100,7 @@ func generateValidationTypesTestsFile(tpl, dest string, pointer bool) { log.Printf("Generating %s done\n", dest) } -func (at *AllTestCasesToGenerate) GenerateFile(tplFile, output string) error { +func (tc *AllTestCasesToGenerate) GenerateFile(tplFile, output string) error { tpl, err := os.ReadFile(tplFile) if err != nil { return fmt.Errorf("error reading %s: %s", tplFile, err) @@ -112,7 +112,7 @@ func (at *AllTestCasesToGenerate) GenerateFile(tplFile, output string) error { } code := new(bytes.Buffer) - if err := tmpl.Execute(code, at); err != nil { + if err := tmpl.Execute(code, tc); err != nil { return err } From 64050faec10930da585103e794407993ae35fa2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=2E=20Garz=C3=A3o?= Date: Mon, 27 Oct 2025 15:30:55 -0300 Subject: [PATCH 10/11] doc: initial testgen readme --- testgen/README.md | 119 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 testgen/README.md diff --git a/testgen/README.md b/testgen/README.md new file mode 100644 index 0000000..b101ed1 --- /dev/null +++ b/testgen/README.md @@ -0,0 +1,119 @@ +# TestGen + +TestGen is the tool responsible for generating tests related to ValidGen validators and supported types. +These generated tests included unit tests, end-to-end tests, and benchmark tests. +In the case of benchmark tests, it means comparing ValidGen and GoValidator. + +## Why a new tool? + +First of all, it is necessary to answer the question: why a new tool to generate tests? + +Currently, ValidGen has 21 possible validations with support for some types: + +| Validation | Basic types | Slice | Array | Map | +| - | - | - | - | - | +| eq | STRING INT FLOAT BOOL | | | | +| required | STRING INT FLOAT BOOL | STRING INT FLOAT BOOL | | STRING INT FLOAT BOOL | +| gt | INT FLOAT | | | | +| gte | INT FLOAT | | | | +| lte | INT FLOAT | | | | +| lt | INT FLOAT | | | | +| min | STRING | STRING INT FLOAT BOOL | | STRING INT FLOAT BOOL | +| max | STRING | STRING INT FLOAT BOOL | | STRING INT FLOAT BOOL | +| eq_ignore_case | STRING | | | | +| len | STRING | STRING INT FLOAT BOOL | | STRING INT FLOAT BOOL | +| neq | STRING INT FLOAT BOOL | | | | +| neq_ignore_case | STRING | | | | +| in | STRING INT FLOAT BOOL | STRING INT FLOAT BOOL | STRING INT FLOAT BOOL | STRING INT FLOAT BOOL | +| nin | STRING INT FLOAT BOOL | STRING INT FLOAT BOOL | STRING INT FLOAT BOOL | STRING INT FLOAT BOOL | +| email | STRING | | | | +| eqfield | STRING INT BOOL | | | | +| neqfield | STRING INT BOOL | | | | +| gtefield | INT | | | | +| gtfield | INT | | | | +| ltefield | INT | | | | +| ltfield | INT | | | | + +In this table, STRING represents the string Go type, and BOOL represents the bool Go type. +But INT represents the ten integer Go types: int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64. +In the same way, FLOAT represents the 2 float go types: float32, float64. +In the same way, slice STRING is just []string, but slice INT is split between all integer Go types. +For array and map, the rule is the same. +And, an important modifier is "*" (pointer) because the code generated is different with or without a pointer. + +For each possible combination (validation x type) is necessary to have the following tests: +- Unit test in the analyzer phase +- Unit test in the code generator phase +- Benchmark test between ValidGen and GoValidator +- End-to-end test + +As it is necessary to test all valid and invalid scenarios, it is necessary to test all validations against all types. +At this time, it means: +- Go types (14) +- Validations (21) +- Test types (4) +- Types with and without a pointer (2) +- Tests with valid and invalid inputs (2) + +14 x 21 x 4 x 2 x 2 = 4.704 distinct test cases :-) + +With all the tests that need to be created (valid inputs, invalid inputs) for unit tests, benchmark, and end-to-end tests, creating the tests "by hand" is a tedious and error-prone task. + +Some of these necessary unit tests were created "by hand", but it is a pain to keep the code in sync when supporting new operations and types. + +At this time, ValidGen already has two generators: +- To generate benchmark tests between ValidGen and GoValidator +- To generate end-to-end tests + - to validate ValidGen with integer types + - to validate ValidGen with float types + - to validate all possible use cases in ValidGen (all validations x all types) + +But these generators do not have a common configuration, do not implement all tests for all cases, and keeping the distinct configuration files in sync is painful. + +Beyond that, some new generators could be created: +- Unit tests to validate operations +- Unit tests to validate operation x type +- Unit tests to validate the "buildValidationCode" function +- Unit tests to validate the "condition table" +- Parser tests +- Almost all existing end-to-end tests could be generated +- Examples (in _examples/) could be generated + +And, for all cases, valid scenarios and invalid scenarios must be generated. + +## What TestGen does + +TestGen generates the following tests: +- Benchmark tests between ValidGen and GoValidator +- End-to-end tests with all possible use cases (all validations vs all types vs valid and invalid inputs) +- Unit tests to validate operations +- Unit tests to validate operation vs type +- Unit tests to validate the "buildValidationCode" function +- Unit tests to validate "condition table" result +- Parser tests (parser_tests.go) +- Examples (in _examples/) + +In some cases, valid scenarios and invalid scenarios must be generated. + +## How TestGen works + +To be possible to generate all these tests, TestGen must have a configuration with: +- All valid operations +- All valid go types +- All valid operation x type +- Valid input cases for each operation x type +- Invalid input cases for each operation x type +- Equivalent GoValidator tag + +## Steps to generate the tests + +The steps to generate the tests are: + +```bash +# Enter in the project root folder +cd validgen + +# Run testgen +make testgen +``` + From 2ee054c9ed6b31f0d2d55714a17c6636717f21db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=2E=20Garz=C3=A3o?= Date: Mon, 27 Oct 2025 15:38:57 -0300 Subject: [PATCH 11/11] chore: remove useless code --- testgen/generate_validation_types_tests.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/testgen/generate_validation_types_tests.go b/testgen/generate_validation_types_tests.go index 3984617..f848725 100644 --- a/testgen/generate_validation_types_tests.go +++ b/testgen/generate_validation_types_tests.go @@ -116,10 +116,6 @@ func (tc *AllTestCasesToGenerate) GenerateFile(tplFile, output string) error { return err } - // if err := os.WriteFile(output, code.Bytes(), 0644); err != nil { - // return err - // } - formattedCode, err := format.Source(code.Bytes()) if err != nil { return err