How to use removeDuplicateTags method of infoGatherer Package

Best Gauge code snippet using infoGatherer.removeDuplicateTags

specDetails.go

Source:specDetails.go Github

copy

Full Screen

...187 s.tagsCache.tags[file] = append(s.tagsCache.tags[file], sce.Tags.Values()...)188 }189 }190}191func removeDuplicateTags(tags []string) []string {192 encountered := map[string]bool{}193 result := []string{}194 for i := range tags {195 if !encountered[tags[i]] {196 encountered[tags[i]] = true197 result = append(result, tags[i])198 }199 }200 return result201}202func (s *SpecInfoGatherer) addToSpecsCache(key string, value *SpecDetail) {203 s.specsCache.specDetails[key] = value204}205func (s *SpecInfoGatherer) addToConceptsCache(key string, value *gauge.Concept) {206 if s.conceptsCache.concepts[key] == nil {207 s.conceptsCache.concepts[key] = make([]*gauge.Concept, 0)208 }209 s.conceptsCache.concepts[key] = append(s.conceptsCache.concepts[key], value)210}211func (s *SpecInfoGatherer) deleteFromConceptDictionary(file string) {212 for _, c := range s.conceptsCache.concepts[file] {213 if file == s.conceptDictionary.ConceptsMap[c.ConceptStep.Value].FileName {214 s.conceptDictionary.Remove(c.ConceptStep.Value)215 }216 }217}218func (s *SpecInfoGatherer) addToStepsCache(fileName string, allSteps []*gauge.Step) {219 s.stepsCache.steps[fileName] = allSteps220}221func (s *SpecInfoGatherer) getParsedSpecs(specFiles []string) []*SpecDetail {222 if s.conceptDictionary == nil {223 s.conceptDictionary = gauge.NewConceptDictionary()224 }225 parsedSpecs, parseResults := parser.ParseSpecFiles(specFiles, s.conceptDictionary, gauge.NewBuildErrors())226 specs := make(map[string]*SpecDetail)227 for _, spec := range parsedSpecs {228 specs[spec.FileName] = &SpecDetail{Spec: spec}229 }230 for _, v := range parseResults {231 _, ok := specs[v.FileName]232 if !ok {233 specs[v.FileName] = &SpecDetail{Spec: &gauge.Specification{FileName: v.FileName}, Errs: v.ParseErrors}234 }235 }236 details := make([]*SpecDetail, 0)237 for _, d := range specs {238 details = append(details, d)239 }240 return details241}242func (s *SpecInfoGatherer) getParsedConcepts() map[string]*gauge.Concept {243 var result *parser.ParseResult244 var err error245 s.conceptDictionary, result, err = parser.CreateConceptsDictionary()246 if err != nil {247 logger.Fatalf(true, "Unable to parse concepts : %s", err.Error())248 }249 handleParseFailures([]*parser.ParseResult{result})250 return s.conceptDictionary.ConceptsMap251}252func (s *SpecInfoGatherer) getStepsFromCachedSpecs() map[string][]*gauge.Step {253 s.specsCache.mutex.RLock()254 defer s.specsCache.mutex.RUnlock()255 var stepsFromSpecsMap = make(map[string][]*gauge.Step, 0)256 for _, detail := range s.specsCache.specDetails {257 stepsFromSpecsMap[detail.Spec.FileName] = append(stepsFromSpecsMap[detail.Spec.FileName], getStepsFromSpec(detail.Spec)...)258 }259 return stepsFromSpecsMap260}261func (s *SpecInfoGatherer) getStepsFromCachedConcepts() map[string][]*gauge.Step {262 var stepsFromConceptMap = make(map[string][]*gauge.Step, 0)263 s.conceptsCache.mutex.RLock()264 defer s.conceptsCache.mutex.RUnlock()265 for _, conceptList := range s.conceptsCache.concepts {266 for _, concept := range conceptList {267 stepsFromConceptMap[concept.FileName] = append(stepsFromConceptMap[concept.FileName], getStepsFromConcept(concept)...)268 }269 }270 return stepsFromConceptMap271}272func (s *SpecInfoGatherer) OnSpecFileModify(file string) {273 logger.Infof(false, "Spec file added / modified: %s", file)274 details := s.getParsedSpecs([]string{file})275 s.specsCache.mutex.Lock()276 s.addToSpecsCache(file, details[0])277 s.specsCache.mutex.Unlock()278 var steps []*gauge.Step279 steps = append(steps, getStepsFromSpec(details[0].Spec)...)280 s.stepsCache.mutex.Lock()281 s.addToStepsCache(file, steps)282 s.stepsCache.mutex.Unlock()283 s.paramsCache.mutex.Lock()284 s.updateParamCacheFromSpecs(file, details[0])285 s.paramsCache.mutex.Unlock()286 s.tagsCache.mutex.Lock()287 s.updateTagsCacheFromSpecs(file, details[0])288 s.tagsCache.mutex.Unlock()289}290func (s *SpecInfoGatherer) OnConceptFileModify(file string) {291 s.conceptsCache.mutex.Lock()292 defer s.conceptsCache.mutex.Unlock()293 logger.Infof(false, "Concept file added / modified: %s", file)294 s.deleteFromConceptDictionary(file)295 concepts, parseErrors, err := parser.AddConcepts([]string{file}, s.conceptDictionary)296 if err != nil {297 logger.Fatalf(true, "Unable to update concepts : %s", err.Error())298 }299 if len(parseErrors) > 0 {300 res := &parser.ParseResult{}301 res.ParseErrors = append(res.ParseErrors, parseErrors...)302 res.Ok = false303 handleParseFailures([]*parser.ParseResult{res})304 }305 s.conceptsCache.concepts[file] = make([]*gauge.Concept, 0)306 var stepsFromConcept []*gauge.Step307 for _, concept := range concepts {308 c := gauge.Concept{ConceptStep: concept, FileName: file}309 s.addToConceptsCache(file, &c)310 stepsFromConcept = append(stepsFromConcept, getStepsFromConcept(&c)...)311 }312 s.addToStepsCache(file, stepsFromConcept)313 s.paramsCache.mutex.Lock()314 defer s.paramsCache.mutex.Unlock()315 s.updateParamsCacheFromConcepts(file, s.conceptsCache.concepts[file])316}317func (s *SpecInfoGatherer) onSpecFileRemove(file string) {318 logger.Infof(false, "Spec file removed: %s", file)319 s.specsCache.mutex.Lock()320 defer s.specsCache.mutex.Unlock()321 delete(s.specsCache.specDetails, file)322 s.removeStepsFromCache(file)323}324func (s *SpecInfoGatherer) removeStepsFromCache(fileName string) {325 s.stepsCache.mutex.Lock()326 defer s.stepsCache.mutex.Unlock()327 delete(s.stepsCache.steps, fileName)328}329func (s *SpecInfoGatherer) onConceptFileRemove(file string) {330 logger.Infof(false, "Concept file removed: %s", file)331 s.conceptsCache.mutex.Lock()332 defer s.conceptsCache.mutex.Unlock()333 s.deleteFromConceptDictionary(file)334 delete(s.conceptsCache.concepts, file)335 s.removeStepsFromCache(file)336}337func (s *SpecInfoGatherer) onFileAdd(watcher *fsnotify.Watcher, file string) {338 if util.IsDir(file) {339 addDirToFileWatcher(watcher, file)340 }341 s.onFileModify(watcher, file)342}343func (s *SpecInfoGatherer) onFileModify(watcher *fsnotify.Watcher, file string) {344 if util.IsSpec(file) {345 s.OnSpecFileModify(file)346 } else if util.IsConcept(file) {347 s.OnConceptFileModify(file)348 }349}350func (s *SpecInfoGatherer) onFileRemove(watcher *fsnotify.Watcher, file string) {351 if util.IsSpec(file) {352 s.onSpecFileRemove(file)353 } else if util.IsConcept(file) {354 s.onConceptFileRemove(file)355 } else {356 removeWatcherOn(watcher, file)357 }358}359func (s *SpecInfoGatherer) onFileRename(watcher *fsnotify.Watcher, file string) {360 s.onFileRemove(watcher, file)361}362func (s *SpecInfoGatherer) handleEvent(event fsnotify.Event, watcher *fsnotify.Watcher) {363 s.waitGroup.Wait()364 file, err := filepath.Abs(event.Name)365 if err != nil {366 logger.Errorf(false, "Failed to get abs file path for %s: %s", event.Name, err)367 return368 }369 if util.IsSpec(file) || util.IsConcept(file) || util.IsDir(file) {370 switch event.Op {371 case fsnotify.Create:372 s.onFileAdd(watcher, file)373 case fsnotify.Write:374 s.onFileModify(watcher, file)375 case fsnotify.Rename:376 s.onFileRename(watcher, file)377 case fsnotify.Remove:378 s.onFileRemove(watcher, file)379 }380 }381}382func (s *SpecInfoGatherer) watchForFileChanges() {383 s.waitGroup.Add(1)384 watcher, err := fsnotify.NewWatcher()385 if err != nil {386 logger.Errorf(false, "Error creating fileWatcher: %s", err)387 }388 defer watcher.Close()389 done := make(chan bool)390 go func() {391 for {392 select {393 case event := <-watcher.Events:394 s.handleEvent(event, watcher)395 case err := <-watcher.Errors:396 logger.Errorf(false, "Error event while watching specs %s", err)397 }398 }399 }()400 var allDirsToWatch []string401 var specDir string402 for _, dir := range s.SpecDirs {403 specDir = filepath.Join(config.ProjectRoot, dir)404 allDirsToWatch = append(allDirsToWatch, specDir)405 allDirsToWatch = append(allDirsToWatch, util.FindAllNestedDirs(specDir)...)406 }407 for _, dir := range allDirsToWatch {408 addDirToFileWatcher(watcher, dir)409 }410 s.waitGroup.Done()411 <-done412}413// GetAvailableSpecs returns the list of all the specs in the gauge project414func (s *SpecInfoGatherer) GetAvailableSpecDetails(specs []string) []*SpecDetail {415 if len(specs) < 1 {416 specs = util.GetSpecDirs()417 }418 specFiles := getSpecFiles(specs)419 s.specsCache.mutex.RLock()420 defer s.specsCache.mutex.RUnlock()421 var details []*SpecDetail422 for _, f := range specFiles {423 if d, ok := s.specsCache.specDetails[f]; ok {424 details = append(details, d)425 }426 }427 return details428}429func (s *SpecInfoGatherer) GetSpecDirs() []string {430 return s.SpecDirs431}432// Steps returns the list of all the steps in the gauge project. Duplicate steps are filtered433func (s *SpecInfoGatherer) Steps(filterConcepts bool) []*gauge.Step {434 s.stepsCache.mutex.RLock()435 defer s.stepsCache.mutex.RUnlock()436 filteredSteps := make(map[string]*gauge.Step)437 for _, steps := range s.stepsCache.steps {438 for _, s := range steps {439 if !filterConcepts || !s.IsConcept {440 filteredSteps[s.Value] = s441 }442 }443 }444 var steps []*gauge.Step445 for _, sv := range filteredSteps {446 steps = append(steps, sv)447 }448 return steps449}450// Steps returns the list of all the steps in the gauge project including duplicate steps451func (s *SpecInfoGatherer) AllSteps(filterConcepts bool) []*gauge.Step {452 s.stepsCache.mutex.RLock()453 defer s.stepsCache.mutex.RUnlock()454 var allSteps []*gauge.Step455 for _, steps := range s.stepsCache.steps {456 if filterConcepts {457 for _, s := range steps {458 if !s.IsConcept {459 allSteps = append(allSteps, s)460 }461 }462 } else {463 allSteps = append(allSteps, steps...)464 }465 }466 return allSteps467}468// Steps returns the list of all the steps in the gauge project469func (s *SpecInfoGatherer) Params(filePath string, argType gauge.ArgType) []gauge.StepArg {470 s.paramsCache.mutex.RLock()471 defer s.paramsCache.mutex.RUnlock()472 var params []gauge.StepArg473 if argType == gauge.Static {474 for _, param := range s.paramsCache.staticParams[filePath] {475 params = append(params, param)476 }477 } else {478 for _, param := range s.paramsCache.dynamicParams[filePath] {479 params = append(params, param)480 }481 }482 return params483}484// Concepts returns an array containing information about all the concepts present in the Gauge project485func (s *SpecInfoGatherer) Concepts() []*gauge_messages.ConceptInfo {486 var conceptInfos []*gauge_messages.ConceptInfo487 s.conceptsCache.mutex.RLock()488 defer s.conceptsCache.mutex.RUnlock()489 for _, conceptList := range s.conceptsCache.concepts {490 for _, concept := range conceptList {491 stepValue := parser.CreateStepValue(concept.ConceptStep)492 conceptInfos = append(conceptInfos, &gauge_messages.ConceptInfo{StepValue: gauge.ConvertToProtoStepValue(&stepValue), Filepath: concept.FileName, LineNumber: int32(concept.ConceptStep.LineNo)})493 }494 }495 return conceptInfos496}497func (s *SpecInfoGatherer) Tags() []string {498 s.tagsCache.mutex.RLock()499 defer s.tagsCache.mutex.RUnlock()500 var allTags []string501 for _, tags := range s.tagsCache.tags {502 allTags = append(allTags, tags...)503 }504 return removeDuplicateTags(allTags)505}506// SearchConceptDictionary searches for a concept in concept dictionary507func (s *SpecInfoGatherer) SearchConceptDictionary(stepValue string) *gauge.Concept {508 return s.conceptDictionary.Search(stepValue)509}510func getStepsFromSpec(spec *gauge.Specification) []*gauge.Step {511 steps := spec.Contexts512 for _, scenario := range spec.Scenarios {513 steps = append(steps, scenario.Steps...)514 }515 steps = append(steps, spec.TearDownSteps...)516 return steps517}518func getStepsFromConcept(concept *gauge.Concept) []*gauge.Step {...

