Best Gauge code snippet using parser.containsAny
alipay.go
Source:alipay.go
1// Copyright 2019 wongoo. All rights reserved.2package aliwepaystat3import (4 "golang.org/x/text/encoding"5 "golang.org/x/text/encoding/simplifiedchinese"6)7const (8 AlipayCsvHeader = "交æå·,å家订åå·,交æå建æ¶é´,ä»æ¬¾æ¶é´,æè¿ä¿®æ¹æ¶é´,交ææ¥æºå°,ç±»å,交æ对æ¹,ååå称,éé¢ï¼å
ï¼,æ¶/æ¯,交æç¶æ,æå¡è´¹ï¼å
ï¼,æåé款ï¼å
ï¼,å¤æ³¨,èµéç¶æ,"9 AlipayCsvFieldNum = 1710)11//AlipayTrans alipay transaction12type AlipayTrans struct {13 ID string `csv:"id"`14 OrderID string `csv:"order_id"`15 CreatedTime string `csv:"created_time"`16 PaidTime string `csv:"paid_time"`17 ModifiedTime string `csv:"modified_time"`18 Source string `csv:"source"`19 Type string `csv:"type"`20 Target string `csv:"target"`21 Product string `csv:"product"`22 Amount float64 `csv:"amount"`23 FinType string `csv:"fin_type"`24 Status string `csv:"status"`25 Charge float64 `csv:"charge"`26 Refund float64 `csv:"refund"`27 Comment string `csv:"comment"`28 FundStatus string `csv:"fund_status"`29 Other string `csv:"other"`30}31func (t *AlipayTrans) IsIncome() bool {32 return Contains(t.FinType, "æ¶å
¥") || ContainsAny(t.Product, cfg.IncomeKeyWords...)33}34func (t *AlipayTrans) IsInnerTransfer() bool {35 return ContainsAny(t.Target, cfg.FamilyMembers...) ||36 ContainsAny(t.Product, cfg.InnerTransferKeyWords...)37}38func (t *AlipayTrans) IsTransfer() bool {39 return Contains(t.FundStatus, "èµé转移") ||40 EitherContainsAny(t.Product, t.Target, cfg.TransferKeyWords...) ||41 ContainsAny(t.Target, cfg.FamilyMembers...)42}43func (t *AlipayTrans) IsClosed() bool {44 return ContainsAny(t.Status, "失败", "交æå
³é")45}46func (t *AlipayTrans) YearMonth() string {47 if t.ID[:2] != "20" {48 return "20" + t.ID[:4]49 }50 return t.ID[:6]51}52func (t *AlipayTrans) GetID() string { return t.ID }53func (t *AlipayTrans) GetOrderID() string { return t.OrderID }54func (t *AlipayTrans) GetCreatedTime() string { return t.CreatedTime }55func (t *AlipayTrans) GetPaidTime() string { return t.PaidTime }56func (t *AlipayTrans) GetModifiedTime() string { return t.ModifiedTime }57func (t *AlipayTrans) GetSource() string { return t.Source }58func (t *AlipayTrans) GetType() string { return t.Type }59func (t *AlipayTrans) GetTarget() string { return t.Target }60func (t *AlipayTrans) GetProduct() string { return t.Product }61func (t *AlipayTrans) GetAmount() float64 { return t.Amount }62func (t *AlipayTrans) GetFormatAmount() float64 {63 return RoundFloat(t.GetAmount())64}65func (t *AlipayTrans) GetFinType() string { return t.FinType }66func (t *AlipayTrans) GetStatus() string { return t.Status }67func (t *AlipayTrans) GetCharge() float64 { return t.Charge }68func (t *AlipayTrans) GetRefund() float64 { return t.Refund }69func (t *AlipayTrans) GetComment() string { return t.Comment }70func (t *AlipayTrans) GetFundStatus() string { return t.FundStatus }71func (t *AlipayTrans) IsShowInList() bool { return t.GetAmount() > cfg.ListMinAmount }72func NewAlipayTrans() Trans {73 return &AlipayTrans{}74}75type alipayTransParser struct {76}77func (p *alipayTransParser) NewTrans() Trans {78 return &AlipayTrans{}79}80func (p *alipayTransParser) CsvHeader() string {81 return AlipayCsvHeader82}83func (p *alipayTransParser) FieldNum() int {84 return AlipayCsvFieldNum85}86func (p *alipayTransParser) Enc() encoding.Encoding {87 return simplifiedchinese.GBK88}89var TransParserAlipay = &alipayTransParser{}...
wechat.go
Source:wechat.go
1// Copyright 2019 wongoo. All rights reserved.2package aliwepaystat3import (4 "log"5 "strconv"6 "strings"7 "golang.org/x/text/encoding"8 "golang.org/x/text/encoding/unicode"9)10const (11 WechatCsvHeader = "交ææ¶é´,交æç±»å,交æ对æ¹,åå,æ¶/æ¯,éé¢(å
),æ¯ä»æ¹å¼,å½åç¶æ,交æåå·,åæ·åå·,å¤æ³¨"12 WechatCsvFieldNum = 1113)14//WechatTrans Wechat transaction15type WechatTrans struct {16 CreatedTime string `csv:"created_time"`17 Type string `csv:"type"`18 Target string `csv:"target"`19 Product string `csv:"product"`20 FinType string `csv:"fin_type"`21 Amount string `csv:"amount"`22 amt float6423 Source string `csv:"source"`24 Status string `csv:"status"`25 ID string `csv:"id"`26 OrderID string `csv:"order_id"`27 Comment string `csv:"comment"`28 refund float6429}30func (t *WechatTrans) IsIncome() bool {31 return Contains(t.FinType, "æ¶å
¥") ||32 ContainsAny(t.Product, cfg.IncomeKeyWords...)33}34func (t *WechatTrans) IsInnerTransfer() bool {35 return ContainsAny(t.Target, cfg.FamilyMembers...) ||36 ContainsAny(t.Product, cfg.InnerTransferKeyWords...)37}38func (t *WechatTrans) IsTransfer() bool {39 return Contains(t.Type, "转账") ||40 EitherContainsAny(t.Product, t.Target, cfg.TransferKeyWords...) ||41 ContainsAny(t.Target, cfg.FamilyMembers...)42}43func (t *WechatTrans) IsClosed() bool {44 return ContainsAny(t.Status, "失败", "交æå
³é")45}46func (t *WechatTrans) YearMonth() string {47 return t.CreatedTime[0:4] + t.CreatedTime[5:7]48}49func (t *WechatTrans) GetID() string { return t.ID }50func (t *WechatTrans) GetOrderID() string { return t.OrderID }51func (t *WechatTrans) GetCreatedTime() string { return t.CreatedTime }52func (t *WechatTrans) GetSource() string { return t.Source }53func (t *WechatTrans) GetType() string { return t.Type }54func (t *WechatTrans) GetTarget() string { return t.Target }55func (t *WechatTrans) GetProduct() string { return t.Product }56func (t *WechatTrans) GetAmount() float64 {57 if t.amt == 0 && t.Amount != "" {58 var err error59 t.amt, err = strconv.ParseFloat(strings.ReplaceAll(t.Amount, "Â¥", ""), 32)60 if err != nil {61 log.Fatalf("æ æ³è§£æéé¢: %v", t.Amount)62 }63 }64 return t.amt65}66func (t *WechatTrans) GetFormatAmount() float64 {67 return RoundFloat(t.GetAmount())68}69func (t *WechatTrans) GetFinType() string { return t.FinType }70func (t *WechatTrans) GetStatus() string { return t.Status }71func (t *WechatTrans) GetRefund() float64 { return t.refund }72func (t *WechatTrans) GetComment() string { return t.Comment }73func (t *WechatTrans) IsShowInList() bool { return t.GetAmount() > cfg.ListMinAmount }74type wechatTransParser struct {75}76func (p *wechatTransParser) NewTrans() Trans {77 return &WechatTrans{}78}79func (p *wechatTransParser) CsvHeader() string {80 return WechatCsvHeader81}82func (p *wechatTransParser) FieldNum() int {83 return WechatCsvFieldNum84}85func (p *wechatTransParser) Enc() encoding.Encoding {86 return unicode.UTF887}88var TransParserWechat = &wechatTransParser{}89func IsWechatGroupAAExpense(trans Trans) bool {90 if we, ok := trans.(*WechatTrans); ok {91 return we.Type == "群æ¶æ¬¾" && we.FinType == "æ¯åº"92 }93 return false94}...
parser_test.go
Source:parser_test.go
1package parser2import (3 "strings"4 "testing"5)6func Test_Parser(t *testing.T) {7 p := func(str string) *Result {8 if strings.ContainsAny(str[0:1], "abc") {9 return &Result{Token: str[0:1], Count: 1}10 }11 return nil12 }13 arr, c := Parse("a.bc.a", []Parser{p}).ToArray()14 strCnt := 015 etcCnt := 016 if c != 6 {17 t.Fatal("Result count sym is not 6.", c)18 }19 for i := 0; i < len(arr); i++ {20 if _, ok := arr[i].Token.(string); ok {21 strCnt += 122 } else {23 etcCnt += 124 }25 }26 if strCnt != 4 {27 t.Fail()28 }29 if etcCnt != 2 {30 t.Fail()31 }32}33func Test_Parser_Ony_Three_Tokens(t *testing.T) {34 p := func(str string) *Result {35 if strings.ContainsAny(str[0:1], "abc") {36 return &Result{Token: str[0:1], Count: 1}37 }38 return nil39 }40 arr, c := Parse("a.bc.a", []Parser{p}).FewArray(3)41 if c != 3 {42 t.Fatal("Result count sym is not 3.", c)43 }44 if len(arr) != 3 {45 t.Fatal("Count is not 3.", len(arr))46 }47}48func Test_Parser_Only_Filtered_Tokens(t *testing.T) {49 p := func(str string) *Result {50 if strings.ContainsAny(str[0:1], "abc") {51 return &Result{Token: str[0:1], Count: 1}52 }53 return nil54 }55 arr, c := Parse("a.bc.a", []Parser{p}).FilterArray(func(r *Result) bool {56 if _, ok := r.Token.(string); ok {57 return true58 }59 return false60 })61 if c != 6 {62 t.Fatal("Result count sym is not 6.", c)63 }64 if len(arr) != 4 {65 t.Fatal("Count is not 4.", len(arr))66 }67}68func Test_Parser_Unti_C_Token(t *testing.T) {69 p := func(str string) *Result {70 if strings.ContainsAny(str[0:1], "abc") {71 return &Result{Token: str[0:1], Count: 1}72 }73 return nil74 }75 arr, c := Parse("a.bc.a", []Parser{p}).UntilArray(76 func(r *Result) bool {77 if t, ok := r.Token.(string); ok {78 return t == "c"79 }80 return false81 },82 )83 if c != 3 {84 t.Fatal("Result count sym is not 3.", c)85 }86 if len(arr) != 3 {87 t.Fatal("Count is not 4.", len(arr))88 }89 if tok, ok := arr[2].Token.(string); ok {90 if tok != "b" {91 t.Fatal("Array last element is not 'b'.", tok)92 }93 } else {94 t.Fatal("Type of last token is not valid!")95 }96}...
containsAny
Using AI Code Generation
1import (2func main() {3 fmt.Println(strings.ContainsAny("team", "i"))4 fmt.Println(strings.ContainsAny("failure", "u & i"))5 fmt.Println(strings.ContainsAny("foo", ""))6 fmt.Println(strings.ContainsAny("", ""))7}8import (9func main() {10 fmt.Println(strings.ContainsAny("team", "i"))11 fmt.Println(strings.ContainsAny("failure", "u & i"))12 fmt.Println(strings.ContainsAny("foo", ""))13 fmt.Println(strings.ContainsAny("", ""))14}15import (16func main() {17 fmt.Println(strings.ContainsAny("team", "i"))18 fmt.Println(strings.ContainsAny("failure", "u & i"))19 fmt.Println(strings.ContainsAny("foo", ""))20 fmt.Println(strings.ContainsAny("", ""))21}22import (23func main() {24 fmt.Println(strings.ContainsAny("team", "i"))25 fmt.Println(strings.ContainsAny("failure", "u & i"))26 fmt.Println(strings.ContainsAny("foo", ""))27 fmt.Println(strings.ContainsAny("", ""))28}29import (30func main() {31 fmt.Println(strings.ContainsAny("team", "i"))32 fmt.Println(strings.ContainsAny("failure", "u & i"))33 fmt.Println(strings.ContainsAny("foo", ""))34 fmt.Println(strings.ContainsAny("", ""))35}36import (37func main() {38 fmt.Println(strings.ContainsAny("team", "i"))39 fmt.Println(strings.ContainsAny("failure", "u & i"))40 fmt.Println(strings.ContainsAny("foo", ""))41 fmt.Println(strings.ContainsAny("", ""))42}
containsAny
Using AI Code Generation
1import (2func main() {3 fmt.Println(strings.ContainsAny("team", "i"))4 fmt.Println(strings.ContainsAny("failure", "u & i"))5 fmt.Println(strings.ContainsAny("failure", " "))6 fmt.Println(strings.ContainsAny("in failure", "s g"))7 fmt.Println(strings.ContainsAny("foo", ""))8 fmt.Println(strings.ContainsAny("", ""))9}10Recommended Posts: Go | ContainsRune() method in strings11Go | Contains() method in strings12Go | ContainsFold() method in strings13Go | Count() method in strings14Go | EqualFold() method in strings15Go | Fields() method in strings16Go | FieldsFunc() method in strings17Go | HasPrefix() method in strings18Go | HasSuffix() method in strings19Go | IndexAny() method in strings20Go | IndexByte() method in strings21Go | IndexFunc() method in strings22Go | IndexRune() method in strings23Go | Join() method in strings24Go | LastIndexAny() method in strings25Go | LastIndexByte() method in strings26Go | LastIndexFunc() method in strings27Go | LastIndex() method in strings28Go | Map() method in strings29Go | Repeat() method in strings30Go | Replace() method in strings31Go | SplitAfterN() method in strings32Go | SplitAfter() method in strings33Go | SplitN() method in strings34Go | Split() method in strings35Go | Title() method in strings36Go | ToLower() method in strings37Go | ToLowerSpecial() method in strings38Go | ToTitle() method in strings39Go | ToTitleSpecial() method in strings40Go | ToUpper() method in strings41Go | ToUpperSpecial() method in strings42Go | TrimFunc() method in strings43Go | TrimLeftFunc() method in strings44Go | TrimPrefix() method in strings45Go | TrimRightFunc() method in strings46Go | TrimSpace() method in strings47Go | TrimSuffix() method in strings48Go | Trim() method in strings49Go | Fields() method in strings50Go | FieldsFunc() method in strings51Go | Index() method in strings52Go | IndexAny() method in strings53Go | IndexByte() method in
containsAny
Using AI Code Generation
1import (2func main() {3 var res = strings.ContainsAny(str, "world")4 fmt.Println(res)5}6func ContainsRune(s string, r rune) bool7import (8func main() {9 var res = strings.ContainsRune(str, 'w')10 fmt.Println(res)11}12func Count(s, substr string) int13import (14func main() {15 var res = strings.Count(str, "l")16 fmt.Println(res)17}18func EqualFold(s, t string) bool19import (20func main() {21 var res = strings.EqualFold(str, "HELLO WORLD")22 fmt.Println(res)23}24func Fields(s string) []string25import (26func main() {
containsAny
Using AI Code Generation
1import (2func main() {3 re := regexp.MustCompile(`[a-z]+`)4 fmt.Println(re.ContainsAnyString("123"))5 fmt.Println(re.ContainsAnyString("abc"))6 fmt.Println(re.ContainsAnyString("abc123"))7}8import (9func main() {10 re := regexp.MustCompile(`[a-z]+`)11 fmt.Println(re.ContainsString("123"))12 fmt.Println(re.ContainsString("abc"))13 fmt.Println(re.ContainsString("abc123"))14}15import (16func main() {17 re := regexp.MustCompile(`[a-z]+`)18 fmt.Println(re.FindAllString("123", -1))19 fmt.Println(re.FindAllString("abc", -1))20 fmt.Println(re.FindAllString("abc123", -1))21}22import (23func main() {24 re := regexp.MustCompile(`[a-z]+`)25 fmt.Println(re.FindAllStringIndex("123", -1))26 fmt.Println(re.FindAllStringIndex("abc", -1))27 fmt.Println(re.FindAllStringIndex("abc123", -1))28}29import (
containsAny
Using AI Code Generation
1func main() {2 fmt.Println(strings.ContainsAny(s, "aeiouy"))3 fmt.Println(strings.ContainsAny(s, "abc"))4 fmt.Println(strings.ContainsAny(s, "xyz"))5}6Related Posts: Golang strings.ContainsAny() Method7Golang strings.ContainsRune() Method8Golang strings.Contains() Method9Golang strings.Compare() Method10Golang strings.Count() Method11Golang strings.Contains() Method12Golang strings.Count() Method13Golang strings.ContainsRune() Method14Golang strings.Compare() Method15Golang strings.ContainsAny() Method16Golang strings.Contains() Method17Golang strings.Compare() Method18Golang strings.Contains() Method19Golang strings.Compare() Method20Golang strings.ContainsAny() M
containsAny
Using AI Code Generation
1import (2func main() {3 fmt.Println("ContainsAny: ", strings.ContainsAny("success", "suc"))4}5import (6func main() {7 fmt.Println("ContainsRune: ", strings.ContainsRune("success", 's'))8}9import (10func main() {11 fmt.Println("Count: ", strings.Count("success", "s"))12}13import (14func main() {15 fmt.Println("Contains: ", strings.Contains("success", "suc"))16}17import (18func main() {19 fmt.Println("ContainsFunc: ", strings.ContainsFunc("success", func(r rune) bool {20 }))21}22import (23func main() {24 fmt.Println("ContainsRune: ", strings.ContainsRune("success", 's'))25}26import (
containsAny
Using AI Code Generation
1import (2func main() {3 fmt.Println(strings.ContainsAny("Hello World", "H"))4 fmt.Println(strings.ContainsAny("Hello World", "W"))5 fmt.Println(strings.ContainsAny("Hello World", "R"))6}7func ContainsAny(s, chars string) bool8import (9func main() {10 fmt.Println(strings.ContainsAny("Hello World", "H"))11 fmt.Println(strings.ContainsAny("Hello World", "W"))12 fmt.Println(strings.ContainsAny("Hello World", "R"))13}14func ContainsAny(s, chars string) bool
containsAny
Using AI Code Generation
1import (2func main() {3 fmt.Printf("ContainsAny: %t", strings.ContainsAny("team", "i"))4 fmt.Printf("5ContainsAny: %t", strings.ContainsAny("failure", "i"))6 fmt.Printf("7ContainsAny: %t", strings.ContainsAny("in failure", "s"))8 fmt.Printf("9ContainsAny: %t", strings.ContainsAny("foo", ""))10 fmt.Printf("11ContainsAny: %t", strings.ContainsAny("", ""))12}13Go | Count the number of times a character occurs in a string without using strings.Count()14Go | Count the number of times a substring occurs in a string without using strings.Count()15Go | Count the number of times a character occurs in a string without using strings.Count()16Go | Convert a slice of strings to a string using strings.Join()17Go | Convert a string to a slice of strings using strings.Split()18Go | Convert a slice of bytes to a string using strings.Join()19Go | Convert a string to a slice of bytes using strings.Split()20Go | Convert a slice of strings to a string using strings.Join()21Go | Convert a slice of bytes to a string using strings.Join()22Go | Convert a string to a slice of bytes using strings.Split()23Go | Convert a slice of strings to a string using strings.Join()24Go | Convert a slice of bytes to a string using strings.Join()25Go | Convert a string to a slice of bytes using strings.Split()26Go | Convert a slice of strings to a string using strings.Join()27Go | Convert a slice of bytes to a string using strings.Join()28Go | Convert a string to a slice of bytes using strings.Split()29Go | Convert a slice of strings to a string using strings.Join()
containsAny
Using AI Code Generation
1import (2func main() {3fmt.Println(strings.ContainsAny("Hello World", "H"))4fmt.Println(strings.ContainsAny("Hello World", "h"))5}6Syntax: func ContainsRune(s string, r rune) bool7import (8func main() {9fmt.Println(strings.ContainsRune("Hello World", 'H'))10fmt.Println(strings.ContainsRune("Hello World", 'h'))11}12Syntax: func Contains(s, substr string) bool13import (14func main() {15fmt.Println(strings.Contains("Hello World", "Hello"))16fmt.Println(strings.Contains("Hello World", "hello"))17}18Syntax: func Count(s, sep string) int19import (20func main() {21fmt.Println(strings.Count("Hello World", "l"))22fmt.Println(strings.Count("Hello World", "llo"))23fmt.Println(strings.Count("Hello World", "lloW"))24}25Syntax: func Fields(s string) []string26import (27func main() {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!