mirror of
https://github.com/aclindsa/ofxgo.git
synced 2024-10-30 05:20:05 -04:00
constants: Improve testing, eliminate redundant check when marshalling
This commit is contained in:
parent
ac5a0dce1d
commit
8f1cf63bd3
234
constants.go
234
constants.go
@ -26,6 +26,8 @@ const (
|
||||
var acctTypes = [...]string{"CHECKING", "SAVINGS", "MONEYMRKT", "CREDITLINE", "CD"}
|
||||
|
||||
func (e acctType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= AcctTypeChecking && e <= AcctTypeCD
|
||||
}
|
||||
|
||||
@ -60,10 +62,8 @@ func (e *acctType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *acctType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid AcctType")
|
||||
}
|
||||
enc.EncodeElement(acctTypes[*e-1], start)
|
||||
return nil
|
||||
@ -104,6 +104,8 @@ const (
|
||||
var trnTypes = [...]string{"CREDIT", "DEBIT", "INT", "DIV", "FEE", "SRVCHG", "DEP", "ATM", "POS", "XFER", "CHECK", "PAYMENT", "CASH", "DIRECTDEP", "DIRECTDEBIT", "REPEATPMT", "HOLD", "OTHER"}
|
||||
|
||||
func (e trnType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= TrnTypeCredit && e <= TrnTypeOther
|
||||
}
|
||||
|
||||
@ -138,10 +140,8 @@ func (e *trnType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *trnType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid TrnType")
|
||||
}
|
||||
enc.EncodeElement(trnTypes[*e-1], start)
|
||||
return nil
|
||||
@ -167,6 +167,8 @@ const (
|
||||
var imageTypes = [...]string{"STATEMENT", "TRANSACTION", "TAX"}
|
||||
|
||||
func (e imageType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= ImageTypeStatement && e <= ImageTypeTax
|
||||
}
|
||||
|
||||
@ -201,10 +203,8 @@ func (e *imageType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *imageType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid ImageType")
|
||||
}
|
||||
enc.EncodeElement(imageTypes[*e-1], start)
|
||||
return nil
|
||||
@ -230,6 +230,8 @@ const (
|
||||
var imageRefTypes = [...]string{"OPAQUE", "URL", "FORMURL"}
|
||||
|
||||
func (e imageRefType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= ImageRefTypeOpaque && e <= ImageRefTypeFormURL
|
||||
}
|
||||
|
||||
@ -264,10 +266,8 @@ func (e *imageRefType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) erro
|
||||
}
|
||||
|
||||
func (e *imageRefType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid ImageRefType")
|
||||
}
|
||||
enc.EncodeElement(imageRefTypes[*e-1], start)
|
||||
return nil
|
||||
@ -293,6 +293,8 @@ const (
|
||||
var checkSups = [...]string{"FRONTONLY", "BACKONLY", "FRONTANDBACK"}
|
||||
|
||||
func (e checkSup) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= CheckSupFrontOnly && e <= CheckSupFrontAndBack
|
||||
}
|
||||
|
||||
@ -327,10 +329,8 @@ func (e *checkSup) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *checkSup) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid CheckSup")
|
||||
}
|
||||
enc.EncodeElement(checkSups[*e-1], start)
|
||||
return nil
|
||||
@ -355,6 +355,8 @@ const (
|
||||
var correctActions = [...]string{"DELETE", "REPLACE"}
|
||||
|
||||
func (e correctAction) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= CorrectActionDelete && e <= CorrectActionReplace
|
||||
}
|
||||
|
||||
@ -389,10 +391,8 @@ func (e *correctAction) UnmarshalXML(d *xml.Decoder, start xml.StartElement) err
|
||||
}
|
||||
|
||||
func (e *correctAction) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid CorrectAction")
|
||||
}
|
||||
enc.EncodeElement(correctActions[*e-1], start)
|
||||
return nil
|
||||
@ -418,6 +418,8 @@ const (
|
||||
var balTypes = [...]string{"DOLLAR", "PERCENT", "NUMBER"}
|
||||
|
||||
func (e balType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= BalTypeDollar && e <= BalTypeNumber
|
||||
}
|
||||
|
||||
@ -452,10 +454,8 @@ func (e *balType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *balType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid BalType")
|
||||
}
|
||||
enc.EncodeElement(balTypes[*e-1], start)
|
||||
return nil
|
||||
@ -485,6 +485,8 @@ const (
|
||||
var inv401kSources = [...]string{"PRETAX", "AFTERTAX", "MATCH", "PROFITSHARING", "ROLLOVER", "OTHERVEST", "OTHERNONVEST"}
|
||||
|
||||
func (e inv401kSource) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= Inv401kSourcePreTax && e <= Inv401kSourceOtherNonVest
|
||||
}
|
||||
|
||||
@ -519,10 +521,8 @@ func (e *inv401kSource) UnmarshalXML(d *xml.Decoder, start xml.StartElement) err
|
||||
}
|
||||
|
||||
func (e *inv401kSource) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid Inv401kSource")
|
||||
}
|
||||
enc.EncodeElement(inv401kSources[*e-1], start)
|
||||
return nil
|
||||
@ -549,6 +549,8 @@ const (
|
||||
var subAcctTypes = [...]string{"CASH", "MARGIN", "SHORT", "OTHER"}
|
||||
|
||||
func (e subAcctType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= SubAcctTypeCash && e <= SubAcctTypeOther
|
||||
}
|
||||
|
||||
@ -583,10 +585,8 @@ func (e *subAcctType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
}
|
||||
|
||||
func (e *subAcctType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid SubAcctType")
|
||||
}
|
||||
enc.EncodeElement(subAcctTypes[*e-1], start)
|
||||
return nil
|
||||
@ -611,6 +611,8 @@ const (
|
||||
var buyTypes = [...]string{"BUY", "BUYTOCOVER"}
|
||||
|
||||
func (e buyType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= BuyTypeBuy && e <= BuyTypeBuyToCover
|
||||
}
|
||||
|
||||
@ -645,10 +647,8 @@ func (e *buyType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *buyType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid BuyType")
|
||||
}
|
||||
enc.EncodeElement(buyTypes[*e-1], start)
|
||||
return nil
|
||||
@ -674,6 +674,8 @@ const (
|
||||
var optActions = [...]string{"EXERCISE", "ASSIGN", "EXPIRE"}
|
||||
|
||||
func (e optAction) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= OptActionExercise && e <= OptActionExpire
|
||||
}
|
||||
|
||||
@ -708,10 +710,8 @@ func (e *optAction) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *optAction) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid OptAction")
|
||||
}
|
||||
enc.EncodeElement(optActions[*e-1], start)
|
||||
return nil
|
||||
@ -736,6 +736,8 @@ const (
|
||||
var tferActions = [...]string{"IN", "OUT"}
|
||||
|
||||
func (e tferAction) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= TferActionIn && e <= TferActionOut
|
||||
}
|
||||
|
||||
@ -770,10 +772,8 @@ func (e *tferAction) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
}
|
||||
|
||||
func (e *tferAction) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid TferAction")
|
||||
}
|
||||
enc.EncodeElement(tferActions[*e-1], start)
|
||||
return nil
|
||||
@ -798,6 +798,8 @@ const (
|
||||
var posTypes = [...]string{"LONG", "SHORT"}
|
||||
|
||||
func (e posType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= PosTypeLong && e <= PosTypeShort
|
||||
}
|
||||
|
||||
@ -832,10 +834,8 @@ func (e *posType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *posType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid PosType")
|
||||
}
|
||||
enc.EncodeElement(posTypes[*e-1], start)
|
||||
return nil
|
||||
@ -860,6 +860,8 @@ const (
|
||||
var secureds = [...]string{"NAKED", "COVERED"}
|
||||
|
||||
func (e secured) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= SecuredNaked && e <= SecuredCovered
|
||||
}
|
||||
|
||||
@ -894,10 +896,8 @@ func (e *secured) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *secured) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid Secured")
|
||||
}
|
||||
enc.EncodeElement(secureds[*e-1], start)
|
||||
return nil
|
||||
@ -923,6 +923,8 @@ const (
|
||||
var durations = [...]string{"DAY", "GOODTILCANCEL", "IMMEDIATE"}
|
||||
|
||||
func (e duration) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= DurationDay && e <= DurationImmediate
|
||||
}
|
||||
|
||||
@ -957,10 +959,8 @@ func (e *duration) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *duration) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid Duration")
|
||||
}
|
||||
enc.EncodeElement(durations[*e-1], start)
|
||||
return nil
|
||||
@ -986,6 +986,8 @@ const (
|
||||
var restrictions = [...]string{"ALLORNONE", "MINUNITS", "NONE"}
|
||||
|
||||
func (e restriction) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= RestrictionAllOrNone && e <= RestrictionNone
|
||||
}
|
||||
|
||||
@ -1020,10 +1022,8 @@ func (e *restriction) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
}
|
||||
|
||||
func (e *restriction) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid Restriction")
|
||||
}
|
||||
enc.EncodeElement(restrictions[*e-1], start)
|
||||
return nil
|
||||
@ -1048,6 +1048,8 @@ const (
|
||||
var unitTypes = [...]string{"SHARES", "CURRENCY"}
|
||||
|
||||
func (e unitType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= UnitTypeShares && e <= UnitTypeCurrency
|
||||
}
|
||||
|
||||
@ -1082,10 +1084,8 @@ func (e *unitType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *unitType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid UnitType")
|
||||
}
|
||||
enc.EncodeElement(unitTypes[*e-1], start)
|
||||
return nil
|
||||
@ -1110,6 +1110,8 @@ const (
|
||||
var optBuyTypes = [...]string{"BUYTOOPEN", "BUYTOCLOSE"}
|
||||
|
||||
func (e optBuyType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= OptBuyTypeBuyToOpen && e <= OptBuyTypeBuyToClose
|
||||
}
|
||||
|
||||
@ -1144,10 +1146,8 @@ func (e *optBuyType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
}
|
||||
|
||||
func (e *optBuyType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid OptBuyType")
|
||||
}
|
||||
enc.EncodeElement(optBuyTypes[*e-1], start)
|
||||
return nil
|
||||
@ -1172,6 +1172,8 @@ const (
|
||||
var sellTypes = [...]string{"SELL", "SELLSHORT"}
|
||||
|
||||
func (e sellType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= SellTypeSell && e <= SellTypeSellShort
|
||||
}
|
||||
|
||||
@ -1206,10 +1208,8 @@ func (e *sellType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *sellType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid SellType")
|
||||
}
|
||||
enc.EncodeElement(sellTypes[*e-1], start)
|
||||
return nil
|
||||
@ -1242,6 +1242,8 @@ const (
|
||||
var loanPmtFreqs = [...]string{"WEEKLY", "BIWEEKLY", "TWICEMONTHLY", "MONTHLY", "FOURWEEKS", "BIMONTHLY", "QUARTERLY", "SEMIANNUALLY", "ANNUALLY", "OTHER"}
|
||||
|
||||
func (e loanPmtFreq) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= LoanPmtFreqWeekly && e <= LoanPmtFreqOther
|
||||
}
|
||||
|
||||
@ -1276,10 +1278,8 @@ func (e *loanPmtFreq) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
}
|
||||
|
||||
func (e *loanPmtFreq) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid LoanPmtFreq")
|
||||
}
|
||||
enc.EncodeElement(loanPmtFreqs[*e-1], start)
|
||||
return nil
|
||||
@ -1307,6 +1307,8 @@ const (
|
||||
var incomeTypes = [...]string{"CGLONG", "CGSHORT", "DIV", "INTEREST", "MISC"}
|
||||
|
||||
func (e incomeType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= IncomeTypeCGLong && e <= IncomeTypeMisc
|
||||
}
|
||||
|
||||
@ -1341,10 +1343,8 @@ func (e *incomeType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
}
|
||||
|
||||
func (e *incomeType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid IncomeType")
|
||||
}
|
||||
enc.EncodeElement(incomeTypes[*e-1], start)
|
||||
return nil
|
||||
@ -1370,6 +1370,8 @@ const (
|
||||
var sellReasons = [...]string{"CALL", "SELL", "MATURITY"}
|
||||
|
||||
func (e sellReason) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= SellReasonCall && e <= SellReasonMaturity
|
||||
}
|
||||
|
||||
@ -1404,10 +1406,8 @@ func (e *sellReason) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
}
|
||||
|
||||
func (e *sellReason) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid SellReason")
|
||||
}
|
||||
enc.EncodeElement(sellReasons[*e-1], start)
|
||||
return nil
|
||||
@ -1432,6 +1432,8 @@ const (
|
||||
var optSellTypes = [...]string{"SELLTOCLOSE", "SELLTOOPEN"}
|
||||
|
||||
func (e optSellType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= OptSellTypeSellToClose && e <= OptSellTypeSellToOpen
|
||||
}
|
||||
|
||||
@ -1466,10 +1468,8 @@ func (e *optSellType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
}
|
||||
|
||||
func (e *optSellType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid OptSellType")
|
||||
}
|
||||
enc.EncodeElement(optSellTypes[*e-1], start)
|
||||
return nil
|
||||
@ -1496,6 +1496,8 @@ const (
|
||||
var relTypes = [...]string{"SPREAD", "STRADDLE", "NONE", "OTHER"}
|
||||
|
||||
func (e relType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= RelTypeSpread && e <= RelTypeOther
|
||||
}
|
||||
|
||||
@ -1530,10 +1532,8 @@ func (e *relType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *relType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid RelType")
|
||||
}
|
||||
enc.EncodeElement(relTypes[*e-1], start)
|
||||
return nil
|
||||
@ -1560,6 +1560,8 @@ const (
|
||||
var charTypes = [...]string{"ALPHAONLY", "NUMERICONLY", "ALPHAORNUMERIC", "ALPHAANDNUMERIC"}
|
||||
|
||||
func (e charType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= CharTypeAlphaOnly && e <= CharTypeAlphaAndNumeric
|
||||
}
|
||||
|
||||
@ -1594,10 +1596,8 @@ func (e *charType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *charType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid CharType")
|
||||
}
|
||||
enc.EncodeElement(charTypes[*e-1], start)
|
||||
return nil
|
||||
@ -1622,6 +1622,8 @@ const (
|
||||
var syncModes = [...]string{"FULL", "LITE"}
|
||||
|
||||
func (e syncMode) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= SyncModeFull && e <= SyncModeLite
|
||||
}
|
||||
|
||||
@ -1656,10 +1658,8 @@ func (e *syncMode) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *syncMode) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid SyncMode")
|
||||
}
|
||||
enc.EncodeElement(syncModes[*e-1], start)
|
||||
return nil
|
||||
@ -1684,6 +1684,8 @@ const (
|
||||
var debtTypes = [...]string{"COUPON", "ZERO"}
|
||||
|
||||
func (e debtType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= DebtTypeCoupon && e <= DebtTypeZero
|
||||
}
|
||||
|
||||
@ -1718,10 +1720,8 @@ func (e *debtType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *debtType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid DebtType")
|
||||
}
|
||||
enc.EncodeElement(debtTypes[*e-1], start)
|
||||
return nil
|
||||
@ -1748,6 +1748,8 @@ const (
|
||||
var debtClasss = [...]string{"TREASURY", "MUNICIPAL", "CORPORATE", "OTHER"}
|
||||
|
||||
func (e debtClass) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= DebtClassTreasury && e <= DebtClassOther
|
||||
}
|
||||
|
||||
@ -1782,10 +1784,8 @@ func (e *debtClass) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *debtClass) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid DebtClass")
|
||||
}
|
||||
enc.EncodeElement(debtClasss[*e-1], start)
|
||||
return nil
|
||||
@ -1813,6 +1813,8 @@ const (
|
||||
var couponFreqs = [...]string{"MONTHLY", "QUARTERLY", "SEMIANNUAL", "ANNUAL", "OTHER"}
|
||||
|
||||
func (e couponFreq) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= CouponFreqMonthly && e <= CouponFreqOther
|
||||
}
|
||||
|
||||
@ -1847,10 +1849,8 @@ func (e *couponFreq) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
}
|
||||
|
||||
func (e *couponFreq) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid CouponFreq")
|
||||
}
|
||||
enc.EncodeElement(couponFreqs[*e-1], start)
|
||||
return nil
|
||||
@ -1877,6 +1877,8 @@ const (
|
||||
var callTypes = [...]string{"CALL", "PUT", "PREFUND", "MATURITY"}
|
||||
|
||||
func (e callType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= CallTypeCall && e <= CallTypeMaturity
|
||||
}
|
||||
|
||||
@ -1911,10 +1913,8 @@ func (e *callType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *callType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid CallType")
|
||||
}
|
||||
enc.EncodeElement(callTypes[*e-1], start)
|
||||
return nil
|
||||
@ -1944,6 +1944,8 @@ const (
|
||||
var assetClasss = [...]string{"DOMESTICBOND", "INTLBOND", "LARGESTOCK", "SMALLSTOCK", "INTLSTOCK", "MONEYMRKT", "OTHER"}
|
||||
|
||||
func (e assetClass) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= AssetClassDomesticBond && e <= AssetClassOther
|
||||
}
|
||||
|
||||
@ -1978,10 +1980,8 @@ func (e *assetClass) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
}
|
||||
|
||||
func (e *assetClass) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid AssetClass")
|
||||
}
|
||||
enc.EncodeElement(assetClasss[*e-1], start)
|
||||
return nil
|
||||
@ -2007,6 +2007,8 @@ const (
|
||||
var mfTypes = [...]string{"OPENEND", "CLOSEEND", "OTHER"}
|
||||
|
||||
func (e mfType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= MfTypeOpenEnd && e <= MfTypeOther
|
||||
}
|
||||
|
||||
@ -2041,10 +2043,8 @@ func (e *mfType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *mfType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid MfType")
|
||||
}
|
||||
enc.EncodeElement(mfTypes[*e-1], start)
|
||||
return nil
|
||||
@ -2069,6 +2069,8 @@ const (
|
||||
var optTypes = [...]string{"PUT", "CALL"}
|
||||
|
||||
func (e optType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= OptTypePut && e <= OptTypeCall
|
||||
}
|
||||
|
||||
@ -2103,10 +2105,8 @@ func (e *optType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *optType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid OptType")
|
||||
}
|
||||
enc.EncodeElement(optTypes[*e-1], start)
|
||||
return nil
|
||||
@ -2133,6 +2133,8 @@ const (
|
||||
var stockTypes = [...]string{"COMMON", "PREFERRED", "CONVERTIBLE", "OTHER"}
|
||||
|
||||
func (e stockType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= StockTypeCommon && e <= StockTypeOther
|
||||
}
|
||||
|
||||
@ -2167,10 +2169,8 @@ func (e *stockType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *stockType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid StockType")
|
||||
}
|
||||
enc.EncodeElement(stockTypes[*e-1], start)
|
||||
return nil
|
||||
@ -2195,6 +2195,8 @@ const (
|
||||
var ofxSecs = [...]string{"NONE", "TYPE 1"}
|
||||
|
||||
func (e ofxSec) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= OfxSecNone && e <= OfxSecType1
|
||||
}
|
||||
|
||||
@ -2229,10 +2231,8 @@ func (e *ofxSec) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *ofxSec) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid OfxSec")
|
||||
}
|
||||
enc.EncodeElement(ofxSecs[*e-1], start)
|
||||
return nil
|
||||
@ -2260,6 +2260,8 @@ const (
|
||||
var holderTypes = [...]string{"INDIVIDUAL", "JOINT", "CUSTODIAL", "TRUST", "OTHER"}
|
||||
|
||||
func (e holderType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= HolderTypeIndividual && e <= HolderTypeOther
|
||||
}
|
||||
|
||||
@ -2294,10 +2296,8 @@ func (e *holderType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
}
|
||||
|
||||
func (e *holderType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid HolderType")
|
||||
}
|
||||
enc.EncodeElement(holderTypes[*e-1], start)
|
||||
return nil
|
||||
@ -2324,6 +2324,8 @@ const (
|
||||
var acctClassifications = [...]string{"PERSONAL", "BUSINESS", "CORPORATE", "OTHER"}
|
||||
|
||||
func (e acctClassification) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= AcctClassificationPersonal && e <= AcctClassificationOther
|
||||
}
|
||||
|
||||
@ -2358,10 +2360,8 @@ func (e *acctClassification) UnmarshalXML(d *xml.Decoder, start xml.StartElement
|
||||
}
|
||||
|
||||
func (e *acctClassification) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid AcctClassification")
|
||||
}
|
||||
enc.EncodeElement(acctClassifications[*e-1], start)
|
||||
return nil
|
||||
@ -2387,6 +2387,8 @@ const (
|
||||
var svcStatuss = [...]string{"AVAIL", "PEND", "ACTIVE"}
|
||||
|
||||
func (e svcStatus) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= SvcStatusAvail && e <= SvcStatusActive
|
||||
}
|
||||
|
||||
@ -2421,10 +2423,8 @@ func (e *svcStatus) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
}
|
||||
|
||||
func (e *svcStatus) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid SvcStatus")
|
||||
}
|
||||
enc.EncodeElement(svcStatuss[*e-1], start)
|
||||
return nil
|
||||
@ -2458,6 +2458,8 @@ const (
|
||||
var usProductTypes = [...]string{"401K", "403B", "IRA", "KEOGH", "OTHER", "SARSEP", "SIMPLE", "NORMAL", "TDA", "TRUST", "UGMA"}
|
||||
|
||||
func (e usProductType) Valid() bool {
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= UsProductType401K && e <= UsProductTypeUGMA
|
||||
}
|
||||
|
||||
@ -2492,10 +2494,8 @@ func (e *usProductType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) err
|
||||
}
|
||||
|
||||
func (e *usProductType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
|
||||
if *e == 0 {
|
||||
if !e.Valid() {
|
||||
return nil
|
||||
} else if !e.Valid() {
|
||||
return errors.New("Invalid UsProductType")
|
||||
}
|
||||
enc.EncodeElement(usProductTypes[*e-1], start)
|
||||
return nil
|
||||
|
@ -9,6 +9,7 @@ package ofxgo_test
|
||||
import (
|
||||
"github.com/aclindsa/go/src/encoding/xml"
|
||||
"github.com/aclindsa/ofxgo"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -37,6 +38,9 @@ func TestAcctType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("AcctType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("AcctType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -47,6 +51,11 @@ func TestAcctType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "CD", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrnType(t *testing.T) {
|
||||
@ -74,6 +83,9 @@ func TestTrnType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("TrnType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("TrnType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -84,6 +96,11 @@ func TestTrnType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OTHER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageType(t *testing.T) {
|
||||
@ -111,6 +128,9 @@ func TestImageType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("ImageType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("ImageType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -121,6 +141,11 @@ func TestImageType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "TAX", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageRefType(t *testing.T) {
|
||||
@ -148,6 +173,9 @@ func TestImageRefType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("ImageRefType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("ImageRefType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -158,6 +186,11 @@ func TestImageRefType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "FORMURL", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckSup(t *testing.T) {
|
||||
@ -185,6 +218,9 @@ func TestCheckSup(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("CheckSup created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("CheckSup created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -195,6 +231,11 @@ func TestCheckSup(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "FRONTANDBACK", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCorrectAction(t *testing.T) {
|
||||
@ -222,6 +263,9 @@ func TestCorrectAction(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("CorrectAction created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("CorrectAction created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -232,6 +276,11 @@ func TestCorrectAction(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "REPLACE", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBalType(t *testing.T) {
|
||||
@ -259,6 +308,9 @@ func TestBalType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("BalType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("BalType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -269,6 +321,11 @@ func TestBalType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "NUMBER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInv401kSource(t *testing.T) {
|
||||
@ -296,6 +353,9 @@ func TestInv401kSource(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("Inv401kSource created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("Inv401kSource created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -306,6 +366,11 @@ func TestInv401kSource(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OTHERNONVEST", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubAcctType(t *testing.T) {
|
||||
@ -333,6 +398,9 @@ func TestSubAcctType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("SubAcctType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("SubAcctType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -343,6 +411,11 @@ func TestSubAcctType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OTHER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuyType(t *testing.T) {
|
||||
@ -370,6 +443,9 @@ func TestBuyType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("BuyType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("BuyType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -380,6 +456,11 @@ func TestBuyType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "BUYTOCOVER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOptAction(t *testing.T) {
|
||||
@ -407,6 +488,9 @@ func TestOptAction(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("OptAction created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("OptAction created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -417,6 +501,11 @@ func TestOptAction(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "EXPIRE", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTferAction(t *testing.T) {
|
||||
@ -444,6 +533,9 @@ func TestTferAction(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("TferAction created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("TferAction created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -454,6 +546,11 @@ func TestTferAction(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OUT", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPosType(t *testing.T) {
|
||||
@ -481,6 +578,9 @@ func TestPosType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("PosType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("PosType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -491,6 +591,11 @@ func TestPosType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "SHORT", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecured(t *testing.T) {
|
||||
@ -518,6 +623,9 @@ func TestSecured(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("Secured created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("Secured created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -528,6 +636,11 @@ func TestSecured(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "COVERED", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDuration(t *testing.T) {
|
||||
@ -555,6 +668,9 @@ func TestDuration(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("Duration created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("Duration created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -565,6 +681,11 @@ func TestDuration(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "IMMEDIATE", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRestriction(t *testing.T) {
|
||||
@ -592,6 +713,9 @@ func TestRestriction(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("Restriction created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("Restriction created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -602,6 +726,11 @@ func TestRestriction(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "NONE", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnitType(t *testing.T) {
|
||||
@ -629,6 +758,9 @@ func TestUnitType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("UnitType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("UnitType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -639,6 +771,11 @@ func TestUnitType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "CURRENCY", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOptBuyType(t *testing.T) {
|
||||
@ -666,6 +803,9 @@ func TestOptBuyType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("OptBuyType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("OptBuyType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -676,6 +816,11 @@ func TestOptBuyType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "BUYTOCLOSE", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSellType(t *testing.T) {
|
||||
@ -703,6 +848,9 @@ func TestSellType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("SellType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("SellType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -713,6 +861,11 @@ func TestSellType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "SELLSHORT", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoanPmtFreq(t *testing.T) {
|
||||
@ -740,6 +893,9 @@ func TestLoanPmtFreq(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("LoanPmtFreq created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("LoanPmtFreq created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -750,6 +906,11 @@ func TestLoanPmtFreq(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OTHER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIncomeType(t *testing.T) {
|
||||
@ -777,6 +938,9 @@ func TestIncomeType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("IncomeType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("IncomeType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -787,6 +951,11 @@ func TestIncomeType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "MISC", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSellReason(t *testing.T) {
|
||||
@ -814,6 +983,9 @@ func TestSellReason(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("SellReason created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("SellReason created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -824,6 +996,11 @@ func TestSellReason(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "MATURITY", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOptSellType(t *testing.T) {
|
||||
@ -851,6 +1028,9 @@ func TestOptSellType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("OptSellType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("OptSellType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -861,6 +1041,11 @@ func TestOptSellType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "SELLTOOPEN", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRelType(t *testing.T) {
|
||||
@ -888,6 +1073,9 @@ func TestRelType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("RelType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("RelType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -898,6 +1086,11 @@ func TestRelType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OTHER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCharType(t *testing.T) {
|
||||
@ -925,6 +1118,9 @@ func TestCharType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("CharType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("CharType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -935,6 +1131,11 @@ func TestCharType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "ALPHAANDNUMERIC", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncMode(t *testing.T) {
|
||||
@ -962,6 +1163,9 @@ func TestSyncMode(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("SyncMode created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("SyncMode created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -972,6 +1176,11 @@ func TestSyncMode(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "LITE", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebtType(t *testing.T) {
|
||||
@ -999,6 +1208,9 @@ func TestDebtType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("DebtType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("DebtType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1009,6 +1221,11 @@ func TestDebtType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "ZERO", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDebtClass(t *testing.T) {
|
||||
@ -1036,6 +1253,9 @@ func TestDebtClass(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("DebtClass created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("DebtClass created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1046,6 +1266,11 @@ func TestDebtClass(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OTHER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCouponFreq(t *testing.T) {
|
||||
@ -1073,6 +1298,9 @@ func TestCouponFreq(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("CouponFreq created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("CouponFreq created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1083,6 +1311,11 @@ func TestCouponFreq(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OTHER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallType(t *testing.T) {
|
||||
@ -1110,6 +1343,9 @@ func TestCallType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("CallType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("CallType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1120,6 +1356,11 @@ func TestCallType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "MATURITY", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssetClass(t *testing.T) {
|
||||
@ -1147,6 +1388,9 @@ func TestAssetClass(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("AssetClass created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("AssetClass created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1157,6 +1401,11 @@ func TestAssetClass(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OTHER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMfType(t *testing.T) {
|
||||
@ -1184,6 +1433,9 @@ func TestMfType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("MfType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("MfType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1194,6 +1446,11 @@ func TestMfType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OTHER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOptType(t *testing.T) {
|
||||
@ -1221,6 +1478,9 @@ func TestOptType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("OptType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("OptType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1231,6 +1491,11 @@ func TestOptType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "CALL", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStockType(t *testing.T) {
|
||||
@ -1258,6 +1523,9 @@ func TestStockType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("StockType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("StockType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1268,6 +1536,11 @@ func TestStockType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OTHER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOfxSec(t *testing.T) {
|
||||
@ -1295,6 +1568,9 @@ func TestOfxSec(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("OfxSec created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("OfxSec created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1305,6 +1581,11 @@ func TestOfxSec(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "TYPE 1", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHolderType(t *testing.T) {
|
||||
@ -1332,6 +1613,9 @@ func TestHolderType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("HolderType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("HolderType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1342,6 +1626,11 @@ func TestHolderType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OTHER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAcctClassification(t *testing.T) {
|
||||
@ -1369,6 +1658,9 @@ func TestAcctClassification(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("AcctClassification created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("AcctClassification created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1379,6 +1671,11 @@ func TestAcctClassification(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "OTHER", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSvcStatus(t *testing.T) {
|
||||
@ -1406,6 +1703,9 @@ func TestSvcStatus(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("SvcStatus created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("SvcStatus created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1416,6 +1716,11 @@ func TestSvcStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "ACTIVE", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUsProductType(t *testing.T) {
|
||||
@ -1443,6 +1748,9 @@ func TestUsProductType(t *testing.T) {
|
||||
if overwritten.Valid() {
|
||||
t.Fatalf("UsProductType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not be valid\n")
|
||||
}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {
|
||||
t.Fatalf("UsProductType created with string \"THISWILLNEVERBEAVALIDENUMSTRING\" should not return valid string from String()\n")
|
||||
}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {
|
||||
@ -1453,4 +1761,9 @@ func TestUsProductType(t *testing.T) {
|
||||
}
|
||||
|
||||
unmarshalHelper(t, "UGMA", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error unmarshalling garbage value\n")
|
||||
}
|
||||
}
|
||||
|
@ -76,6 +76,8 @@ const (
|
||||
var {enumLower}s = [...]string{{"{upperValueString}"}}
|
||||
|
||||
func (e {enumLower}) Valid() bool {{
|
||||
// This check is mostly out of paranoia, ensuring e != 0 should be
|
||||
// sufficient
|
||||
return e >= {firstValue} && e <= {lastValue}
|
||||
}}
|
||||
|
||||
@ -110,10 +112,8 @@ func (e *{enumLower}) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
|
||||
}}
|
||||
|
||||
func (e *{enumLower}) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {{
|
||||
if *e == 0 {{
|
||||
if !e.Valid() {{
|
||||
return nil
|
||||
}} else if !e.Valid() {{
|
||||
return errors.New("Invalid {enum}")
|
||||
}}
|
||||
enc.EncodeElement({enumLower}s[*e-1], start)
|
||||
return nil
|
||||
@ -166,6 +166,7 @@ test_header = """package ofxgo_test
|
||||
import (
|
||||
"github.com/aclindsa/go/src/encoding/xml"
|
||||
"github.com/aclindsa/ofxgo"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
"""
|
||||
@ -196,6 +197,9 @@ func Test{enum}(t *testing.T) {{
|
||||
if overwritten.Valid() {{
|
||||
t.Fatalf("{enum} created with string \\\"THISWILLNEVERBEAVALIDENUMSTRING\\\" should not be valid\\n")
|
||||
}}
|
||||
if !strings.Contains(strings.ToLower(overwritten.String()), "invalid") {{
|
||||
t.Fatalf("{enum} created with string \\\"THISWILLNEVERBEAVALIDENUMSTRING\\\" should not return valid string from String()\\n")
|
||||
}}
|
||||
|
||||
b, err := xml.Marshal(&overwritten)
|
||||
if err != nil {{
|
||||
@ -206,6 +210,11 @@ func Test{enum}(t *testing.T) {{
|
||||
}}
|
||||
|
||||
unmarshalHelper(t, "{lastValueUpper}", &e, &overwritten)
|
||||
|
||||
err = xml.Unmarshal([]byte("<GARBAGE><!LALDK>"), &overwritten)
|
||||
if err == nil {{
|
||||
t.Fatalf("Expected error unmarshalling garbage value\\n")
|
||||
}}
|
||||
}}
|
||||
"""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user