How to use Anchor method of td Package

Best Go-testdeep code snippet using td.Anchor

richText.go

Source:richText.go Github

copy

Full Screen

...25 RichTextMarkedType RichTextEnum = "richTextMarked"26 RichTextPhoneNumberType RichTextEnum = "richTextPhoneNumber"27 RichTextIconType RichTextEnum = "richTextIcon"28 RichTextReferenceType RichTextEnum = "richTextReference"29 RichTextAnchorType RichTextEnum = "richTextAnchor"30 RichTextAnchorLinkType RichTextEnum = "richTextAnchorLink"31 RichTextsType RichTextEnum = "richTexts"32)33func unmarshalRichText(rawMsg *json.RawMessage) (RichText, error) {34 if rawMsg == nil {35 return nil, nil36 }37 var objMap map[string]interface{}38 err := json.Unmarshal(*rawMsg, &objMap)39 if err != nil {40 return nil, err41 }42 switch RichTextEnum(objMap["@type"].(string)) {43 case RichTextPlainType:44 var richTextPlain RichTextPlain45 err := json.Unmarshal(*rawMsg, &richTextPlain)46 return &richTextPlain, err47 case RichTextBoldType:48 var richTextBold RichTextBold49 err := json.Unmarshal(*rawMsg, &richTextBold)50 return &richTextBold, err51 case RichTextItalicType:52 var richTextItalic RichTextItalic53 err := json.Unmarshal(*rawMsg, &richTextItalic)54 return &richTextItalic, err55 case RichTextUnderlineType:56 var richTextUnderline RichTextUnderline57 err := json.Unmarshal(*rawMsg, &richTextUnderline)58 return &richTextUnderline, err59 case RichTextStrikethroughType:60 var richTextStrikethrough RichTextStrikethrough61 err := json.Unmarshal(*rawMsg, &richTextStrikethrough)62 return &richTextStrikethrough, err63 case RichTextFixedType:64 var richTextFixed RichTextFixed65 err := json.Unmarshal(*rawMsg, &richTextFixed)66 return &richTextFixed, err67 case RichTextURLType:68 var richTextURL RichTextURL69 err := json.Unmarshal(*rawMsg, &richTextURL)70 return &richTextURL, err71 case RichTextEmailAddressType:72 var richTextEmailAddress RichTextEmailAddress73 err := json.Unmarshal(*rawMsg, &richTextEmailAddress)74 return &richTextEmailAddress, err75 case RichTextSubscriptType:76 var richTextSubscript RichTextSubscript77 err := json.Unmarshal(*rawMsg, &richTextSubscript)78 return &richTextSubscript, err79 case RichTextSuperscriptType:80 var richTextSuperscript RichTextSuperscript81 err := json.Unmarshal(*rawMsg, &richTextSuperscript)82 return &richTextSuperscript, err83 case RichTextMarkedType:84 var richTextMarked RichTextMarked85 err := json.Unmarshal(*rawMsg, &richTextMarked)86 return &richTextMarked, err87 case RichTextPhoneNumberType:88 var richTextPhoneNumber RichTextPhoneNumber89 err := json.Unmarshal(*rawMsg, &richTextPhoneNumber)90 return &richTextPhoneNumber, err91 case RichTextIconType:92 var richTextIcon RichTextIcon93 err := json.Unmarshal(*rawMsg, &richTextIcon)94 return &richTextIcon, err95 case RichTextReferenceType:96 var richTextReference RichTextReference97 err := json.Unmarshal(*rawMsg, &richTextReference)98 return &richTextReference, err99 case RichTextAnchorType:100 var richTextAnchor RichTextAnchor101 err := json.Unmarshal(*rawMsg, &richTextAnchor)102 return &richTextAnchor, err103 case RichTextAnchorLinkType:104 var richTextAnchorLink RichTextAnchorLink105 err := json.Unmarshal(*rawMsg, &richTextAnchorLink)106 return &richTextAnchorLink, err107 case RichTextsType:108 var richTexts RichTexts109 err := json.Unmarshal(*rawMsg, &richTexts)110 return &richTexts, err111 default:112 return nil, fmt.Errorf("Error UnMarshaling, unknown type:" + objMap["@type"].(string))113 }114}115// RichTextPlain A plain text116type RichTextPlain struct {117 tdCommon118 Text string `json:"text"` // Text119}120// MessageType return the string telegram-type of RichTextPlain121func (richTextPlain *RichTextPlain) MessageType() string {122 return "richTextPlain"123}124// NewRichTextPlain creates a new RichTextPlain125//126// @param text Text127func NewRichTextPlain(text string) *RichTextPlain {128 richTextPlainTemp := RichTextPlain{129 tdCommon: tdCommon{Type: "richTextPlain"},130 Text: text,131 }132 return &richTextPlainTemp133}134// GetRichTextEnum return the enum type of this object135func (richTextPlain *RichTextPlain) GetRichTextEnum() RichTextEnum {136 return RichTextPlainType137}138// RichTextBold A bold rich text139type RichTextBold struct {140 tdCommon141 Text RichText `json:"text"` // Text142}143// MessageType return the string telegram-type of RichTextBold144func (richTextBold *RichTextBold) MessageType() string {145 return "richTextBold"146}147// NewRichTextBold creates a new RichTextBold148//149// @param text Text150func NewRichTextBold(text RichText) *RichTextBold {151 richTextBoldTemp := RichTextBold{152 tdCommon: tdCommon{Type: "richTextBold"},153 Text: text,154 }155 return &richTextBoldTemp156}157// UnmarshalJSON unmarshal to json158func (richTextBold *RichTextBold) UnmarshalJSON(b []byte) error {159 var objMap map[string]*json.RawMessage160 err := json.Unmarshal(b, &objMap)161 if err != nil {162 return err163 }164 tempObj := struct {165 tdCommon166 }{}167 err = json.Unmarshal(b, &tempObj)168 if err != nil {169 return err170 }171 richTextBold.tdCommon = tempObj.tdCommon172 fieldText, _ := unmarshalRichText(objMap["text"])173 richTextBold.Text = fieldText174 return nil175}176// GetRichTextEnum return the enum type of this object177func (richTextBold *RichTextBold) GetRichTextEnum() RichTextEnum {178 return RichTextBoldType179}180// RichTextItalic An italicized rich text181type RichTextItalic struct {182 tdCommon183 Text RichText `json:"text"` // Text184}185// MessageType return the string telegram-type of RichTextItalic186func (richTextItalic *RichTextItalic) MessageType() string {187 return "richTextItalic"188}189// NewRichTextItalic creates a new RichTextItalic190//191// @param text Text192func NewRichTextItalic(text RichText) *RichTextItalic {193 richTextItalicTemp := RichTextItalic{194 tdCommon: tdCommon{Type: "richTextItalic"},195 Text: text,196 }197 return &richTextItalicTemp198}199// UnmarshalJSON unmarshal to json200func (richTextItalic *RichTextItalic) UnmarshalJSON(b []byte) error {201 var objMap map[string]*json.RawMessage202 err := json.Unmarshal(b, &objMap)203 if err != nil {204 return err205 }206 tempObj := struct {207 tdCommon208 }{}209 err = json.Unmarshal(b, &tempObj)210 if err != nil {211 return err212 }213 richTextItalic.tdCommon = tempObj.tdCommon214 fieldText, _ := unmarshalRichText(objMap["text"])215 richTextItalic.Text = fieldText216 return nil217}218// GetRichTextEnum return the enum type of this object219func (richTextItalic *RichTextItalic) GetRichTextEnum() RichTextEnum {220 return RichTextItalicType221}222// RichTextUnderline An underlined rich text223type RichTextUnderline struct {224 tdCommon225 Text RichText `json:"text"` // Text226}227// MessageType return the string telegram-type of RichTextUnderline228func (richTextUnderline *RichTextUnderline) MessageType() string {229 return "richTextUnderline"230}231// NewRichTextUnderline creates a new RichTextUnderline232//233// @param text Text234func NewRichTextUnderline(text RichText) *RichTextUnderline {235 richTextUnderlineTemp := RichTextUnderline{236 tdCommon: tdCommon{Type: "richTextUnderline"},237 Text: text,238 }239 return &richTextUnderlineTemp240}241// UnmarshalJSON unmarshal to json242func (richTextUnderline *RichTextUnderline) UnmarshalJSON(b []byte) error {243 var objMap map[string]*json.RawMessage244 err := json.Unmarshal(b, &objMap)245 if err != nil {246 return err247 }248 tempObj := struct {249 tdCommon250 }{}251 err = json.Unmarshal(b, &tempObj)252 if err != nil {253 return err254 }255 richTextUnderline.tdCommon = tempObj.tdCommon256 fieldText, _ := unmarshalRichText(objMap["text"])257 richTextUnderline.Text = fieldText258 return nil259}260// GetRichTextEnum return the enum type of this object261func (richTextUnderline *RichTextUnderline) GetRichTextEnum() RichTextEnum {262 return RichTextUnderlineType263}264// RichTextStrikethrough A strikethrough rich text265type RichTextStrikethrough struct {266 tdCommon267 Text RichText `json:"text"` // Text268}269// MessageType return the string telegram-type of RichTextStrikethrough270func (richTextStrikethrough *RichTextStrikethrough) MessageType() string {271 return "richTextStrikethrough"272}273// NewRichTextStrikethrough creates a new RichTextStrikethrough274//275// @param text Text276func NewRichTextStrikethrough(text RichText) *RichTextStrikethrough {277 richTextStrikethroughTemp := RichTextStrikethrough{278 tdCommon: tdCommon{Type: "richTextStrikethrough"},279 Text: text,280 }281 return &richTextStrikethroughTemp282}283// UnmarshalJSON unmarshal to json284func (richTextStrikethrough *RichTextStrikethrough) UnmarshalJSON(b []byte) error {285 var objMap map[string]*json.RawMessage286 err := json.Unmarshal(b, &objMap)287 if err != nil {288 return err289 }290 tempObj := struct {291 tdCommon292 }{}293 err = json.Unmarshal(b, &tempObj)294 if err != nil {295 return err296 }297 richTextStrikethrough.tdCommon = tempObj.tdCommon298 fieldText, _ := unmarshalRichText(objMap["text"])299 richTextStrikethrough.Text = fieldText300 return nil301}302// GetRichTextEnum return the enum type of this object303func (richTextStrikethrough *RichTextStrikethrough) GetRichTextEnum() RichTextEnum {304 return RichTextStrikethroughType305}306// RichTextFixed A fixed-width rich text307type RichTextFixed struct {308 tdCommon309 Text RichText `json:"text"` // Text310}311// MessageType return the string telegram-type of RichTextFixed312func (richTextFixed *RichTextFixed) MessageType() string {313 return "richTextFixed"314}315// NewRichTextFixed creates a new RichTextFixed316//317// @param text Text318func NewRichTextFixed(text RichText) *RichTextFixed {319 richTextFixedTemp := RichTextFixed{320 tdCommon: tdCommon{Type: "richTextFixed"},321 Text: text,322 }323 return &richTextFixedTemp324}325// UnmarshalJSON unmarshal to json326func (richTextFixed *RichTextFixed) UnmarshalJSON(b []byte) error {327 var objMap map[string]*json.RawMessage328 err := json.Unmarshal(b, &objMap)329 if err != nil {330 return err331 }332 tempObj := struct {333 tdCommon334 }{}335 err = json.Unmarshal(b, &tempObj)336 if err != nil {337 return err338 }339 richTextFixed.tdCommon = tempObj.tdCommon340 fieldText, _ := unmarshalRichText(objMap["text"])341 richTextFixed.Text = fieldText342 return nil343}344// GetRichTextEnum return the enum type of this object345func (richTextFixed *RichTextFixed) GetRichTextEnum() RichTextEnum {346 return RichTextFixedType347}348// RichTextURL A rich text URL link349type RichTextURL struct {350 tdCommon351 Text RichText `json:"text"` // Text352 URL string `json:"url"` // URL353 IsCached bool `json:"is_cached"` // True, if the URL has cached instant view server-side354}355// MessageType return the string telegram-type of RichTextURL356func (richTextURL *RichTextURL) MessageType() string {357 return "richTextUrl"358}359// NewRichTextURL creates a new RichTextURL360//361// @param text Text362// @param uRL URL363// @param isCached True, if the URL has cached instant view server-side364func NewRichTextURL(text RichText, uRL string, isCached bool) *RichTextURL {365 richTextURLTemp := RichTextURL{366 tdCommon: tdCommon{Type: "richTextUrl"},367 Text: text,368 URL: uRL,369 IsCached: isCached,370 }371 return &richTextURLTemp372}373// UnmarshalJSON unmarshal to json374func (richTextURL *RichTextURL) UnmarshalJSON(b []byte) error {375 var objMap map[string]*json.RawMessage376 err := json.Unmarshal(b, &objMap)377 if err != nil {378 return err379 }380 tempObj := struct {381 tdCommon382 URL string `json:"url"` // URL383 IsCached bool `json:"is_cached"` // True, if the URL has cached instant view server-side384 }{}385 err = json.Unmarshal(b, &tempObj)386 if err != nil {387 return err388 }389 richTextURL.tdCommon = tempObj.tdCommon390 richTextURL.URL = tempObj.URL391 richTextURL.IsCached = tempObj.IsCached392 fieldText, _ := unmarshalRichText(objMap["text"])393 richTextURL.Text = fieldText394 return nil395}396// GetRichTextEnum return the enum type of this object397func (richTextURL *RichTextURL) GetRichTextEnum() RichTextEnum {398 return RichTextURLType399}400// RichTextEmailAddress A rich text email link401type RichTextEmailAddress struct {402 tdCommon403 Text RichText `json:"text"` // Text404 EmailAddress string `json:"email_address"` // Email address405}406// MessageType return the string telegram-type of RichTextEmailAddress407func (richTextEmailAddress *RichTextEmailAddress) MessageType() string {408 return "richTextEmailAddress"409}410// NewRichTextEmailAddress creates a new RichTextEmailAddress411//412// @param text Text413// @param emailAddress Email address414func NewRichTextEmailAddress(text RichText, emailAddress string) *RichTextEmailAddress {415 richTextEmailAddressTemp := RichTextEmailAddress{416 tdCommon: tdCommon{Type: "richTextEmailAddress"},417 Text: text,418 EmailAddress: emailAddress,419 }420 return &richTextEmailAddressTemp421}422// UnmarshalJSON unmarshal to json423func (richTextEmailAddress *RichTextEmailAddress) UnmarshalJSON(b []byte) error {424 var objMap map[string]*json.RawMessage425 err := json.Unmarshal(b, &objMap)426 if err != nil {427 return err428 }429 tempObj := struct {430 tdCommon431 EmailAddress string `json:"email_address"` // Email address432 }{}433 err = json.Unmarshal(b, &tempObj)434 if err != nil {435 return err436 }437 richTextEmailAddress.tdCommon = tempObj.tdCommon438 richTextEmailAddress.EmailAddress = tempObj.EmailAddress439 fieldText, _ := unmarshalRichText(objMap["text"])440 richTextEmailAddress.Text = fieldText441 return nil442}443// GetRichTextEnum return the enum type of this object444func (richTextEmailAddress *RichTextEmailAddress) GetRichTextEnum() RichTextEnum {445 return RichTextEmailAddressType446}447// RichTextSubscript A subscript rich text448type RichTextSubscript struct {449 tdCommon450 Text RichText `json:"text"` // Text451}452// MessageType return the string telegram-type of RichTextSubscript453func (richTextSubscript *RichTextSubscript) MessageType() string {454 return "richTextSubscript"455}456// NewRichTextSubscript creates a new RichTextSubscript457//458// @param text Text459func NewRichTextSubscript(text RichText) *RichTextSubscript {460 richTextSubscriptTemp := RichTextSubscript{461 tdCommon: tdCommon{Type: "richTextSubscript"},462 Text: text,463 }464 return &richTextSubscriptTemp465}466// UnmarshalJSON unmarshal to json467func (richTextSubscript *RichTextSubscript) UnmarshalJSON(b []byte) error {468 var objMap map[string]*json.RawMessage469 err := json.Unmarshal(b, &objMap)470 if err != nil {471 return err472 }473 tempObj := struct {474 tdCommon475 }{}476 err = json.Unmarshal(b, &tempObj)477 if err != nil {478 return err479 }480 richTextSubscript.tdCommon = tempObj.tdCommon481 fieldText, _ := unmarshalRichText(objMap["text"])482 richTextSubscript.Text = fieldText483 return nil484}485// GetRichTextEnum return the enum type of this object486func (richTextSubscript *RichTextSubscript) GetRichTextEnum() RichTextEnum {487 return RichTextSubscriptType488}489// RichTextSuperscript A superscript rich text490type RichTextSuperscript struct {491 tdCommon492 Text RichText `json:"text"` // Text493}494// MessageType return the string telegram-type of RichTextSuperscript495func (richTextSuperscript *RichTextSuperscript) MessageType() string {496 return "richTextSuperscript"497}498// NewRichTextSuperscript creates a new RichTextSuperscript499//500// @param text Text501func NewRichTextSuperscript(text RichText) *RichTextSuperscript {502 richTextSuperscriptTemp := RichTextSuperscript{503 tdCommon: tdCommon{Type: "richTextSuperscript"},504 Text: text,505 }506 return &richTextSuperscriptTemp507}508// UnmarshalJSON unmarshal to json509func (richTextSuperscript *RichTextSuperscript) UnmarshalJSON(b []byte) error {510 var objMap map[string]*json.RawMessage511 err := json.Unmarshal(b, &objMap)512 if err != nil {513 return err514 }515 tempObj := struct {516 tdCommon517 }{}518 err = json.Unmarshal(b, &tempObj)519 if err != nil {520 return err521 }522 richTextSuperscript.tdCommon = tempObj.tdCommon523 fieldText, _ := unmarshalRichText(objMap["text"])524 richTextSuperscript.Text = fieldText525 return nil526}527// GetRichTextEnum return the enum type of this object528func (richTextSuperscript *RichTextSuperscript) GetRichTextEnum() RichTextEnum {529 return RichTextSuperscriptType530}531// RichTextMarked A marked rich text532type RichTextMarked struct {533 tdCommon534 Text RichText `json:"text"` // Text535}536// MessageType return the string telegram-type of RichTextMarked537func (richTextMarked *RichTextMarked) MessageType() string {538 return "richTextMarked"539}540// NewRichTextMarked creates a new RichTextMarked541//542// @param text Text543func NewRichTextMarked(text RichText) *RichTextMarked {544 richTextMarkedTemp := RichTextMarked{545 tdCommon: tdCommon{Type: "richTextMarked"},546 Text: text,547 }548 return &richTextMarkedTemp549}550// UnmarshalJSON unmarshal to json551func (richTextMarked *RichTextMarked) UnmarshalJSON(b []byte) error {552 var objMap map[string]*json.RawMessage553 err := json.Unmarshal(b, &objMap)554 if err != nil {555 return err556 }557 tempObj := struct {558 tdCommon559 }{}560 err = json.Unmarshal(b, &tempObj)561 if err != nil {562 return err563 }564 richTextMarked.tdCommon = tempObj.tdCommon565 fieldText, _ := unmarshalRichText(objMap["text"])566 richTextMarked.Text = fieldText567 return nil568}569// GetRichTextEnum return the enum type of this object570func (richTextMarked *RichTextMarked) GetRichTextEnum() RichTextEnum {571 return RichTextMarkedType572}573// RichTextPhoneNumber A rich text phone number574type RichTextPhoneNumber struct {575 tdCommon576 Text RichText `json:"text"` // Text577 PhoneNumber string `json:"phone_number"` // Phone number578}579// MessageType return the string telegram-type of RichTextPhoneNumber580func (richTextPhoneNumber *RichTextPhoneNumber) MessageType() string {581 return "richTextPhoneNumber"582}583// NewRichTextPhoneNumber creates a new RichTextPhoneNumber584//585// @param text Text586// @param phoneNumber Phone number587func NewRichTextPhoneNumber(text RichText, phoneNumber string) *RichTextPhoneNumber {588 richTextPhoneNumberTemp := RichTextPhoneNumber{589 tdCommon: tdCommon{Type: "richTextPhoneNumber"},590 Text: text,591 PhoneNumber: phoneNumber,592 }593 return &richTextPhoneNumberTemp594}595// UnmarshalJSON unmarshal to json596func (richTextPhoneNumber *RichTextPhoneNumber) UnmarshalJSON(b []byte) error {597 var objMap map[string]*json.RawMessage598 err := json.Unmarshal(b, &objMap)599 if err != nil {600 return err601 }602 tempObj := struct {603 tdCommon604 PhoneNumber string `json:"phone_number"` // Phone number605 }{}606 err = json.Unmarshal(b, &tempObj)607 if err != nil {608 return err609 }610 richTextPhoneNumber.tdCommon = tempObj.tdCommon611 richTextPhoneNumber.PhoneNumber = tempObj.PhoneNumber612 fieldText, _ := unmarshalRichText(objMap["text"])613 richTextPhoneNumber.Text = fieldText614 return nil615}616// GetRichTextEnum return the enum type of this object617func (richTextPhoneNumber *RichTextPhoneNumber) GetRichTextEnum() RichTextEnum {618 return RichTextPhoneNumberType619}620// RichTextIcon A small image inside the text621type RichTextIcon struct {622 tdCommon623 Document *Document `json:"document"` // The image represented as a document. The image can be in GIF, JPEG or PNG format624 Width int32 `json:"width"` // Width of a bounding box in which the image should be shown; 0 if unknown625 Height int32 `json:"height"` // Height of a bounding box in which the image should be shown; 0 if unknown626}627// MessageType return the string telegram-type of RichTextIcon628func (richTextIcon *RichTextIcon) MessageType() string {629 return "richTextIcon"630}631// NewRichTextIcon creates a new RichTextIcon632//633// @param document The image represented as a document. The image can be in GIF, JPEG or PNG format634// @param width Width of a bounding box in which the image should be shown; 0 if unknown635// @param height Height of a bounding box in which the image should be shown; 0 if unknown636func NewRichTextIcon(document *Document, width int32, height int32) *RichTextIcon {637 richTextIconTemp := RichTextIcon{638 tdCommon: tdCommon{Type: "richTextIcon"},639 Document: document,640 Width: width,641 Height: height,642 }643 return &richTextIconTemp644}645// GetRichTextEnum return the enum type of this object646func (richTextIcon *RichTextIcon) GetRichTextEnum() RichTextEnum {647 return RichTextIconType648}649// RichTextReference A reference to a richTexts object on the same web page650type RichTextReference struct {651 tdCommon652 Text RichText `json:"text"` // The text653 AnchorName string `json:"anchor_name"` // The name of a richTextAnchor object, which is the first element of the target richTexts object654 URL string `json:"url"` // An HTTP URL, opening the reference655}656// MessageType return the string telegram-type of RichTextReference657func (richTextReference *RichTextReference) MessageType() string {658 return "richTextReference"659}660// NewRichTextReference creates a new RichTextReference661//662// @param text The text663// @param anchorName The name of a richTextAnchor object, which is the first element of the target richTexts object664// @param uRL An HTTP URL, opening the reference665func NewRichTextReference(text RichText, anchorName string, uRL string) *RichTextReference {666 richTextReferenceTemp := RichTextReference{667 tdCommon: tdCommon{Type: "richTextReference"},668 Text: text,669 AnchorName: anchorName,670 URL: uRL,671 }672 return &richTextReferenceTemp673}674// UnmarshalJSON unmarshal to json675func (richTextReference *RichTextReference) UnmarshalJSON(b []byte) error {676 var objMap map[string]*json.RawMessage677 err := json.Unmarshal(b, &objMap)678 if err != nil {679 return err680 }681 tempObj := struct {682 tdCommon683 AnchorName string `json:"anchor_name"` // The name of a richTextAnchor object, which is the first element of the target richTexts object684 URL string `json:"url"` // An HTTP URL, opening the reference685 }{}686 err = json.Unmarshal(b, &tempObj)687 if err != nil {688 return err689 }690 richTextReference.tdCommon = tempObj.tdCommon691 richTextReference.AnchorName = tempObj.AnchorName692 richTextReference.URL = tempObj.URL693 fieldText, _ := unmarshalRichText(objMap["text"])694 richTextReference.Text = fieldText695 return nil696}697// GetRichTextEnum return the enum type of this object698func (richTextReference *RichTextReference) GetRichTextEnum() RichTextEnum {699 return RichTextReferenceType700}701// RichTextAnchor An anchor702type RichTextAnchor struct {703 tdCommon704 Name string `json:"name"` // Anchor name705}706// MessageType return the string telegram-type of RichTextAnchor707func (richTextAnchor *RichTextAnchor) MessageType() string {708 return "richTextAnchor"709}710// NewRichTextAnchor creates a new RichTextAnchor711//712// @param name Anchor name713func NewRichTextAnchor(name string) *RichTextAnchor {714 richTextAnchorTemp := RichTextAnchor{715 tdCommon: tdCommon{Type: "richTextAnchor"},716 Name: name,717 }718 return &richTextAnchorTemp719}720// GetRichTextEnum return the enum type of this object721func (richTextAnchor *RichTextAnchor) GetRichTextEnum() RichTextEnum {722 return RichTextAnchorType723}724// RichTextAnchorLink A link to an anchor on the same web page725type RichTextAnchorLink struct {726 tdCommon727 Text RichText `json:"text"` // The link text728 AnchorName string `json:"anchor_name"` // The anchor name. If the name is empty, the link should bring back to top729 URL string `json:"url"` // An HTTP URL, opening the anchor730}731// MessageType return the string telegram-type of RichTextAnchorLink732func (richTextAnchorLink *RichTextAnchorLink) MessageType() string {733 return "richTextAnchorLink"734}735// NewRichTextAnchorLink creates a new RichTextAnchorLink736//737// @param text The link text738// @param anchorName The anchor name. If the name is empty, the link should bring back to top739// @param uRL An HTTP URL, opening the anchor740func NewRichTextAnchorLink(text RichText, anchorName string, uRL string) *RichTextAnchorLink {741 richTextAnchorLinkTemp := RichTextAnchorLink{742 tdCommon: tdCommon{Type: "richTextAnchorLink"},743 Text: text,744 AnchorName: anchorName,745 URL: uRL,746 }747 return &richTextAnchorLinkTemp748}749// UnmarshalJSON unmarshal to json750func (richTextAnchorLink *RichTextAnchorLink) UnmarshalJSON(b []byte) error {751 var objMap map[string]*json.RawMessage752 err := json.Unmarshal(b, &objMap)753 if err != nil {754 return err755 }756 tempObj := struct {757 tdCommon758 AnchorName string `json:"anchor_name"` // The anchor name. If the name is empty, the link should bring back to top759 URL string `json:"url"` // An HTTP URL, opening the anchor760 }{}761 err = json.Unmarshal(b, &tempObj)762 if err != nil {763 return err764 }765 richTextAnchorLink.tdCommon = tempObj.tdCommon766 richTextAnchorLink.AnchorName = tempObj.AnchorName767 richTextAnchorLink.URL = tempObj.URL768 fieldText, _ := unmarshalRichText(objMap["text"])769 richTextAnchorLink.Text = fieldText770 return nil771}772// GetRichTextEnum return the enum type of this object773func (richTextAnchorLink *RichTextAnchorLink) GetRichTextEnum() RichTextEnum {774 return RichTextAnchorLinkType775}776// RichTexts A concatenation of rich texts777type RichTexts struct {778 tdCommon779 Texts []RichText `json:"texts"` // Texts780}781// MessageType return the string telegram-type of RichTexts782func (richTexts *RichTexts) MessageType() string {783 return "richTexts"784}785// NewRichTexts creates a new RichTexts786//787// @param texts Texts788func NewRichTexts(texts []RichText) *RichTexts {...