Full Screen

Full Screen

removeDuplicateTags

Using AI Code Generation

copy

Full Screen

1infoGatherer ig;2ig.removeDuplicateTags();3infoGatherer ig;4ig.removeDuplicateTags();5infoGatherer ig;6ig.removeDuplicateTags();7infoGatherer ig;8ig.removeDuplicateTags();9infoGatherer ig;10ig.removeDuplicateTags();11infoGatherer ig;12ig.removeDuplicateTags();13infoGatherer ig;14ig.removeDuplicateTags();15infoGatherer ig;16ig.removeDuplicateTags();17infoGatherer ig;18ig.removeDuplicateTags();19infoGatherer ig;20ig.removeDuplicateTags();21infoGatherer ig;22ig.removeDuplicateTags();23infoGatherer ig;24ig.removeDuplicateTags();25infoGatherer ig;26ig.removeDuplicateTags();27infoGatherer ig;28ig.removeDuplicateTags();29infoGatherer ig;30ig.removeDuplicateTags();

Full Screen

Full Screen

removeDuplicateTags

Using AI Code Generation

copy

Full Screen

1func main() {2 infoGatherer.removeDuplicateTags()3}4func main() {5 infoGatherer.removeDuplicateTags()6}7func main() {8 infoGatherer.removeDuplicateTags()9}10func main() {11 infoGatherer.removeDuplicateTags()12}13func main() {14 infoGatherer.removeDuplicateTags()15}16func main() {17 infoGatherer.removeDuplicateTags()18}19func main() {20 infoGatherer.removeDuplicateTags()21}22func main() {23 infoGatherer.removeDuplicateTags()24}25func main() {26 infoGatherer.removeDuplicateTags()27}28func main() {29 infoGatherer.removeDuplicateTags()30}31func main() {32 infoGatherer.removeDuplicateTags()33}

