From 6ece1694173fc78565a44036e8b42b6e9ed5bc28 Mon Sep 17 00:00:00 2001 From: Cory Slep Date: Sat, 5 Jan 2019 17:17:12 +0100 Subject: [PATCH] Add serialization and comparison for xsd:nonNegativeInteger --- tools/exp/rdf/xsd/ontology.go | 43 ++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/tools/exp/rdf/xsd/ontology.go b/tools/exp/rdf/xsd/ontology.go index 82c798a..eb130e9 100644 --- a/tools/exp/rdf/xsd/ontology.go +++ b/tools/exp/rdf/xsd/ontology.go @@ -665,21 +665,58 @@ func (n *nonNegativeInteger) Apply(key string, value interface{}, ctx *rdf.Parsi nonNegativeIntegerSpec, jen.Id("int"), []jen.Code{ - // TODO + jen.Return( + jen.Id(codegen.This()), + jen.Nil(), + ), }), DeserializeFn: rdf.DeserializeValueFunction( n.pkg, nonNegativeIntegerSpec, jen.Id("int"), []jen.Code{ - // TODO + jen.If( + jen.List( + jen.Id("i"), + jen.Id("ok"), + ).Op(":=").Id(codegen.This()).Assert(jen.Float64()), + jen.Id("ok"), + ).Block( + jen.Id("n").Op(":=").Int().Call(jen.Id("i")), + jen.If( + jen.Id("n").Op(">=").Lit(0), + ).Block( + jen.Return( + jen.Id("n"), + jen.Nil(), + ), + ).Else().Block( + jen.Return( + jen.Lit(0), + jen.Qual("fmt", "Errorf").Call( + jen.Lit("%v is a negative integer for xsd:nonNegativeInteger"), + jen.Id(codegen.This()), + ), + ), + ), + ).Else().Block( + jen.Return( + jen.Lit(0), + jen.Qual("fmt", "Errorf").Call( + jen.Lit("%v cannot be interpreted as a float for xsd:nonNegativeInteger"), + jen.Id(codegen.This()), + ), + ), + ), }), LessFn: rdf.LessFunction( n.pkg, nonNegativeIntegerSpec, jen.Id("int"), []jen.Code{ - // TODO + jen.Return( + jen.Id("lhs").Op("<").Id("rhs"), + ), }), } if err = v.SetValue(nonNegativeIntegerSpec, val); err != nil {