Full Screen

Full Screen

t_anchor_test.go

Source:t_anchor_test.go Github

copy

Full Screen

...17 t.Fatalf("Cannot parse `%s`: %s", s, err)18 }19 return dt20}21func TestAnchor(tt *testing.T) {22 ttt := test.NewTestingTB(tt.Name())23 t := td.NewT(ttt)24 type MyStruct struct {25 PNum *int26 Num int6427 Str string28 Slice []int29 Map map[string]bool30 Time time.Time31 }32 n := 4233 got := MyStruct{34 PNum: &n,35 Num: 136,36 Str: "Pipo bingo",37 Time: timeParse(tt, "2019-01-02T11:22:33.123456Z"),38 }39 // Using T.Anchor()40 td.CmpTrue(tt,41 t.Cmp(got, MyStruct{42 PNum: t.Anchor(td.Ptr(td.Between(40, 45))).(*int),43 Num: t.Anchor(td.Between(int64(135), int64(137))).(int64),44 Str: t.Anchor(td.HasPrefix("Pipo"), "").(string),45 Time: t.Anchor(td.TruncTime(timeParse(tt, "2019-01-02T11:22:00Z"), time.Minute)).(time.Time),46 }))47 // Using T.A()48 td.CmpTrue(tt,49 t.Cmp(got, MyStruct{50 PNum: t.A(td.Ptr(td.Between(40, 45))).(*int),51 Num: t.A(td.Between(int64(135), int64(137))).(int64),52 Str: t.A(td.HasPrefix("Pipo"), "").(string),53 Time: t.A(td.TruncTime(timeParse(tt, "2019-01-02T11:22:00Z"), time.Minute)).(time.Time),54 }))55 // Testing persistence56 got = MyStruct{Num: 136}57 tt.Run("without persistence", func(tt *testing.T) {58 numOp := t.Anchor(td.Between(int64(135), int64(137))).(int64)59 td.CmpTrue(tt, t.Cmp(got, MyStruct{Num: numOp}))60 td.CmpFalse(tt, t.Cmp(got, MyStruct{Num: numOp}))61 })62 tt.Run("with persistence", func(tt *testing.T) {63 numOp := t.Anchor(td.Between(int64(135), int64(137))).(int64)64 defer t.AnchorsPersistTemporarily()()65 td.CmpTrue(tt, t.Cmp(got, MyStruct{Num: numOp}))66 td.CmpTrue(tt, t.Cmp(got, MyStruct{Num: numOp}))67 t.ResetAnchors() // force reset anchored operators68 td.CmpFalse(tt, t.Cmp(got, MyStruct{Num: numOp}))69 })70 // Errors71 tt.Run("errors", func(tt *testing.T) {72 td.Cmp(tt, ttt.CatchFatal(func() { t.Anchor(nil) }),73 "Cannot anchor a nil TestDeep operator")74 td.Cmp(tt, ttt.CatchFatal(func() { t.Anchor(td.Ignore(), 1, 2) }),75 "usage: Anchor(OPERATOR[, MODEL]), too many parameters")76 td.Cmp(tt, ttt.CatchFatal(func() { t.Anchor(td.Ignore(), nil) }),77 "Untyped nil value is not valid as model for an anchor")78 td.Cmp(tt, ttt.CatchFatal(func() { t.Anchor(td.Between(1, 2), 12.3) }),79 "Operator Between TypeBehind() returned int which differs from model type float64. Omit model or ensure its type is int")80 td.Cmp(tt, ttt.CatchFatal(func() { t.Anchor(td.Ignore()) }),81 "Cannot anchor operator Ignore as TypeBehind() returned nil. Use model parameter to specify the type to return")82 })83}84type privStruct struct {85 num int6486}87func (p privStruct) Num() int64 {88 return p.num89}90func TestAddAnchorableStructType(tt *testing.T) {91 type MyStruct struct {92 Priv privStruct93 }94 ttt := test.NewTestingTB(tt.Name())95 t := td.NewT(ttt)96 // We want to anchor this operator97 op := td.Smuggle((privStruct).Num, int64(42))98 // Without making privStruct anchorable, it does not work99 td.Cmp(tt, ttt.CatchFatal(func() { t.A(op, privStruct{}) }),100 "td_test.privStruct struct type is not supported as an anchor. Try AddAnchorableStructType")101 // Make privStruct anchorable102 td.AddAnchorableStructType(func(nextAnchor int) privStruct {103 return privStruct{num: int64(2e9 - nextAnchor)}104 })105 td.CmpTrue(tt,106 t.Cmp(MyStruct{Priv: privStruct{num: 42}},107 MyStruct{108 Priv: t.A(op, privStruct{}).(privStruct), // ← now it works109 }))110 // Error111 test.CheckPanic(tt,112 func() { td.AddAnchorableStructType(123) },113 "usage: AddAnchorableStructType(func (nextAnchor int) STRUCT_TYPE)")114}115func TestAnchorsPersist(tt *testing.T) {116 ttt := test.NewTestingTB(tt.Name())117 t1 := td.NewT(ttt)118 t2 := td.NewT(ttt)119 t3 := td.NewT(t1)120 tt.Run("without anchors persistence", func(tt *testing.T) {121 // Anchors persistence is shared for a same testing.TB122 td.CmpFalse(tt, t1.DoAnchorsPersist())123 td.CmpFalse(tt, t2.DoAnchorsPersist())124 td.CmpFalse(tt, t3.DoAnchorsPersist())125 func() {126 defer t1.AnchorsPersistTemporarily()()127 td.CmpTrue(tt, t1.DoAnchorsPersist())128 td.CmpTrue(tt, t2.DoAnchorsPersist())129 td.CmpTrue(tt, t3.DoAnchorsPersist())130 }()131 td.CmpFalse(tt, t1.DoAnchorsPersist())132 td.CmpFalse(tt, t2.DoAnchorsPersist())133 td.CmpFalse(tt, t3.DoAnchorsPersist())134 })135 tt.Run("with anchors persistence", func(tt *testing.T) {136 t3.SetAnchorsPersist(true)137 td.CmpTrue(tt, t1.DoAnchorsPersist())138 td.CmpTrue(tt, t2.DoAnchorsPersist())139 td.CmpTrue(tt, t3.DoAnchorsPersist())140 func() {141 defer t1.AnchorsPersistTemporarily()()142 td.CmpTrue(tt, t1.DoAnchorsPersist())143 td.CmpTrue(tt, t2.DoAnchorsPersist())144 td.CmpTrue(tt, t3.DoAnchorsPersist())145 }()146 td.CmpTrue(tt, t1.DoAnchorsPersist())147 td.CmpTrue(tt, t2.DoAnchorsPersist())148 td.CmpTrue(tt, t3.DoAnchorsPersist())149 })150}...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

1//+build sdkcodegen2package main3import (4 "bufio"5 "fmt"6 "io"7 "net/http"8 "os"9 "regexp"10 "strconv"11 "strings"12 "time"13 "github.com/PuerkitoBio/goquery"14)15const errcodeDocURL = "https://work.weixin.qq.com/api/doc/90000/90139/90313"16var absoluteLinkRegexp = regexp.MustCompile(`<a href="(http[^"]+)">([^<]+)</a>`)17var absoluteLinkReplace = "[$2]($1)"18var anchorLinkRegexp = regexp.MustCompile(`<a href="#([^"]+)">([^<]+)</a>`)19var anchorLinkReplace = fmt.Sprintf("[$2](%s#$1)", errcodeDocURL)20var h5Regexp = regexp.MustCompile(`<h5[^>]*>.*</h5>`)21func die(format string, a ...interface{}) {22 fmt.Fprintf(os.Stderr, format, a...)23 os.Exit(1)24 // unreachable25}26func main() {27 // get the fresh documentation!28 var doc *goquery.Document29 var retrieveTime time.Time30 {31 resp, err := http.Get(errcodeDocURL)32 if err != nil {33 die("http get of errcode documentation failed: %+v\n", err)34 }35 defer resp.Body.Close()36 if resp.StatusCode != http.StatusOK {37 die("non-200 response: %s\n", resp)38 }39 tmp, err := goquery.NewDocumentFromReader(resp.Body)40 if err != nil {41 die("parse document failed: %+v\n", err)42 }43 doc = tmp44 retrieveTime = time.Now()45 }46 // prepare to emit code47 destFilename := os.Args[1]48 var sink io.Writer49 {50 file, err := os.Create(destFilename)51 if err != nil {52 die("open '%s' for writing failed: %+v\n", destFilename, err)53 }54 bufWriter := bufio.NewWriter(file)55 sink = bufWriter56 defer func() {57 bufWriter.Flush()58 file.Close()59 }()60 }61 em := &goEmitter{62 Sink: sink,63 }64 err := em.Init(retrieveTime)65 if err != nil {66 die("code emission init failed: %+v\n", err)67 }68 numWritten := 069 // 目前的页面结构是唯一一个 <table> 里面 <tbody> 里面一 <tr> 有按顺序的三个 <td>70 // 错误码, 错误说明, 排查方法71 doc.Find("table > tbody > tr").Each(func(i int, s *goquery.Selection) {72 td := s.Find("td").First()73 codeStr := td.Text()74 code, err := strconv.ParseInt(codeStr, 10, 64)75 if err != nil {76 die("malformed errcode entry: code=%#v not an int: %+v\n", codeStr, err)77 }78 td = td.Next()79 descStr := td.Text()80 td = td.Next()81 solutionHtml, err := td.Html()82 if err != nil {83 die("failed to get html out of td: %+v\n", err)84 }85 // is there any anchor link to different sections of the same doc?86 var anchorRefs []string87 {88 for _, groups := range anchorLinkRegexp.FindAllStringSubmatch(solutionHtml, -1) {89 anchorName := groups[1]90 if !strings.HasPrefix(anchorName, "10649/") {91 // seems only this format is reference to same doc92 continue93 }94 anchorName = anchorName[6:]95 anchorRefs = append(anchorRefs, anchorName)96 }97 }98 // resolve the referenced section and paste the content into solution99 // for users' convenience100 //101 // document structure like this: li > h5 > a[name="错误码:xxxxx"]102 // we want the innerHTML of li103 if len(anchorRefs) > 0 {104 for _, anchor := range anchorRefs {105 a := doc.Find(fmt.Sprintf(`a[name="%s"]`, anchor)).First()106 li := a.Parent().Parent()107 liHtml, err := li.Html()108 if err != nil {109 die("failed to get html out of li: %+v\n", err)110 }111 solutionHtml += "\n\n"112 solutionHtml += h5Regexp.ReplaceAllString(liHtml, "")113 }114 }115 // resolve links116 tmp := solutionHtml117 tmp = absoluteLinkRegexp.ReplaceAllString(tmp, absoluteLinkReplace)118 tmp = anchorLinkRegexp.ReplaceAllString(tmp, anchorLinkReplace)119 // unescape things120 // this is VERY crude but working so...121 tmp = strings.ReplaceAll(tmp, "&lt;", "<")122 tmp = strings.ReplaceAll(tmp, "&gt;", ">")123 tmp = strings.ReplaceAll(tmp, "<br/>", "\n")124 tmp = strings.ReplaceAll(tmp, "<p>", "")125 tmp = strings.ReplaceAll(tmp, "</p>", "")126 tmp = strings.ReplaceAll(tmp, "<ul>", "")127 tmp = strings.ReplaceAll(tmp, "</ul>", "")128 tmp = strings.ReplaceAll(tmp, "<li>", "* ")129 tmp = strings.ReplaceAll(tmp, "</li>", "\n")130 tmp = strings.ReplaceAll(tmp, "<strong>", "**")131 tmp = strings.ReplaceAll(tmp, "</strong>", "**")132 solution := tmp133 err = em.EmitErrCode(code, descStr, solution)134 if err != nil {135 die("errcode emission failed: %+v\n", err)136 }137 numWritten++138 })139 err = em.Finalize()140 if err != nil {141 die("finalization failed: %+v\n", err)142 }143 fmt.Printf("%d errcodes written.\n", numWritten)144}...

Full Screen

Full Screen

Anchor

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := colly.NewCollector()4 c.OnHTML("td", func(e *colly.HTMLElement) {5 link := e.ChildAttr("a", "href")6 fmt.Println(link)7 })8}

Full Screen

Full Screen

Anchor

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := colly.NewCollector()4 c.OnHTML("td", func(e *colly.HTMLElement) {5 link := e.ChildAttr("a", "href")6 fmt.Println(link)7 })8}

Full Screen

Full Screen

Anchor

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := colly.NewCollector()4 c.OnHTML("td", func(e *colly.HTMLElement) {5 link := e.ChildAttr("a", "href")6 fmt.Println(link)7 })8}

Full Screen

Full Screen

Anchor

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := colly.NewCollector()4 c.OnHTML("td", func(e *colly.HTMLElement) {5 fmt.Println(e.Text)6 })7}

Full Screen

Full Screen

Anchor

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 const (4 opts := []selenium.ServiceOption{5 }6 selenium.SetDebug(true)7 service, err := selenium.NewSeleniumService(seleniumPath, port, opts...)8 if err != nil {9 }10 defer service.Stop()11 caps := selenium.Capabilities{"browserName": "firefox"}12 if err != nil {13 panic(err)14 }15 defer wd.Quit()16 panic(err)17 }18 elem, err := wd.FindElement(selenium.ByID, "lst-ib")19 if err != nil {20 panic(err)21 }22 if err := elem.SendKeys("selenium"); err != nil {23 panic(err)24 }25 if err := elem.Submit(); err != nil {26 panic(err)27 }28 wd.Wait(func(wd selenium.WebDriver) (bool, error) {29 _, err := wd.FindElement(selenium.ByClassName, "srg")30 if err != nil && err == selenium.ErrNoSuchElement {31 }32 })

Full Screen

Full Screen

Anchor

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 doc.Find(".gb_P").Each(func(i int, s *goquery.Selection) {7 band := s.Find("a").Text()8 title := s.Find("b").Text()9 fmt.Printf("Review %d: %s - %s\n", i, band, title)10 })11}

Full Screen

Full Screen

Anchor

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 fmt.Print(err.Error())5 os.Exit(1)6 }7 responseData, err := ioutil.ReadAll(response.Body)8 if err != nil {9 log.Fatal(err)10 }11 doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(responseData)))12 if err != nil {13 log.Fatal(err)14 }15 doc.Find(".td").Each(func(i int, s *goquery.Selection) {16 title := s.Find("a").Text()17 linkTag := s.Find("a")18 href, _ := linkTag.Attr("href")19 fmt.Printf("Review %d: %s - %s\n", i, title, href)20 })21}

Full Screen

Full Screen

Anchor

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 const (4 opts := []selenium.ServiceOption{5 }6 selenium.SetDebug(true)7 service, err := selenium.NewChromeDriverService(seleniumPath, port, opts...)8 if err != nil {9 panic(err)10 }11 defer service.Stop()12 caps := selenium.Capabilities{"browserName": "chrome"}13 if err != nil {14 panic(err)15 }16 defer wd.Quit()

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