Full Screen

Full Screen

removeDuplicateTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 info := infoGatherer{}4 info.removeDuplicateTags([]string{"a", "b", "a", "c", "c", "c", "d", "d", "d", "d"})5 fmt.Println("After removing duplicate tags: ")6 pretty.Println(info)7}8[]string{9}

Full Screen

Full Screen

removeDuplicateTags

Using AI Code Generation

copy

Full Screen

1func main() {2 info := infoGatherer{}3 info.removeDuplicateTags()4}5func main() {6 info := infoGatherer{}7 info.removeDuplicateTags()8}9func main() {10 info := infoGatherer{}11 info.removeDuplicateTags()12}13func main() {14 info := infoGatherer{}15 info.removeDuplicateTags()16}17func main() {18 info := infoGatherer{}19 info.removeDuplicateTags()20}21func main() {22 info := infoGatherer{}23 info.removeDuplicateTags()24}25func main() {26 info := infoGatherer{}27 info.removeDuplicateTags()28}29func main() {30 info := infoGatherer{}31 info.removeDuplicateTags()32}

Full Screen

Full Screen

removeDuplicateTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 infoGatherer = InfoGatherer{}4 infoGatherer.removeDuplicateTags(" <a> <a> <a> <b> <b> <c> ")5}6import (7func main() {8 infoGatherer = InfoGatherer{}9 infoGatherer.removeDuplicateTags(" <a> <a> <a> <b> <b> <c> ")10}11import (12func main() {13 infoGatherer = InfoGatherer{}14 infoGatherer.removeDuplicateTags(" <a> <a> <a> <b> <b> <c> ")15}16import (17func main() {18 infoGatherer = InfoGatherer{}19 infoGatherer.removeDuplicateTags(" <a> <a> <a> <b> <b> <c> ")20}21import (22func main() {23 infoGatherer = InfoGatherer{}24 infoGatherer.removeDuplicateTags(" <a> <a> <a> <b> <b> <c> ")25}26import (27func main() {28 infoGatherer = InfoGatherer{}29 infoGatherer.removeDuplicateTags(" <a> <a> <a> <b> <b> <c>

Full Screen

Full Screen

removeDuplicateTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 info := helpers.NewInfoGatherer()4 tags := []string{"a", "b", "c", "d", "a", "b", "e"}5 uniqueTags := info.RemoveDuplicateTags(tags)6 fmt.Println(uniqueTags)7}

Full Screen

Full Screen

removeDuplicateTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 infoGathererObj := infoGatherer{}4 tags := []string{"tag1", "tag2", "tag1", "tag3", "tag4", "tag4"}5 uniqueTags := infoGathererObj.removeDuplicateTags(tags)6 fmt.Println(uniqueTags)7}8import (9func main() {10 infoGathererObj := infoGatherer{}11 tags := []string{"tag1", "tag2", "tag1", "tag3", "tag4", "tag4"}12 uniqueTags := infoGathererObj.removeDuplicateTags(tags)13 fmt.Println(uniqueTags)14}15The above code will work fine in go 1.10.3 but not in go 1.11.1. The reason is that in go 1.11.1, the compiler will not allow the same package to be imported twice in the same package. This is because the package would be imported twice in the

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 Gauge automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful