Segregate base code generation logic to a new package (#31)
This commit is contained in:
parent
737c1a4044
commit
ec08a5a918
22 changed files with 1761 additions and 937 deletions
internal/spec
|
@ -44,7 +44,7 @@ func TestError(t *testing.T) {
|
|||
Name: "IncompatibleComparatorError",
|
||||
Error: spec.NewIncompatibleComparatorError(spec.ComparatorTrue, code.StructField{
|
||||
Name: "Age",
|
||||
Type: code.SimpleType("int"),
|
||||
Type: code.TypeInt,
|
||||
}),
|
||||
ExpectedString: "cannot use comparator EQUAL_TRUE with struct field 'Age' of type 'int'",
|
||||
},
|
||||
|
@ -55,7 +55,7 @@ func TestError(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Name: "ArgumentTypeNotMatchedError",
|
||||
Error: spec.NewArgumentTypeNotMatchedError("Age", code.SimpleType("int"), code.SimpleType("float64")),
|
||||
Error: spec.NewArgumentTypeNotMatchedError("Age", code.TypeInt, code.TypeFloat64),
|
||||
ExpectedString: "field 'Age' requires an argument of type 'int' (got 'float64')",
|
||||
},
|
||||
{
|
||||
|
@ -63,7 +63,7 @@ func TestError(t *testing.T) {
|
|||
Error: spec.NewIncompatibleUpdateOperatorError(spec.UpdateOperatorInc, spec.FieldReference{
|
||||
code.StructField{
|
||||
Name: "City",
|
||||
Type: code.SimpleType("string"),
|
||||
Type: code.TypeString,
|
||||
},
|
||||
}),
|
||||
ExpectedString: "cannot use update operator INC with struct field 'City' of type 'string'",
|
||||
|
|
|
@ -85,7 +85,7 @@ func (p interfaceMethodParser) extractInsertReturns(returns []code.Type) (QueryM
|
|||
return "", NewOperationReturnCountUnmatchedError(2)
|
||||
}
|
||||
|
||||
if returns[1] != code.SimpleType("error") {
|
||||
if returns[1] != code.TypeError {
|
||||
return "", NewUnsupportedReturnError(returns[1], 1)
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ func (p interfaceMethodParser) extractModelOrSliceReturns(returns []code.Type) (
|
|||
return "", NewOperationReturnCountUnmatchedError(2)
|
||||
}
|
||||
|
||||
if returns[1] != code.SimpleType("error") {
|
||||
if returns[1] != code.TypeError {
|
||||
return "", NewUnsupportedReturnError(returns[1], 1)
|
||||
}
|
||||
|
||||
|
@ -318,11 +318,11 @@ func (p interfaceMethodParser) validateCountReturns(returns []code.Type) error {
|
|||
return NewOperationReturnCountUnmatchedError(2)
|
||||
}
|
||||
|
||||
if returns[0] != code.SimpleType("int") {
|
||||
if returns[0] != code.TypeInt {
|
||||
return NewUnsupportedReturnError(returns[0], 0)
|
||||
}
|
||||
|
||||
if returns[1] != code.SimpleType("error") {
|
||||
if returns[1] != code.TypeError {
|
||||
return NewUnsupportedReturnError(returns[1], 1)
|
||||
}
|
||||
|
||||
|
@ -334,16 +334,16 @@ func (p interfaceMethodParser) extractIntOrBoolReturns(returns []code.Type) (Que
|
|||
return "", NewOperationReturnCountUnmatchedError(2)
|
||||
}
|
||||
|
||||
if returns[1] != code.SimpleType("error") {
|
||||
if returns[1] != code.TypeError {
|
||||
return "", NewUnsupportedReturnError(returns[1], 1)
|
||||
}
|
||||
|
||||
simpleType, ok := returns[0].(code.SimpleType)
|
||||
if ok {
|
||||
if simpleType == code.SimpleType("bool") {
|
||||
if simpleType == code.TypeBool {
|
||||
return QueryModeOne, nil
|
||||
}
|
||||
if simpleType == code.SimpleType("int") {
|
||||
if simpleType == code.TypeInt {
|
||||
return QueryModeMany, nil
|
||||
}
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ func (p interfaceMethodParser) validateQueryFromParams(params []code.Param, quer
|
|||
var currentParamIndex int
|
||||
for _, predicate := range querySpec.Predicates {
|
||||
if (predicate.Comparator == ComparatorTrue || predicate.Comparator == ComparatorFalse) &&
|
||||
predicate.FieldReference.ReferencedField().Type != code.SimpleType("bool") {
|
||||
predicate.FieldReference.ReferencedField().Type != code.TypeBool {
|
||||
return NewIncompatibleComparatorError(predicate.Comparator,
|
||||
predicate.FieldReference.ReferencedField())
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue