Best Gauge code snippet using parser.addStates
processor.go
Source:processor.go
...33 return []error{}, false34}35func processComment(parser *SpecParser, token *Token) ([]error, bool) {36 parser.clearState()37 addStates(&parser.currentState, commentScope)38 return []error{}, false39}40func processTag(parser *SpecParser, token *Token) ([]error, bool) {41 if isInState(parser.currentState, tagsScope) {42 retainStates(&parser.currentState, tagsScope)43 } else {44 parser.clearState()45 }46 tokens := splitAndTrimTags(token.Value)47 for _, tagValue := range tokens {48 if len(tagValue) > 0 {49 token.Args = append(token.Args, tagValue)50 }51 }52 return []error{}, false53}54func processTable(parser *SpecParser, token *Token) ([]error, bool) {55 var buffer bytes.Buffer56 shouldEscape := false57 var errs []error58 for i, element := range token.Value {59 if i == 0 {60 continue61 }62 if shouldEscape {63 _, err := buffer.WriteRune(element)64 if err != nil {65 errs = append(errs, err)66 }67 shouldEscape = false68 continue69 }70 if element == '\\' {71 shouldEscape = true72 continue73 } else if element == '|' {74 trimmedValue := strings.TrimSpace(buffer.String())75 if token.Kind == gauge.TableHeader {76 if len(trimmedValue) == 0 {77 errs = append(errs, fmt.Errorf("Table header should not be blank"))78 } else if arrayContains(token.Args, trimmedValue) {79 errs = append(errs, fmt.Errorf("Table header cannot have repeated column values"))80 }81 }82 token.Args = append(token.Args, trimmedValue)83 buffer.Reset()84 } else {85 _, err := buffer.WriteRune(element)86 if err != nil {87 errs = append(errs, err)88 }89 }90 }91 if !isInState(parser.currentState, tableScope) {92 addStates(&parser.currentState, tableScope)93 } else {94 addStates(&parser.currentState, tableDataScope)95 }96 return errs, false97}98func splitAndTrimTags(tag string) []string {99 listOfTags := strings.Split(tag, ",")100 for i, aTag := range listOfTags {101 listOfTags[i] = strings.TrimSpace(aTag)102 }103 return listOfTags104}...
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!!