How to use Bag method of td Package

Best Go-testdeep code snippet using td.Bag

elemmakepkg.go

Source:elemmakepkg.go Github

copy

Full Screen

...14const (15 idPrefix = "XsdGoPkg"16)1718func (me *All) makePkg(bag *PkgBag) {19 me.elemBase.beforeMakePkg(bag)20 me.hasElemsElement.makePkg(bag)21 me.elemBase.afterMakePkg(bag)22}2324func (me *Annotation) makePkg(bag *PkgBag) {25 me.elemBase.beforeMakePkg(bag)26 me.hasElemsAppInfo.makePkg(bag)27 me.hasElemsDocumentation.makePkg(bag)28 me.elemBase.afterMakePkg(bag)29}3031func (me *Any) makePkg(bag *PkgBag) {32 me.elemBase.beforeMakePkg(bag)33 me.elemBase.afterMakePkg(bag)34}3536func (me *AnyAttribute) makePkg(bag *PkgBag) {37 me.elemBase.beforeMakePkg(bag)38 me.elemBase.afterMakePkg(bag)39}4041func (me *AppInfo) makePkg(bag *PkgBag) {42 me.elemBase.beforeMakePkg(bag)43 me.elemBase.afterMakePkg(bag)44}4546func (me *Attribute) makePkg(bag *PkgBag) {47 var safeName, typeName, tmp, key, defVal, impName string48 var defName = "Default"49 me.elemBase.beforeMakePkg(bag)50 if len(me.Form) == 0 {51 me.Form = bag.Schema.AttributeFormDefault52 }53 me.hasElemsSimpleType.makePkg(bag)54 if len(me.Ref) > 0 {55 key = bag.resolveQnameRef(me.Ref.String(), "", &impName)56 tmp = ustr.PrefixWithSep(impName, ".", idPrefix+"HasAttr_"+bag.safeName(me.Ref.String()[(strings.Index(me.Ref.String(), ":")+1):]))57 if bag.attRefImps[me], bag.attsKeys[me] = impName, key; len(bag.attsCache[key]) == 0 {58 bag.attsCache[key] = tmp59 }60 } else {61 safeName = bag.safeName(me.Name.String())62 if typeName = me.Type.String(); (len(typeName) == 0) && (len(me.SimpleTypes) > 0) {63 typeName = me.SimpleTypes[0].Name.String()64 } else {65 if len(typeName) == 0 {66 typeName = bag.xsdStringTypeRef()67 }68 typeName = bag.resolveQnameRef(typeName, "T", &impName)69 }70 if defVal = me.Default; len(defVal) == 0 {71 defName, defVal = "Fixed", me.Fixed72 }73 if me.Parent() == bag.Schema {74 key = safeName75 } else {76 key = safeName + "_" + bag.safeName(typeName) + "_" + bag.safeName(defVal)77 }78 if len(bag.attsCache[key]) == 0 {79 tmp = idPrefix + "HasAttr_" + key80 bag.attsKeys[me] = key81 bag.attsCache[key] = tmp82 var td = bag.addType(me, tmp, "", me.Annotation)83 td.addField(me, safeName, typeName, ustr.Ifs(len(bag.Schema.TargetNamespace) > 0, bag.Schema.TargetNamespace.String()+" ", "")+me.Name.String()+",attr", me.Annotation)84 if isPt := bag.isParseType(typeName); len(defVal) > 0 {85 doc := sfmt("Returns the %v value for %v -- "+ustr.Ifs(isPt, "%v", "%#v"), strings.ToLower(defName), safeName, defVal)86 if isPt {87 if PkgGen.ForceParseForDefaults {88 td.addMethod(nil, tmp, safeName+defName, typeName, sfmt("var x = new(%v); x.Set(%#v); return *x", typeName, defVal), doc)89 } else {90 td.addMethod(nil, tmp, safeName+defName, typeName, sfmt("return %v(%v)", typeName, defVal), doc)91 }92 } else {93 td.addMethod(nil, tmp, safeName+defName, typeName, sfmt("return %v(%#v)", typeName, defVal), doc)94 }95 }96 } else {97 bag.attsKeys[me] = key98 }99 }100 me.elemBase.afterMakePkg(bag)101}102103func (me *AttributeGroup) makePkg(bag *PkgBag) {104 var refName, refImp string105 me.elemBase.beforeMakePkg(bag)106 me.hasElemsAttribute.makePkg(bag)107 me.hasElemsAnyAttribute.makePkg(bag)108 me.hasElemsAttributeGroup.makePkg(bag)109 if len(me.Ref) > 0 {110 if len(bag.attGroups[me]) == 0 {111 refName = bag.resolveQnameRef(me.Ref.String(), "", &refImp)112 bag.attGroups[me] = idPrefix + "HasAtts_" + refName113 bag.attGroupRefImps[me] = refImp114 }115 } else {116 safeName := bag.safeName(me.Name.String())117 tmp := idPrefix + "HasAtts_" + safeName118 var td = bag.addType(me, tmp, "", me.Annotation)119 bag.attGroups[me] = tmp120 for _, ag := range me.AttributeGroups {121 if len(ag.Ref) == 0 {122 ag.Ref.Set(ag.Name.String())123 }124 if refName = bag.resolveQnameRef(ag.Ref.String(), "", &refImp); len(refImp) > 0 {125 td.addEmbed(ag, refImp+"."+idPrefix+"HasAtts_"+refName[(len(refImp)+1):], ag.Annotation)126 } else {127 td.addEmbed(ag, idPrefix+"HasAtts_"+refName, ag.Annotation)128 }129 }130 for _, att := range me.Attributes {131 if key := bag.attsKeys[att]; len(key) > 0 {132 td.addEmbed(att, bag.attsCache[key], att.Annotation)133 }134 }135 }136 me.elemBase.afterMakePkg(bag)137}138139func (me *Choice) makePkg(bag *PkgBag) {140 me.elemBase.beforeMakePkg(bag)141 me.hasElemsAny.makePkg(bag)142 me.hasElemsChoice.makePkg(bag)143 me.hasElemsGroup.makePkg(bag)144 me.hasElemsSequence.makePkg(bag)145 me.hasElemsElement.makePkg(bag)146 me.elemBase.afterMakePkg(bag)147}148149func (me *ComplexContent) makePkg(bag *PkgBag) {150 me.elemBase.beforeMakePkg(bag)151 me.hasElemExtensionComplexContent.makePkg(bag)152 me.hasElemRestrictionComplexContent.makePkg(bag)153 me.elemBase.afterMakePkg(bag)154}155156func (me *ComplexType) makePkg(bag *PkgBag) {157 var att *Attribute158 var attGroup *AttributeGroup159 var ctBaseType, ctValueType, typeSafeName string160 var allAtts = map[*Attribute]bool{}161 var allAttGroups = map[*AttributeGroup]bool{}162 var allElems = map[*Element]bool{}163 var allElemGroups = map[*Group]bool{}164 var elsDone, grsDone = map[string]bool{}, map[string]bool{}165 var allChoices, tmpChoices = []*Choice{}, []*Choice{me.Choice}166 var allSeqs, tmpSeqs = []*Sequence{}, []*Sequence{me.Sequence}167 var el *Element168 var elGr *Group169 var mixed = false170 me.elemBase.beforeMakePkg(bag)171 me.hasElemsAttribute.makePkg(bag)172 me.hasElemsAnyAttribute.makePkg(bag)173 me.hasElemsAttributeGroup.makePkg(bag)174 me.hasElemAll.makePkg(bag)175 me.hasElemChoice.makePkg(bag)176 me.hasElemGroup.makePkg(bag)177 me.hasElemSequence.makePkg(bag)178 me.hasElemComplexContent.makePkg(bag)179 me.hasElemSimpleContent.makePkg(bag)180 if len(me.Name) == 0 {181 me.Name = bag.AnonName(me.longSafeName(bag))182 }183 typeSafeName = bag.safeName(ustr.PrependIf(me.Name.String(), "T"))184 var td = bag.addType(me, typeSafeName, "", me.Annotation)185 for _, att = range me.Attributes {186 allAtts[att] = true187 }188 for _, attGroup = range me.AttributeGroups {189 allAttGroups[attGroup] = true190 }191 allChoices, allSeqs = Flattened(tmpChoices, tmpSeqs)192 if me.All != nil {193 for _, el = range me.All.Elements {194 allElems[el] = true195 }196 }197 if me.Group != nil {198 allElemGroups[me.Group] = true199 }200 if mixed = me.Mixed; me.ComplexContent != nil {201 mixed = mixed || me.ComplexContent.Mixed202 td.addAnnotations(me.ComplexContent.Annotation)203 if me.ComplexContent.ExtensionComplexContent != nil {204 td.addAnnotations(me.ComplexContent.ExtensionComplexContent.Annotation)205 if me.ComplexContent.ExtensionComplexContent.All != nil {206 for _, el = range me.ComplexContent.ExtensionComplexContent.All.Elements {207 allElems[el] = true208 }209 }210 for _, elGr = range me.ComplexContent.ExtensionComplexContent.Groups {211 allElemGroups[elGr] = true212 }213 tmpChoices, tmpSeqs = Flattened(me.ComplexContent.ExtensionComplexContent.Choices, me.ComplexContent.ExtensionComplexContent.Sequences)214 allChoices, allSeqs = append(allChoices, tmpChoices...), append(allSeqs, tmpSeqs...)215 for _, att = range me.ComplexContent.ExtensionComplexContent.Attributes {216 allAtts[att] = true217 }218 for _, attGroup = range me.ComplexContent.ExtensionComplexContent.AttributeGroups {219 allAttGroups[attGroup] = true220 }221 if len(me.ComplexContent.ExtensionComplexContent.Base) > 0 {222 ctBaseType = me.ComplexContent.ExtensionComplexContent.Base.String()223 }224 }225 if me.ComplexContent.RestrictionComplexContent != nil {226 td.addAnnotations(me.ComplexContent.RestrictionComplexContent.Annotation)227 if me.ComplexContent.RestrictionComplexContent.All != nil {228 for _, el = range me.ComplexContent.RestrictionComplexContent.All.Elements {229 allElems[el] = true230 }231 }232 tmpChoices, tmpSeqs = Flattened(me.ComplexContent.RestrictionComplexContent.Choices, me.ComplexContent.RestrictionComplexContent.Sequences)233 allChoices, allSeqs = append(allChoices, tmpChoices...), append(allSeqs, tmpSeqs...)234 for _, att = range me.ComplexContent.RestrictionComplexContent.Attributes {235 allAtts[att] = true236 }237 for _, attGroup = range me.ComplexContent.RestrictionComplexContent.AttributeGroups {238 allAttGroups[attGroup] = true239 }240 if len(me.ComplexContent.RestrictionComplexContent.Base) > 0 {241 ctBaseType = me.ComplexContent.RestrictionComplexContent.Base.String()242 }243 }244 }245 if me.SimpleContent != nil {246 td.addAnnotations(me.SimpleContent.Annotation)247 if me.SimpleContent.ExtensionSimpleContent != nil {248 if len(me.SimpleContent.ExtensionSimpleContent.Base) > 0 {249 ctBaseType = me.SimpleContent.ExtensionSimpleContent.Base.String()250 }251 td.addAnnotations(me.SimpleContent.ExtensionSimpleContent.Annotation)252 for _, att = range me.SimpleContent.ExtensionSimpleContent.Attributes {253 allAtts[att] = true254 }255 for _, attGroup = range me.SimpleContent.ExtensionSimpleContent.AttributeGroups {256 allAttGroups[attGroup] = true257 }258 if (len(ctValueType) == 0) && (len(me.SimpleContent.ExtensionSimpleContent.Base) > 0) {259 ctValueType = me.SimpleContent.ExtensionSimpleContent.Base.String()260 }261 }262 if me.SimpleContent.RestrictionSimpleContent != nil {263 if len(me.SimpleContent.RestrictionSimpleContent.Base) > 0 {264 ctBaseType = me.SimpleContent.RestrictionSimpleContent.Base.String()265 }266 td.addAnnotations(me.SimpleContent.RestrictionSimpleContent.Annotation)267 for _, att = range me.SimpleContent.RestrictionSimpleContent.Attributes {268 allAtts[att] = true269 }270 for _, attGroup = range me.SimpleContent.RestrictionSimpleContent.AttributeGroups {271 allAttGroups[attGroup] = true272 }273 if (len(ctValueType) == 0) && (len(me.SimpleContent.RestrictionSimpleContent.Base) > 0) {274 ctValueType = me.SimpleContent.RestrictionSimpleContent.Base.String()275 }276 if (len(ctValueType) == 0) && (len(me.SimpleContent.RestrictionSimpleContent.SimpleTypes) > 0) {277 ctValueType = me.SimpleContent.RestrictionSimpleContent.SimpleTypes[0].Name.String()278 }279 for _, enum := range me.SimpleContent.RestrictionSimpleContent.Enumerations {280 println("ENUMTODO!?! Whoever sees this message, please post an issue at github.com/metaleap/go-xsd with a link to the XSD..." + enum.selfName().String())281 }282 }283 }284 if ctBaseType = bag.resolveQnameRef(ctBaseType, "T", nil); len(ctBaseType) > 0 {285 if strings.HasPrefix(ctBaseType, "xsdt.") {286 td.addEmbed(nil, idPrefix+"HasCdata")287 } else {288 td.addEmbed(nil, bag.safeName(ctBaseType))289 }290 } else if ctValueType = bag.resolveQnameRef(ctValueType, "T", nil); len(ctValueType) > 0 {291 bag.simpleContentValueTypes[typeSafeName] = ctValueType292 td.addField(nil, idPrefix+"Value", ctValueType, ",chardata")293 chain := sfmt("me.%vValue", idPrefix)294 td.addMethod(nil, "*"+typeSafeName, sfmt("To%v", bag.safeName(ctValueType)), ctValueType, sfmt("return %v", chain), sfmt("Simply returns the value of its %vValue field.", idPrefix))295 var ttn string296 for ttd := bag.declTypes[ctValueType]; ttd != nil; ttd = bag.declTypes[ttn] {297 if ttd != nil {298 bag.declConvs[ttd.Name] = true299 }300 if ttn = ttd.Type; len(ttn) > 0 {301 chain += sfmt(".To%v()", bag.safeName(ttn))302 td.addMethod(nil, "*"+typeSafeName, sfmt("To%v", bag.safeName(ttn)), ttn, sfmt("return %v", chain), sfmt("Returns the value of its %vValue field as a %v (which %v is just aliasing).", idPrefix, ttn, ctValueType))303 } else {304 break305 }306 }307 if (!strings.HasPrefix(ctValueType, "xsdt.")) && (bag.declTypes[ctValueType] == nil) {308 println("NOTFOUND: " + ctValueType)309 }310 } else if mixed {311 td.addEmbed(nil, idPrefix+"HasCdata")312 }313 for elGr = range allElemGroups {314 subMakeElemGroup(bag, td, elGr, grsDone, anns(nil, me.ComplexContent)...)315 }316 for el = range allElems {317 subMakeElem(bag, td, el, elsDone, 1, anns(me.All, nil)...)318 }319 for _, ch := range allChoices {320 for _, el = range ch.Elements {321 subMakeElem(bag, td, el, elsDone, ch.hasAttrMaxOccurs.Value(), ch.Annotation)322 }323 for _, elGr = range ch.Groups {324 subMakeElemGroup(bag, td, elGr, grsDone, ch.Annotation)325 }326 }327 for _, seq := range allSeqs {328 for _, el = range seq.Elements {329 subMakeElem(bag, td, el, elsDone, seq.hasAttrMaxOccurs.Value(), seq.Annotation)330 }331 for _, elGr = range seq.Groups {332 subMakeElemGroup(bag, td, elGr, grsDone, seq.Annotation)333 }334 }335 for attGroup = range allAttGroups {336 td.addEmbed(attGroup, ustr.PrefixWithSep(bag.attGroupRefImps[attGroup], ".", bag.attGroups[attGroup][(strings.Index(bag.attGroups[attGroup], ".")+1):]), attGroup.Annotation)337 }338339 for att = range allAtts {340 if key := bag.attsKeys[att]; len(key) > 0 {341 td.addEmbed(att, ustr.PrefixWithSep(bag.attRefImps[att], ".", bag.attsCache[key][(strings.Index(bag.attsCache[key], ".")+1):]), att.Annotation)342 }343 }344 me.elemBase.afterMakePkg(bag)345}346347func (me *Documentation) makePkg(bag *PkgBag) {348 me.elemBase.beforeMakePkg(bag)349 if len(me.CDATA) > 0 {350 var s, ln string351 for _, ln = range ustr.Split(me.CDATA, "\n") {352 if s = strings.Trim(ln, " \t\r\n"); len(s) > 0 {353 bag.appendFmt(false, "//\t%s", s)354 }355 }356 }357 me.elemBase.afterMakePkg(bag)358}359360func (me *Element) makePkg(bag *PkgBag) {361 var (362 safeName, typeName, valueType, tmp, key, defVal, impName string363 subEl *Element364 )365 asterisk, defName, doc := "", "Default", ""366 me.elemBase.beforeMakePkg(bag)367 if len(me.Form) == 0 {368 me.Form = bag.Schema.ElementFormDefault369 }370 me.hasElemsSimpleType.makePkg(bag)371 me.hasElemComplexType.makePkg(bag)372 if len(me.Ref) > 0 {373 key = bag.resolveQnameRef(me.Ref.String(), "", &impName)374 for pref, cache := range map[string]map[string]string{"HasElem_": bag.elemsCacheOnce, "HasElems_": bag.elemsCacheMult} {375 tmp = ustr.PrefixWithSep(impName, ".", idPrefix+pref+bag.safeName(me.Ref.String()[(strings.Index(me.Ref.String(), ":")+1):]))376 if bag.elemRefImps[me], bag.elemKeys[me] = impName, key; len(cache[key]) == 0 {377 cache[key] = tmp378 }379 }380 } else {381 safeName = bag.safeName(me.Name.String())382 if typeName = me.Type.String(); (len(typeName) == 0) && ((me.ComplexType != nil) || (len(me.SimpleTypes) > 0)) {383 if me.ComplexType != nil {384 asterisk, typeName = "*", me.ComplexType.Name.String()385 } else {386 typeName = me.SimpleTypes[0].Name.String()387 }388 } else {389 if len(typeName) == 0 {390 typeName = bag.xsdStringTypeRef()391 }392 loadedSchemas := make(map[string]bool)393 if typeName = bag.resolveQnameRef(typeName, "T", &impName); bag.Schema.RootSchema([]string{bag.Schema.loadUri}).globalComplexType(bag, typeName, loadedSchemas) != nil {394 asterisk = "*"395 }396 }397 if defVal = me.Default; len(defVal) == 0 {398 defName, defVal = "Fixed", me.Fixed399 }400 if me.Parent() == bag.Schema {401 key = safeName402 } else {403 key = bag.safeName(bag.Stacks.FullName()) + "_" + safeName + "_" + bag.safeName(typeName) + "_" + bag.safeName(defVal)404 }405 if valueType = bag.simpleContentValueTypes[typeName]; len(valueType) == 0 {406 valueType = typeName407 }408 isPt := bag.isParseType(valueType)409 if _, isChoice := me.Parent().(*Choice); isChoice && isPt {410 asterisk = "*"411 }412 for pref, cache := range map[string]map[string]string{"HasElem_": bag.elemsCacheOnce, "HasElems_": bag.elemsCacheMult} {413 if tmp = idPrefix + pref + key; !bag.elemsWritten[tmp] {414 bag.elemsWritten[tmp], bag.elemKeys[me] = true, key415 cache[key] = tmp416 var td = bag.addType(me, tmp, "", me.Annotation)417 td.addField(me, ustr.Ifs(pref == "HasElems_", pluralize(safeName), safeName), ustr.Ifs(pref == "HasElems_", "[]"+asterisk+typeName, asterisk+typeName), ustr.Ifs(len(bag.Schema.TargetNamespace) > 0, bag.Schema.TargetNamespace.String()+" ", "")+me.Name.String(), me.Annotation)418 if me.parent == bag.Schema {419 loadedSchemas := make(map[string]bool)420 for _, subEl = range bag.Schema.RootSchema([]string{bag.Schema.loadUri}).globalSubstitutionElems(me, loadedSchemas) {421 td.addEmbed(subEl, idPrefix+pref+bag.safeName(subEl.Name.String()), subEl.Annotation)422 }423 }424 if len(defVal) > 0 {425 doc = sfmt("Returns the %v value for %v -- "+ustr.Ifs(isPt, "%v", "%#v"), strings.ToLower(defName), safeName, defVal)426 if isPt {427 if PkgGen.ForceParseForDefaults {428 td.addMethod(nil, tmp, safeName+defName, valueType, sfmt("var x = new(%v); x.Set(%#v); return *x", valueType, defVal), doc)429 } else {430 td.addMethod(nil, tmp, safeName+defName, valueType, sfmt("return %v(%v)", valueType, defVal), doc)431 }432 } else {433 td.addMethod(nil, tmp, safeName+defName, valueType, sfmt("return %v(%#v)", valueType, defVal), doc)434 }435 }436 }437 }438 }439 me.elemBase.afterMakePkg(bag)440}441442func (me *ExtensionComplexContent) makePkg(bag *PkgBag) {443 me.elemBase.beforeMakePkg(bag)444 me.hasElemsAttribute.makePkg(bag)445 me.hasElemsAnyAttribute.makePkg(bag)446 me.hasElemsAttributeGroup.makePkg(bag)447 me.hasElemAll.makePkg(bag)448 me.hasElemsChoice.makePkg(bag)449 me.hasElemsGroup.makePkg(bag)450 me.hasElemsSequence.makePkg(bag)451 me.elemBase.afterMakePkg(bag)452}453454func (me *ExtensionSimpleContent) makePkg(bag *PkgBag) {455 me.elemBase.beforeMakePkg(bag)456 me.hasElemsAttribute.makePkg(bag)457 me.hasElemsAnyAttribute.makePkg(bag)458 me.hasElemsAttributeGroup.makePkg(bag)459 me.elemBase.afterMakePkg(bag)460}461462func (me *Field) makePkg(bag *PkgBag) {463 me.elemBase.beforeMakePkg(bag)464 me.elemBase.afterMakePkg(bag)465}466467func (me *Group) makePkg(bag *PkgBag) {468 var refName, refImp string469 var choices = []*Choice{me.Choice}470 var seqs = []*Sequence{me.Sequence}471 var el *Element472 var gr *Group473 var elsDone, grsDone = map[string]bool{}, map[string]bool{}474 me.elemBase.beforeMakePkg(bag)475 me.hasElemAll.makePkg(bag)476 me.hasElemChoice.makePkg(bag)477 me.hasElemSequence.makePkg(bag)478 if len(me.Ref) > 0 {479 if len(bag.elemGroups[me]) == 0 {480 refName = bag.resolveQnameRef(me.Ref.String(), "", &refImp)481 bag.elemGroups[me] = idPrefix + "HasGroup_" + refName482 bag.elemGroupRefImps[me] = refImp483 }484 } else {485 me.Ref.Set(me.Name.String())486 safeName := bag.safeName(me.Name.String())487 tmp := idPrefix + "HasGroup_" + safeName488 bag.elemGroups[me] = tmp489 var td = bag.addType(me, tmp, "", me.Annotation)490 choices, seqs = Flattened(choices, seqs)491 if me.All != nil {492 for _, el = range me.All.Elements {493 subMakeElem(bag, td, el, elsDone, 1, me.All.Annotation)494 }495 }496 for _, ch := range choices {497 for _, el = range ch.Elements {498 subMakeElem(bag, td, el, elsDone, ch.hasAttrMaxOccurs.Value(), ch.Annotation)499 }500 for _, gr = range ch.Groups {501 subMakeElemGroup(bag, td, gr, grsDone, ch.Annotation)502 }503 }504 for _, seq := range seqs {505 for _, el = range seq.Elements {506 subMakeElem(bag, td, el, elsDone, seq.hasAttrMaxOccurs.Value(), seq.Annotation)507 }508 for _, gr = range seq.Groups {509 subMakeElemGroup(bag, td, gr, grsDone, seq.Annotation)510 }511 }512 }513514 me.elemBase.afterMakePkg(bag)515}516517func (me *Import) makePkg(bag *PkgBag) {518 me.elemBase.beforeMakePkg(bag)519 var impName, impPath string520 var pos int521 me.hasElemAnnotation.makePkg(bag)522 for k, v := range bag.Schema.XMLNamespaces {523 if v == me.Namespace {524 impName = safeIdentifier(k)525 break526 }527 }528 if len(impName) > 0 {529 if pos, impPath = strings.Index(me.SchemaLocation.String(), protSep), me.SchemaLocation.String(); pos > 0 {530 impPath = impPath[pos+len(protSep):]531 } else {532 impPath = path.Join(path.Dir(bag.Schema.loadUri), impPath)533 }534 impPath = path.Join(path.Dir(impPath), goPkgPrefix+path.Base(impPath)+goPkgSuffix)535 bag.imports[impName] = path.Join(PkgGen.BasePath, impPath)536 }537 me.elemBase.afterMakePkg(bag)538}539540func (me *Key) makePkg(bag *PkgBag) {541 me.elemBase.beforeMakePkg(bag)542 me.hasElemField.makePkg(bag)543 me.hasElemSelector.makePkg(bag)544 me.elemBase.afterMakePkg(bag)545}546547func (me *KeyRef) makePkg(bag *PkgBag) {548 me.elemBase.beforeMakePkg(bag)549 me.hasElemField.makePkg(bag)550 me.hasElemSelector.makePkg(bag)551 me.elemBase.afterMakePkg(bag)552}553554func (me *List) makePkg(bag *PkgBag) {555 var safeName string556 me.elemBase.beforeMakePkg(bag)557 me.hasElemsSimpleType.makePkg(bag)558 rtr := bag.resolveQnameRef(me.ItemType.String(), "T", nil)559 if len(rtr) == 0 {560 rtr = me.SimpleTypes[0].Name.String()561 }562 st := bag.Stacks.CurSimpleType()563 safeName = bag.safeName(ustr.PrependIf(st.Name.String(), "T"))564 body, doc := "", sfmt("%v declares a String containing a whitespace-separated list of %v values. This Values() method creates and returns a slice of all elements in that list", safeName, rtr)565 body = sfmt("svals := %v.ListValues(string(me)); list = make([]%v, len(svals)); for i, s := range svals { list[i].Set(s) }; return", bag.impName, rtr)566 bag.ctd.addMethod(me, safeName, "Values", sfmt("(list []%v)", rtr), body, doc+".", me.Annotation)567 for baseType := bag.simpleBaseTypes[rtr]; len(baseType) > 0; baseType = bag.simpleBaseTypes[baseType] {568 body = sfmt("svals := %v.ListValues(string(me)); list = make([]%v, len(svals)); for i, s := range svals { list[i].Set(s) }; return", bag.impName, baseType)569 bag.ctd.addMethod(me, safeName, "Values"+bag.safeName(baseType), sfmt("(list []%v)", baseType), body, sfmt("%s, typed as %s.", doc, baseType), me.Annotation)570 }571 me.elemBase.afterMakePkg(bag)572}573574func (me *Notation) makePkg(bag *PkgBag) {575 me.elemBase.beforeMakePkg(bag)576 me.hasElemAnnotation.makePkg(bag)577 bag.appendFmt(false, "%vNotations.Add(%#v, %#v, %#v, %#v)", idPrefix, me.Id, me.Name, me.Public, me.System)578 me.elemBase.afterMakePkg(bag)579}580581func (me *Redefine) makePkg(bag *PkgBag) {582 me.elemBase.beforeMakePkg(bag)583 me.hasElemsSimpleType.makePkg(bag)584 me.hasElemsAttributeGroup.makePkg(bag)585 me.hasElemsGroup.makePkg(bag)586 me.hasElemsComplexType.makePkg(bag)587 me.elemBase.afterMakePkg(bag)588}589590func (me *RestrictionComplexContent) makePkg(bag *PkgBag) {591 me.elemBase.beforeMakePkg(bag)592 me.hasElemsAttribute.makePkg(bag)593 me.hasElemsAnyAttribute.makePkg(bag)594 me.hasElemsAttributeGroup.makePkg(bag)595 me.hasElemAll.makePkg(bag)596 me.hasElemsChoice.makePkg(bag)597 me.hasElemsSequence.makePkg(bag)598 me.elemBase.afterMakePkg(bag)599}600601func (me *RestrictionSimpleContent) makePkg(bag *PkgBag) {602 me.elemBase.beforeMakePkg(bag)603 me.hasElemsSimpleType.makePkg(bag)604 me.hasElemsAttribute.makePkg(bag)605 me.hasElemsAnyAttribute.makePkg(bag)606 me.hasElemsAttributeGroup.makePkg(bag)607 me.hasElemLength.makePkg(bag)608 me.hasElemPattern.makePkg(bag)609 me.hasElemsEnumeration.makePkg(bag)610 me.hasElemFractionDigits.makePkg(bag)611 me.hasElemMaxExclusive.makePkg(bag)612 me.hasElemMaxInclusive.makePkg(bag)613 me.hasElemMaxLength.makePkg(bag)614 me.hasElemMinExclusive.makePkg(bag)615 me.hasElemMinInclusive.makePkg(bag)616 me.hasElemMinLength.makePkg(bag)617 me.hasElemTotalDigits.makePkg(bag)618 me.hasElemWhiteSpace.makePkg(bag)619 me.elemBase.afterMakePkg(bag)620}621622func (me *RestrictionSimpleEnumeration) makePkg(bag *PkgBag) {623 me.elemBase.beforeMakePkg(bag)624 safeName := bag.safeName(ustr.PrependIf(bag.Stacks.CurSimpleType().Name.String(), "T"))625 var doc = sfmt("Returns true if the value of this enumerated %v is %#v.", safeName, me.Value)626 bag.ctd.addMethod(me, safeName, "Is"+bag.safeName(me.Value), "bool", sfmt("return me.String() == %#v", me.Value), doc)627 me.elemBase.afterMakePkg(bag)628}629630func (me *RestrictionSimpleFractionDigits) makePkg(bag *PkgBag) {631 me.elemBase.beforeMakePkg(bag)632 me.elemBase.afterMakePkg(bag)633}634635func (me *RestrictionSimpleLength) makePkg(bag *PkgBag) {636 me.elemBase.beforeMakePkg(bag)637 me.elemBase.afterMakePkg(bag)638}639640func (me *RestrictionSimpleMaxExclusive) makePkg(bag *PkgBag) {641 me.elemBase.beforeMakePkg(bag)642 me.elemBase.afterMakePkg(bag)643}644645func (me *RestrictionSimpleMaxInclusive) makePkg(bag *PkgBag) {646 me.elemBase.beforeMakePkg(bag)647 me.elemBase.afterMakePkg(bag)648}649650func (me *RestrictionSimpleMaxLength) makePkg(bag *PkgBag) {651 me.elemBase.beforeMakePkg(bag)652 me.elemBase.afterMakePkg(bag)653}654655func (me *RestrictionSimpleMinExclusive) makePkg(bag *PkgBag) {656 me.elemBase.beforeMakePkg(bag)657 me.elemBase.afterMakePkg(bag)658}659660func (me *RestrictionSimpleMinInclusive) makePkg(bag *PkgBag) {661 me.elemBase.beforeMakePkg(bag)662 me.elemBase.afterMakePkg(bag)663}664665func (me *RestrictionSimpleMinLength) makePkg(bag *PkgBag) {666 me.elemBase.beforeMakePkg(bag)667 me.elemBase.afterMakePkg(bag)668}669670func (me *RestrictionSimplePattern) makePkg(bag *PkgBag) {671 me.elemBase.beforeMakePkg(bag)672 me.elemBase.afterMakePkg(bag)673}674675func (me *RestrictionSimpleTotalDigits) makePkg(bag *PkgBag) {676 me.elemBase.beforeMakePkg(bag)677 me.elemBase.afterMakePkg(bag)678}679680func (me *RestrictionSimpleType) makePkg(bag *PkgBag) {681 me.elemBase.beforeMakePkg(bag)682 me.hasElemsSimpleType.makePkg(bag)683 me.hasElemLength.makePkg(bag)684 me.hasElemPattern.makePkg(bag)685 me.hasElemsEnumeration.makePkg(bag)686 me.hasElemFractionDigits.makePkg(bag)687 me.hasElemMaxExclusive.makePkg(bag)688 me.hasElemMaxInclusive.makePkg(bag)689 me.hasElemMaxLength.makePkg(bag)690 me.hasElemMinExclusive.makePkg(bag)691 me.hasElemMinInclusive.makePkg(bag)692 me.hasElemMinLength.makePkg(bag)693 me.hasElemTotalDigits.makePkg(bag)694 me.hasElemWhiteSpace.makePkg(bag)695 me.elemBase.afterMakePkg(bag)696}697698func (me *RestrictionSimpleWhiteSpace) makePkg(bag *PkgBag) {699 me.elemBase.beforeMakePkg(bag)700 me.elemBase.afterMakePkg(bag)701}702703func (me *Schema) makePkg(bag *PkgBag) {704 me.elemBase.beforeMakePkg(bag)705 me.hasElemsImport.makePkg(bag)706 me.hasElemsSimpleType.makePkg(bag)707 me.hasElemsAttribute.makePkg(bag)708 me.hasElemsAttributeGroup.makePkg(bag)709 me.hasElemsComplexType.makePkg(bag)710 me.hasElemsElement.makePkg(bag)711 me.hasElemsGroup.makePkg(bag)712 me.hasElemsRedefine.makePkg(bag)713 me.elemBase.afterMakePkg(bag)714}715716func (me *Selector) makePkg(bag *PkgBag) {717 me.elemBase.beforeMakePkg(bag)718 me.hasElemAnnotation.makePkg(bag)719 me.elemBase.afterMakePkg(bag)720}721722func (me *Sequence) makePkg(bag *PkgBag) {723 me.elemBase.beforeMakePkg(bag)724 me.hasElemsAny.makePkg(bag)725 me.hasElemsChoice.makePkg(bag)726 me.hasElemsGroup.makePkg(bag)727 me.hasElemsSequence.makePkg(bag)728 me.hasElemsElement.makePkg(bag)729 me.elemBase.afterMakePkg(bag)730}731732func (me *SimpleContent) makePkg(bag *PkgBag) {733 me.elemBase.beforeMakePkg(bag)734 me.hasElemExtensionSimpleContent.makePkg(bag)735 me.hasElemRestrictionSimpleContent.makePkg(bag)736 me.elemBase.afterMakePkg(bag)737}738739func (me *SimpleType) makePkg(bag *PkgBag) {740 var typeName = me.Name741 var baseType, safeName = "", ""742 var resolve = true743 var isPt bool744 if len(typeName) == 0 {745 typeName = bag.AnonName(me.longSafeName(bag))746 me.Name = typeName747 } else {748 me.Name = typeName749 }750 typeName = xsdt.NCName(ustr.PrependIf(typeName.String(), "T"))751 me.elemBase.beforeMakePkg(bag)752 bag.Stacks.SimpleType.Push(me)753 safeName = bag.safeName(typeName.String())754 if me.RestrictionSimpleType != nil {755 if baseType = me.RestrictionSimpleType.Base.String(); (len(baseType) == 0) && (len(me.RestrictionSimpleType.SimpleTypes) > 0) {756 resolve, baseType = false, me.RestrictionSimpleType.SimpleTypes[0].Name.String()757 }758 }759 if len(baseType) == 0 {760 baseType = bag.xsdStringTypeRef()761 }762 if resolve {763 baseType = bag.resolveQnameRef(baseType, "T", nil)764 }765 bag.simpleBaseTypes[safeName] = baseType766 if isPt = bag.isParseType(baseType); isPt {767 bag.parseTypes[safeName] = true768 }769 var td = bag.addType(me, safeName, baseType, me.Annotation)770 var doc string771 if isPt {772 doc = sfmt("Since %v is a non-string scalar type (either boolean or numeric), sets the current value obtained from parsing the specified string.", safeName)773 } else {774 doc = sfmt("Since %v is just a simple String type, this merely sets the current value from the specified string.", safeName)775 }776 td.addMethod(nil, "*"+safeName, "Set (s string)", "", sfmt("(*%v)(me).Set(s)", baseType), doc)777 if isPt {778 doc = sfmt("Returns a string representation of this %v's current non-string scalar value.", safeName)779 } else {780 doc = sfmt("Since %v is just a simple String type, this merely returns the current string value.", safeName)781 }782 td.addMethod(nil, safeName, "String", "string", sfmt("return %v(me).String()", baseType), doc)783 doc = sfmt("This convenience method just performs a simple type conversion to %v's alias type %v.", safeName, baseType)784 td.addMethod(nil, safeName, "To"+bag.safeName(baseType), baseType, sfmt("return %v(me)", baseType), doc)785 me.hasElemRestrictionSimpleType.makePkg(bag)786 me.hasElemList.makePkg(bag)787 me.hasElemUnion.makePkg(bag)788 bag.Stacks.SimpleType.Pop()789 me.elemBase.afterMakePkg(bag)790}791792func (me *Union) makePkg(bag *PkgBag) {793 var memberTypes []string794 var rtn, rtnSafeName, safeName string795 me.elemBase.beforeMakePkg(bag)796 me.hasElemsSimpleType.makePkg(bag)797 memberTypes = ustr.Split(me.MemberTypes, " ")798 for _, st := range me.SimpleTypes {799 memberTypes = append(memberTypes, st.Name.String())800 }801 for _, mt := range memberTypes {802 rtn = bag.resolveQnameRef(mt, "T", nil)803 safeName, rtnSafeName = bag.safeName(ustr.PrependIf(bag.Stacks.CurSimpleType().Name.String(), "T")), bag.safeName(rtn)804 bag.ctd.addMethod(me, safeName, "To"+rtnSafeName, rtn, sfmt(ustr.Ifs(bag.isParseType(rtn), "var x = new(%v); x.Set(me.String()); return *x", "return %v(me)"), rtn), sfmt("%v is an XSD union-type of several types. This is a simple type conversion to %v, but keep in mind the actual value may or may not be a valid %v value.", safeName, rtnSafeName, rtnSafeName), me.Annotation)805 }806 me.elemBase.afterMakePkg(bag)807}808809func (me *Unique) makePkg(bag *PkgBag) {810 me.elemBase.beforeMakePkg(bag)811 me.hasElemField.makePkg(bag)812 me.hasElemSelector.makePkg(bag)813 me.elemBase.afterMakePkg(bag)814}815816func anns(a *All, cc *ComplexContent) (anns []*Annotation) {817 if (a != nil) && (a.Annotation != nil) {818 anns = append(anns, a.Annotation)819 }820 if cc != nil {821 if cc.Annotation != nil {822 anns = append(anns, cc.Annotation)823 }824 if ecc := cc.ExtensionComplexContent; (ecc != nil) && (ecc.Annotation != nil) {825 anns = append(anns, ecc.Annotation)826 }827 }828 return829}830831func pluralize(s string) string {832 for _, psp := range PkgGen.PluralizeSpecialPrefixes {833 if strings.HasPrefix(s, psp) {834 return ustr.Pluralize(s[len(psp):] + s[:len(psp)])835 }836 }837 return ustr.Pluralize(s)838}839840func sfmt(s string, a ...interface{}) string {841 return fmt.Sprintf(s, a...)842}843844// For any rune, return a rune that is a valid in an identifier845func coerceToIdentifierRune(ch rune) rune {846 if !unicode.IsLetter(ch) && !unicode.IsNumber(ch) {847 return '_'848 }849 return ch850}851852// Take any string and convert it to a valid identifier853// Appends an underscore if the first rune is a number854func safeIdentifier(s string) string {855 s = strings.Map(coerceToIdentifierRune, s)856 if unicode.IsNumber([]rune(s)[0]) {857 s = fmt.Sprint("_", s)858 }859 return s860}861862func subMakeElem(bag *PkgBag, td *declType, el *Element, done map[string]bool, parentMaxOccurs xsdt.Long, anns ...*Annotation) {863 var elCache map[string]string864 anns = append(anns, el.Annotation)865 if refName := bag.elemKeys[el]; (len(refName) > 0) && (!done[refName]) {866 if done[refName], elCache = true, ustr.Ifm((parentMaxOccurs == 1) && (el.hasAttrMaxOccurs.Value() == 1), bag.elemsCacheOnce, bag.elemsCacheMult); !strings.HasPrefix(elCache[refName], bag.impName+"."+idPrefix) {867 td.addEmbed(el, elCache[refName], anns...)868 }869 }870}871872func subMakeElemGroup(bag *PkgBag, td *declType, gr *Group, done map[string]bool, anns ...*Annotation) {873 var refImp string874 anns = append(anns, gr.Annotation)875 if refName := bag.resolveQnameRef(gr.Ref.String(), "", &refImp); !done[refName] {876 if done[refName] = true; len(refImp) > 0 {877 if !strings.HasPrefix(refName, bag.impName+"."+idPrefix) {878 td.addEmbed(gr, refImp+"."+idPrefix+"HasGroup_"+refName[(len(refImp)+1):], anns...)879 }880 } else {881 td.addEmbed(gr, idPrefix+"HasGroup_"+refName, anns...)882 }883 }884} ...

Full Screen

Full Screen

dns_client_test.go

Source:dns_client_test.go Github

copy

Full Screen

...22 name: "Resolve dns.google - incomplete FQDN",23 args: args{24 host: "dns.google",25 },26 wantRes: td.SuperBagOf(td.Code(func(ip net.IP) bool {27 return ip.Equal(net.IPv4(8, 8, 8, 8))28 })),29 wantErr: false,30 },31 {32 name: "Resolve dns.google - complete FQDN",33 args: args{34 host: "dns.google.",35 },36 wantRes: td.SuperBagOf(td.Code(func(ip net.IP) bool {37 return ip.Equal(net.IPv4(8, 8, 8, 8))38 })),39 wantErr: false,40 },41 {42 name: "Resolve one.one.one.one",43 args: args{44 host: "one.one.one.one",45 },46 wantRes: td.SuperBagOf(td.Code(func(ip net.IP) bool {47 return ip.Equal(net.IPv4(1, 1, 1, 1))48 })),49 wantErr: false,50 },51 {52 name: "Resolve dns9.quad9.net",53 args: args{54 host: "dns9.quad9.net",55 },56 wantRes: td.SuperBagOf(td.Code(func(ip net.IP) bool {57 return ip.Equal(net.IPv4(9, 9, 9, 9))58 })),59 wantErr: false,60 },61 }62 for _, tt := range tests {63 tt := tt64 t.Run(tt.name, func(t *testing.T) {65 t.Parallel()66 r := client.Resolver{67 Transport: &client.TraditionalTransport{68 Network: "tcp",69 Address: "9.9.9.9:53",70 },71 }72 ctx, cancel := context.WithCancel(context.Background())73 t.Cleanup(cancel)74 var gotRes []net.IP75 err := retry(resolveRetries, func() (err error) {76 gotRes, err = r.LookupA(ctx, tt.args.host)77 return78 })79 if (err != nil) != tt.wantErr {80 t.Errorf("LookupA() error = %v, wantErr %v", err, tt.wantErr)81 return82 }83 td.Cmp(t, gotRes, tt.wantRes)84 })85 }86}87func TestResolver_LookupAAAA(t *testing.T) {88 t.Parallel()89 type args struct {90 host string91 }92 tests := []struct {93 name string94 args args95 wantRes interface{}96 wantErr bool97 }{98 {99 name: "Resolve dns.google - incomplete FQDN",100 args: args{101 host: "dns.google",102 },103 wantRes: td.SuperBagOf(td.Code(func(ip net.IP) bool {104 return ip.Equal(net.ParseIP("2001:4860:4860::8888"))105 })),106 wantErr: false,107 },108 {109 name: "Resolve dns.google - complete FQDN",110 args: args{111 host: "dns.google.",112 },113 wantRes: td.SuperBagOf(td.Code(func(ip net.IP) bool {114 return ip.Equal(net.ParseIP("2001:4860:4860::8888"))115 })),116 wantErr: false,117 },118 {119 name: "Resolve one.one.one.one",120 args: args{121 host: "one.one.one.one",122 },123 wantRes: td.SuperBagOf(td.Code(func(ip net.IP) bool {124 return ip.Equal(net.ParseIP("2606:4700:4700::1111"))125 })),126 wantErr: false,127 },128 {129 name: "Resolve dns9.quad9.net",130 args: args{131 host: "dns9.quad9.net",132 },133 wantRes: td.SuperBagOf(td.Code(func(ip net.IP) bool {134 return ip.Equal(net.ParseIP("2620:fe::fe:9"))135 })),136 wantErr: false,137 },138 }139 for _, tt := range tests {140 tt := tt141 t.Run(tt.name, func(t *testing.T) {142 t.Parallel()143 r := client.Resolver{144 Transport: &client.TraditionalTransport{145 Network: "tcp",146 Address: "9.9.9.9:53",147 },148 }149 ctx, cancel := context.WithCancel(context.Background())150 t.Cleanup(cancel)151 var gotResp []net.IP152 err := retry(resolveRetries, func() (err error) {153 gotResp, err = r.LookupAAAA(ctx, tt.args.host)154 return155 })156 if (err != nil) != tt.wantErr {157 t.Errorf("LookupAAAA() error = %v, wantErr %v", err, tt.wantErr)158 return159 }160 td.Cmp(t, gotResp, tt.wantRes)161 })162 }163}164func TestResolver_LookupPTR(t *testing.T) {165 t.Parallel()166 type args struct {167 inAddrArpa string168 }169 tests := []struct {170 name string171 args args172 wantRes interface{}173 wantErr bool174 }{175 {176 name: "Resolve PTR 8.8.8.8 - invalid PTR syntax",177 args: args{178 inAddrArpa: "8.8.8.8",179 },180 wantRes: td.SuperBagOf("dns.google."),181 wantErr: false,182 },183 {184 name: "Resolve PTR 8.8.8.8 - valid PTR syntax",185 args: args{186 inAddrArpa: "8.8.8.8.in-addr.arpa",187 },188 wantRes: td.SuperBagOf("dns.google."),189 wantErr: false,190 },191 {192 name: "Resolve PTR 9.9.9.9",193 args: args{194 inAddrArpa: "9.9.9.9",195 },196 wantRes: td.SuperBagOf("dns9.quad9.net."),197 wantErr: false,198 },199 {200 name: "Resolve PTR 1.1.1.1",201 args: args{202 inAddrArpa: "1.1.1.1",203 },204 wantRes: td.SuperBagOf("one.one.one.one."),205 wantErr: false,206 },207 }208 for _, tt := range tests {209 tt := tt210 t.Run(tt.name, func(t *testing.T) {211 t.Parallel()212 r := client.Resolver{213 Transport: &client.TraditionalTransport{214 Network: "tcp",215 Address: "9.9.9.9:53",216 },217 }218 ctx, cancel := context.WithCancel(context.Background())...

Full Screen

Full Screen

Bag

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 td := new(Td)4 td.Add(1)5 td.Add(2)6 td.Add(3)7 td.Add(4)8 td.Add(5)9 td.Add(6)10 td.Add(7)11 td.Add(8)12 td.Add(9)13 td.Add(10)14 td.Add(11)15 td.Add(12)16 td.Add(13)17 td.Add(14)18 td.Add(15)19 td.Add(16)20 td.Add(17)21 td.Add(18)22 td.Add(19)23 td.Add(20)24 td.Add(21)25 td.Add(22)26 td.Add(23)27 td.Add(24)28 td.Add(25)29 td.Add(26)30 td.Add(27)31 td.Add(28)32 td.Add(29)33 td.Add(30)34 td.Add(31)35 td.Add(32)36 td.Add(33)37 td.Add(34)38 td.Add(35)39 td.Add(36)40 td.Add(37)41 td.Add(38)42 td.Add(39)43 td.Add(40)44 td.Add(41)45 td.Add(42)46 td.Add(43)47 td.Add(44)48 td.Add(45)49 td.Add(46)50 td.Add(47)51 td.Add(48)52 td.Add(49)53 td.Add(50)54 td.Add(51)55 td.Add(52)56 td.Add(53)57 td.Add(54)58 td.Add(55)59 td.Add(56)60 td.Add(57)61 td.Add(58)62 td.Add(59)63 td.Add(60)64 td.Add(61)65 td.Add(62)66 td.Add(63)67 td.Add(64)68 td.Add(65)69 td.Add(66)70 td.Add(67)71 td.Add(68)72 td.Add(69)73 td.Add(70)74 td.Add(71)75 td.Add(72)76 td.Add(73)77 td.Add(74)78 td.Add(75)79 td.Add(76)80 td.Add(77)81 td.Add(78)82 td.Add(79)83 td.Add(80)

Full Screen

Full Screen

Bag

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 b = NewBag()4 b.Add(1)5 b.Add(2)6 b.Add(3)7 b.Add(4)8 b.Add(5)9 b.Add(6)10 b.Add(7)11 b.Add(8)12 b.Add(9)13 b.Add(10)14 b.Add(11)15 b.Add(12)16 b.Add(13)17 b.Add(14)18 b.Add(15)19 b.Add(16)20 b.Add(17)21 b.Add(18)22 b.Add(19)23 b.Add(20)24 b.Add(21)25 b.Add(22)26 b.Add(23)27 b.Add(24)28 b.Add(25)29 b.Add(26)30 b.Add(27)31 b.Add(28)32 b.Add(29)33 b.Add(30)34 b.Add(31)35 b.Add(32)36 b.Add(33)37 b.Add(34)38 b.Add(35)39 b.Add(36)40 b.Add(37)41 b.Add(38)42 b.Add(39)43 b.Add(40)44 b.Add(41)45 b.Add(42)46 b.Add(43)47 b.Add(44)48 b.Add(45)49 b.Add(46)50 b.Add(47)51 b.Add(48)52 b.Add(49)53 b.Add(50)54 b.Add(51)55 b.Add(52)56 b.Add(53)57 b.Add(54)58 b.Add(55)59 b.Add(56)60 b.Add(57)61 b.Add(58)62 b.Add(59)63 b.Add(60)64 b.Add(61)65 b.Add(62)66 b.Add(63)67 b.Add(64)68 b.Add(65)69 b.Add(66)70 b.Add(67)71 b.Add(68)72 b.Add(69)73 b.Add(70)74 b.Add(71)75 b.Add(72)76 b.Add(73)77 b.Add(74)78 b.Add(75)79 b.Add(76)80 b.Add(77)81 b.Add(78)82 b.Add(79)

Full Screen

Full Screen

Bag

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conn := redigomock.NewConn()4 conn.Command("SET", "foo", "bar").Expect("OK")5 conn.Command("GET", "foo").Expect("bar")6 conn.Command("GET", "bar").ExpectError(fmt.Errorf("not found"))7 conn.Command("SET", "foo", "bar").Expect("OK")8 conn.Command("GET", "foo").Expect("bar")9 conn.Command("GET", "bar").ExpectError(fmt.Errorf("not found"))10 conn.Command("SET", "foo", "bar").Expect("OK")11 conn.Command("GET", "foo").Expect("bar")12 conn.Command("GET", "bar").ExpectError(fmt.Errorf("not found"))13 conn.Command("SET", "foo", "bar").Expect("OK")14 conn.Command("GET", "foo").Expect("bar")15 conn.Command("GET", "bar").ExpectError(fmt.Errorf("not found"))16 conn.Command("SET", "foo", "bar").Expect("OK")17 conn.Command("GET", "foo").Expect("bar")18 conn.Command("GET", "bar").ExpectError(fmt.Errorf("not found"))19 conn.Command("SET", "foo", "bar").Expect("OK")20 conn.Command("GET", "foo").Expect("bar")21 conn.Command("GET", "bar").ExpectError(fmt.Errorf("not found"))22 conn.Command("SET", "foo", "bar").Expect("OK")23 conn.Command("GET", "foo").Expect("bar")24 conn.Command("GET", "bar").ExpectError(fmt.Errorf("not found"))25 conn.Command("SET", "foo", "bar").Expect("OK")26 conn.Command("GET", "foo").Expect("bar")27 conn.Command("GET", "bar").ExpectError(fmt.Errorf("not found"))28 conn.Command("SET", "foo", "bar").Expect("OK")29 conn.Command("GET", "foo").Expect("bar")30 conn.Command("GET", "bar").ExpectError(fmt.Errorf("not found"))31 conn.Command("SET", "foo", "bar").Expect("OK")32 conn.Command("GET", "foo").Expect("bar")

Full Screen

Full Screen

Bag

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 b.Add(1)4 b.Add(2)5 b.Add(3)6 for b.More() {7 fmt.Println(b.Next())8 }9}10import (11type Bag struct {12 data []interface{}13}14func (b *Bag) Add(x interface{}) {15 b.data = append(b.data, x)16}17func (b *Bag) More() bool {18 return len(b.data) > 019}20func (b *Bag) Next() interface{} {21}22func (b *Bag) Print() {23 for _, x := range b.data {24 fmt.Println(x)25 }26}27import (28func main() {29 b.Add(1)30 b.Add(2)31 b.Add(3)32 for b.More() {33 fmt.Println(b.Next())34 }35}

Full Screen

Full Screen

Bag

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(td.Bag())4}5import (6func main() {7 fmt.Println(td.Bag())8}9import (10func main() {11 fmt.Println(td.Bag())12}

Full Screen

Full Screen

Bag

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 td := NewTrie()4 td.Insert("hello")5 td.Insert("world")6 td.Insert("how")7 td.Insert("are")8 td.Insert("you")9 td.Insert("today")10 fmt.Println(td.Bag("hel"))11 fmt.Println(td.Bag("w"))12 fmt.Println(td.Bag("h"))13 fmt.Println(td.Bag("a"))14 fmt.Println(td.Bag("t"))15 fmt.Println(td.Bag("y"))16 fmt.Println(td.Bag("to"))17 fmt.Println(td.Bag("q"))18 fmt.Println(td.Bag("wq"))19}20import (21func main() {22 td := NewTrie()23 td.Insert("hello")24 td.Insert("world")25 td.Insert("how")26 td.Insert("are")27 td.Insert("you")28 td.Insert("today")29 fmt.Println(td.Remove("hel"))30 fmt.Println(td.Remove("w"))31 fmt.Println(td.Remove("h"))32 fmt.Println(td.Remove("a"))33 fmt.Println(td.Remove("t"))34 fmt.Println(td.Remove("y"))35 fmt.Println(td.Remove("to"))36 fmt.Println(td.Remove("q"))37 fmt.Println(td.Remove("wq"))38}39import (40func main() {41 td := NewTrie()42 td.Insert("hello")43 td.Insert("world")44 td.Insert("how")45 td.Insert("are")46 td.Insert("you")47 td.Insert("today")48 td.Print()49}50import (51func main() {52 td := NewTrie()53 td.Insert("hello")54 td.Insert("world")55 td.Insert("how")56 td.Insert("are")57 td.Insert("you

Full Screen

Full Screen

Bag

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 b := td.NewBag()4 b.Add("Hello")5 b.Add("World")6 b.Add("!")7 fmt.Println(b)8}9import (10func main() {11 b := td.NewBag()12 b.Add("Hello")13 b.Add("World")14 b.Add("!")15 fmt.Println(b)16 b2 := td.NewBag()17 b2.Add("Hello")18 b2.Add("World")19 b2.Add("!")20 fmt.Println(b2)21}22import (23func main() {24 b := td.NewBag()25 b.Add("Hello")26 b.Add("World")27 b.Add("!")28 fmt.Println(b)29 b2 := td.NewBag()30 b2.Add("Hello")31 b2.Add("World")32 b2.Add("!")33 fmt.Println(b2)34 b.Add(b2)35 fmt.Println(b)36}37import (38func main() {39 b := td.NewBag()40 b.Add("Hello")41 b.Add("World")42 b.Add("!")43 fmt.Println(b)44 b2 := td.NewBag()45 b2.Add("Hello")46 b2.Add("World")47 b2.Add("!")48 fmt.Println(b2)49 b.Add(b2)50 fmt.Println(b)51 b3 := td.NewBag()52 b3.Add("Hello")53 b3.Add("World")

Full Screen

Full Screen

Bag

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 td := tribbler.NewTribblerDaemon()4 td.Start()5 td.Register("user1")6 td.Register("user2")7 td.Register("user3")8 td.Register("user4")9 td.Register("user5")10 td.Post("user1", "Hello, World!", tribbler.NewPost())11 td.Post("user2", "Hello, World!", tribbler.NewPost())12 td.Post("user3", "Hello, World!", tribbler.NewPost())13 td.Post("user4", "Hello, World!", tribbler.NewPost())14 td.Post("user5", "Hello, World!", tribbler.NewPost())15 td.Follow("user1", "user2")16 td.Follow("user1", "user3")17 td.Follow("user1", "user4")18 td.Follow("user1", "user5")19 td.Follow("user2", "user1")20 td.Follow("user2", "user3")21 td.Follow("user2", "user4")22 td.Follow("user2", "user5")23 td.Follow("user3", "user1")24 td.Follow("user3", "user2")25 td.Follow("user3", "user4")26 td.Follow("user3", "user5")27 td.Follow("user4", "user1")28 td.Follow("user4", "user2")29 td.Follow("user4", "user3")30 td.Follow("user4", "user5")31 td.Follow("user5", "user1")32 td.Follow("user5", "u

Full Screen

Full Screen

Bag

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 b := tdclass.NewBag()4 b.Add(1)5 b.Add(2)6 b.Add(3)7 fmt.Println(b)8}9import (10func main() {11 s := tdclass.NewStack()12 s.Push(1)13 s.Push(2)14 s.Push(3)15 fmt.Println(s)16 fmt.Println(s.Pop())17 fmt.Println(s.Pop())18 fmt.Println(s.Pop())19}20import (21func main() {22 q := tdclass.NewQueue()23 q.Enqueue(1)24 q.Enqueue(2)25 q.Enqueue(3)26 fmt.Println(q)27 fmt.Println(q.Dequeue())28 fmt.Println(q.Dequeue())29 fmt.Println(q.Dequeue())30}31import (32func main() {33 l := tdclass.NewLinkedList()34 l.Add(1)35 l.Add(2)36 l.Add(3)37 fmt.Println(l)38 fmt.Println(l.Remove(2))39 fmt.Println(l.Remove(1))40 fmt.Println(l.Remove(3))41}42import (43func main() {44 s := tdclass.NewStack()45 s.Push(1)46 s.Push(2)47 s.Push(3)48 fmt.Println(s)49 fmt.Println(s.Pop())50 fmt.Println(s.Pop())51 fmt.Println(s.Pop())52}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Go-testdeep automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful