How to use filterSpecsByTags method of filter Package

Best Gauge code snippet using filter.filterSpecsByTags

specItemFilter_test.go

Source:specItemFilter_test.go Github

copy

Full Screen

...257 var specs []*gauge.Specification258 specs = append(specs, spec1, spec2)259 c.Assert(specs[0].Tags.Values()[0], Equals, myTags[0])260 c.Assert(specs[0].Tags.Values()[1], Equals, myTags[1])261 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag2")262 c.Assert(len(filteredSpecs), Equals, 1)263 c.Assert(len(otherSpecs), Equals, 1)264}265func (s *MySuite) TestToEvaluateTagExpression(c *C) {266 myTags := []string{"tag1", "tag2"}267 scenario1 := &gauge.Scenario{268 Heading: &gauge.Heading{Value: "First Scenario"},269 Span: &gauge.Span{Start: 1, End: 3},270 Tags: &gauge.Tags{RawValues: [][]string{{myTags[0]}}},271 }272 scenario2 := &gauge.Scenario{273 Heading: &gauge.Heading{Value: "Second Scenario"},274 Span: &gauge.Span{Start: 4, End: 6},275 Tags: &gauge.Tags{RawValues: [][]string{{"tag3"}}},276 }277 scenario3 := &gauge.Scenario{278 Heading: &gauge.Heading{Value: "Third Scenario"},279 Span: &gauge.Span{Start: 1, End: 3},280 }281 scenario4 := &gauge.Scenario{282 Heading: &gauge.Heading{Value: "Fourth Scenario"},283 Span: &gauge.Span{Start: 4, End: 6},284 }285 spec1 := &gauge.Specification{286 Items: []gauge.Item{scenario1, scenario2},287 Scenarios: []*gauge.Scenario{scenario1, scenario2},288 }289 spec2 := &gauge.Specification{290 Items: []gauge.Item{scenario3, scenario4},291 Scenarios: []*gauge.Scenario{scenario3, scenario4},292 Tags: &gauge.Tags{RawValues: [][]string{myTags}},293 }294 var specs []*gauge.Specification295 specs = append(specs, spec1, spec2)296 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & !(tag1 & tag4) & (tag2 | tag3)")297 c.Assert(len(filteredSpecs), Equals, 1)298 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 2)299 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario3)300 c.Assert(filteredSpecs[0].Scenarios[1], Equals, scenario4)301 c.Assert(len(otherSpecs), Equals, 1)302 c.Assert(len(otherSpecs[0].Scenarios), Equals, 2)303 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario1)304 c.Assert(otherSpecs[0].Scenarios[1], Equals, scenario2)305}306func (s *MySuite) TestToFilterSpecsByWrongTagExpression(c *C) {307 myTags := []string{"tag1", "tag2"}308 scenario1 := &gauge.Scenario{309 Heading: &gauge.Heading{Value: "First Scenario"},310 Span: &gauge.Span{Start: 1, End: 3},311 }312 scenario2 := &gauge.Scenario{313 Heading: &gauge.Heading{Value: "Second Scenario"},314 Span: &gauge.Span{Start: 4, End: 6},315 }316 spec1 := &gauge.Specification{317 Items: []gauge.Item{scenario1, scenario2},318 Scenarios: []*gauge.Scenario{scenario1, scenario2},319 Tags: &gauge.Tags{RawValues: [][]string{myTags}},320 }321 spec2 := &gauge.Specification{322 Items: []gauge.Item{scenario1, scenario2},323 Scenarios: []*gauge.Scenario{scenario1, scenario2},324 }325 var specs []*gauge.Specification326 specs = append(specs, spec1, spec2)327 c.Assert(specs[0].Tags.Values()[0], Equals, myTags[0])328 c.Assert(specs[0].Tags.Values()[1], Equals, myTags[1])329 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "(tag1 & tag2")330 c.Assert(len(filteredSpecs), Equals, 0)331 c.Assert(len(otherSpecs), Equals, 2)332}333func (s *MySuite) TestToFilterMultipleScenariosByMultipleTags(c *C) {334 myTags := []string{"tag1", "tag2"}335 scenario1 := &gauge.Scenario{336 Heading: &gauge.Heading{Value: "First Scenario"},337 Span: &gauge.Span{Start: 1, End: 3},338 Tags: &gauge.Tags{RawValues: [][]string{{"tag1"}}},339 }340 scenario2 := &gauge.Scenario{341 Heading: &gauge.Heading{Value: "Second Scenario"},342 Span: &gauge.Span{Start: 4, End: 6},343 Tags: &gauge.Tags{RawValues: [][]string{myTags}},344 }345 scenario3 := &gauge.Scenario{346 Heading: &gauge.Heading{Value: "Third Scenario"},347 Span: &gauge.Span{Start: 1, End: 3},348 Tags: &gauge.Tags{RawValues: [][]string{myTags}},349 }350 scenario4 := &gauge.Scenario{351 Heading: &gauge.Heading{Value: "Fourth Scenario"},352 Span: &gauge.Span{Start: 4, End: 6},353 Tags: &gauge.Tags{RawValues: [][]string{{"prod", "tag7", "tag1", "tag2"}}},354 }355 spec1 := &gauge.Specification{356 Items: []gauge.Item{scenario1, scenario2, scenario3, scenario4},357 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3, scenario4},358 }359 var specs []*gauge.Specification360 specs = append(specs, spec1)361 c.Assert(len(specs[0].Scenarios), Equals, 4)362 c.Assert(len(specs[0].Scenarios[0].Tags.Values()), Equals, 1)363 c.Assert(len(specs[0].Scenarios[1].Tags.Values()), Equals, 2)364 c.Assert(len(specs[0].Scenarios[2].Tags.Values()), Equals, 2)365 c.Assert(len(specs[0].Scenarios[3].Tags.Values()), Equals, 4)366 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag2")367 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 3)368 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario2)369 c.Assert(filteredSpecs[0].Scenarios[1], Equals, scenario3)370 c.Assert(filteredSpecs[0].Scenarios[2], Equals, scenario4)371 c.Assert(len(otherSpecs[0].Scenarios), Equals, 1)372 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario1)373}374func (s *MySuite) TestToFilterScenariosByTagsAtSpecLevel(c *C) {375 myTags := []string{"tag1", "tag2"}376 scenario1 := &gauge.Scenario{377 Heading: &gauge.Heading{Value: "First Scenario"},378 Span: &gauge.Span{Start: 1, End: 3},379 }380 scenario2 := &gauge.Scenario{381 Heading: &gauge.Heading{Value: "Second Scenario"},382 Span: &gauge.Span{Start: 4, End: 6},383 }384 scenario3 := &gauge.Scenario{385 Heading: &gauge.Heading{Value: "Third Scenario"},386 Span: &gauge.Span{Start: 4, End: 6},387 }388 spec1 := &gauge.Specification{389 Items: []gauge.Item{scenario1, scenario2, scenario3},390 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},391 Tags: &gauge.Tags{RawValues: [][]string{myTags}},392 }393 var specs []*gauge.Specification394 specs = append(specs, spec1)395 c.Assert(len(specs[0].Scenarios), Equals, 3)396 c.Assert(len(specs[0].Tags.Values()), Equals, 2)397 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag2")398 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 3)399 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario1)400 c.Assert(filteredSpecs[0].Scenarios[1], Equals, scenario2)401 c.Assert(filteredSpecs[0].Scenarios[2], Equals, scenario3)402 c.Assert(len(otherSpecs), Equals, 0)403}404func (s *MySuite) TestToFilterScenariosByTagExpWithDuplicateTagNames(c *C) {405 myTags := []string{"tag1", "tag12"}406 scenario1 := &gauge.Scenario{407 Heading: &gauge.Heading{Value: "First Scenario"},408 Span: &gauge.Span{Start: 1, End: 3},409 Tags: &gauge.Tags{RawValues: [][]string{myTags}},410 }411 scenario2 := &gauge.Scenario{412 Heading: &gauge.Heading{Value: "Second Scenario"},413 Span: &gauge.Span{Start: 4, End: 6},414 Tags: &gauge.Tags{RawValues: [][]string{{"tag1"}}},415 }416 scenario3 := &gauge.Scenario{417 Heading: &gauge.Heading{Value: "Third Scenario"},418 Span: &gauge.Span{Start: 4, End: 6},419 Tags: &gauge.Tags{RawValues: [][]string{{"tag12"}}},420 }421 spec1 := &gauge.Specification{422 Items: []gauge.Item{scenario1, scenario2, scenario3},423 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},424 }425 var specs []*gauge.Specification426 specs = append(specs, spec1)427 c.Assert(len(specs), Equals, 1)428 c.Assert(len(specs[0].Scenarios), Equals, 3)429 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag12")430 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 1)431 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario1)432 c.Assert(len(otherSpecs), Equals, 1)433 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario2)434 c.Assert(otherSpecs[0].Scenarios[1], Equals, scenario3)435}436func (s *MySuite) TestFilterTags(c *C) {437 specTags := []string{"abcd", "foo", "bar", "foo bar"}438 tagFilter := NewScenarioFilterBasedOnTags(specTags, "abcd & foo bar")439 evaluateTrue := tagFilter.filterTags(specTags)440 c.Assert(evaluateTrue, Equals, true)441}442func (s *MySuite) TestFilterMixedCaseTags(c *C) {443 before()444 defer after()445 specTags := []string{"abcd", "foo", "BAR", "foo bar"}446 tagFilter := NewScenarioFilterBasedOnTags(specTags, "abcd & FOO bar")447 evaluateTrue := tagFilter.filterTags(specTags)448 c.Assert(evaluateTrue, Equals, true)449}450func (s *MySuite) TestSanitizeTags(c *C) {451 specTags := []string{"abcd", "foo", "bar", "foo bar"}452 tagFilter := NewScenarioFilterBasedOnTags(specTags, "abcd & foo bar | true")453 evaluateTrue := tagFilter.filterTags(specTags)454 c.Assert(evaluateTrue, Equals, true)455}456func (s *MySuite) TestSanitizeMixedCaseTags(c *C) {457 before()458 defer after()459 specTags := []string{"abcd", "foo", "bar", "foo bar"}460 tagFilter := NewScenarioFilterBasedOnTags(specTags, "abcd & foo Bar | true")461 evaluateTrue := tagFilter.filterTags(specTags)462 c.Assert(evaluateTrue, Equals, true)463}464func (s *MySuite) TestToFilterSpecsByTags(c *C) {465 myTags := []string{"tag1", "tag2"}466 scenario1 := &gauge.Scenario{467 Heading: &gauge.Heading{Value: "First Scenario"},468 Span: &gauge.Span{Start: 1, End: 3},469 Tags: &gauge.Tags{RawValues: [][]string{myTags}},470 }471 scenario2 := &gauge.Scenario{472 Heading: &gauge.Heading{Value: "Second Scenario"},473 Span: &gauge.Span{Start: 4, End: 6},474 }475 scenario3 := &gauge.Scenario{476 Heading: &gauge.Heading{Value: "Third Scenario"},477 Span: &gauge.Span{Start: 1, End: 3},478 }479 spec1 := &gauge.Specification{480 Items: []gauge.Item{scenario1, scenario2},481 Scenarios: []*gauge.Scenario{scenario1, scenario2},482 }483 spec2 := &gauge.Specification{484 Items: []gauge.Item{scenario2, scenario3},485 Scenarios: []*gauge.Scenario{scenario2, scenario3},486 }487 spec3 := &gauge.Specification{488 Items: []gauge.Item{scenario1, scenario3},489 Scenarios: []*gauge.Scenario{scenario1, scenario3},490 }491 var specs []*gauge.Specification492 specs = append(specs, spec1, spec2, spec3)493 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag2")494 c.Assert(len(filteredSpecs), Equals, 2)495 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 1)496 c.Assert(len(filteredSpecs[1].Scenarios), Equals, 1)497 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario1)498 c.Assert(filteredSpecs[1].Scenarios[0], Equals, scenario1)499 c.Assert(len(otherSpecs), Equals, 3)500 c.Assert(len(otherSpecs[0].Scenarios), Equals, 1)501 c.Assert(len(otherSpecs[1].Scenarios), Equals, 2)502 c.Assert(len(otherSpecs[2].Scenarios), Equals, 1)503 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario2)504 c.Assert(otherSpecs[1].Scenarios[0], Equals, scenario2)505 c.Assert(otherSpecs[1].Scenarios[1], Equals, scenario3)506 c.Assert(otherSpecs[2].Scenarios[0], Equals, scenario3)507}508func (s *MySuite) TestToFilterSpecsByMixedCaseTags(c *C) {509 before()510 defer after()511 myTags := []string{"tag1", "TAG2"}512 scenario1 := &gauge.Scenario{513 Heading: &gauge.Heading{Value: "First Scenario"},514 Span: &gauge.Span{Start: 1, End: 3},515 Tags: &gauge.Tags{RawValues: [][]string{myTags}},516 }517 scenario2 := &gauge.Scenario{518 Heading: &gauge.Heading{Value: "Second Scenario"},519 Span: &gauge.Span{Start: 4, End: 6},520 }521 scenario3 := &gauge.Scenario{522 Heading: &gauge.Heading{Value: "Third Scenario"},523 Span: &gauge.Span{Start: 1, End: 3},524 }525 spec1 := &gauge.Specification{526 Items: []gauge.Item{scenario1, scenario2},527 Scenarios: []*gauge.Scenario{scenario1, scenario2},528 }529 spec2 := &gauge.Specification{530 Items: []gauge.Item{scenario2, scenario3},531 Scenarios: []*gauge.Scenario{scenario2, scenario3},532 }533 spec3 := &gauge.Specification{534 Items: []gauge.Item{scenario1, scenario3},535 Scenarios: []*gauge.Scenario{scenario1, scenario3},536 }537 var specs []*gauge.Specification538 specs = append(specs, spec1, spec2, spec3)539 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & Tag2")540 c.Assert(len(filteredSpecs), Equals, 2)541 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 1)542 c.Assert(len(filteredSpecs[1].Scenarios), Equals, 1)543 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario1)544 c.Assert(filteredSpecs[1].Scenarios[0], Equals, scenario1)545 c.Assert(len(otherSpecs), Equals, 3)546 c.Assert(len(otherSpecs[0].Scenarios), Equals, 1)547 c.Assert(len(otherSpecs[1].Scenarios), Equals, 2)548 c.Assert(len(otherSpecs[2].Scenarios), Equals, 1)549 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario2)550 c.Assert(otherSpecs[1].Scenarios[0], Equals, scenario2)551 c.Assert(otherSpecs[1].Scenarios[1], Equals, scenario3)552 c.Assert(otherSpecs[2].Scenarios[0], Equals, scenario3)553}554func (s *MySuite) TestToFilterScenariosByTag(c *C) {555 myTags := []string{"tag1", "tag2"}556 scenario1 := &gauge.Scenario{557 Heading: &gauge.Heading{Value: "First Scenario"},558 Span: &gauge.Span{Start: 1, End: 3},559 }560 scenario2 := &gauge.Scenario{561 Heading: &gauge.Heading{Value: "Second Scenario"},562 Span: &gauge.Span{Start: 4, End: 6},563 Tags: &gauge.Tags{RawValues: [][]string{myTags}},564 }565 scenario3 := &gauge.Scenario{566 Heading: &gauge.Heading{Value: "Third Scenario"},567 Span: &gauge.Span{Start: 4, End: 6},568 }569 spec1 := &gauge.Specification{570 Items: []gauge.Item{scenario1, scenario2, scenario3},571 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},572 }573 var specs []*gauge.Specification574 specs = append(specs, spec1)575 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag2")576 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 1)577 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario2)578 c.Assert(len(otherSpecs), Equals, 1)579 c.Assert(len(otherSpecs[0].Scenarios), Equals, 2)580 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario1)581 c.Assert(otherSpecs[0].Scenarios[1], Equals, scenario3)582}583func (s *MySuite) TestToFilterScenariosByMixedCaseTag(c *C) {584 before()585 defer after()586 myTags := []string{"Tag-1", "tag2"}587 scenario1 := &gauge.Scenario{588 Heading: &gauge.Heading{Value: "First Scenario"},589 Span: &gauge.Span{Start: 1, End: 3},590 }591 scenario2 := &gauge.Scenario{592 Heading: &gauge.Heading{Value: "Second Scenario"},593 Span: &gauge.Span{Start: 4, End: 6},594 Tags: &gauge.Tags{RawValues: [][]string{myTags}},595 }596 scenario3 := &gauge.Scenario{597 Heading: &gauge.Heading{Value: "Third Scenario"},598 Span: &gauge.Span{Start: 4, End: 6},599 }600 spec1 := &gauge.Specification{601 Items: []gauge.Item{scenario1, scenario2, scenario3},602 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},603 }604 var specs []*gauge.Specification605 specs = append(specs, spec1)606 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag-1 & tag2")607 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 1)608 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario2)609 c.Assert(len(otherSpecs), Equals, 1)610 c.Assert(len(otherSpecs[0].Scenarios), Equals, 2)611 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario1)612 c.Assert(otherSpecs[0].Scenarios[1], Equals, scenario3)613}614func (s *MySuite) TestToFilterMultipleScenariosByTags(c *C) {615 myTags := []string{"tag1", "tag2"}616 scenario1 := &gauge.Scenario{617 Heading: &gauge.Heading{Value: "First Scenario"},618 Span: &gauge.Span{Start: 1, End: 3},619 Tags: &gauge.Tags{RawValues: [][]string{{"tag1"}}},620 }621 scenario2 := &gauge.Scenario{622 Heading: &gauge.Heading{Value: "Second Scenario"},623 Span: &gauge.Span{Start: 4, End: 6},624 Tags: &gauge.Tags{RawValues: [][]string{myTags}},625 }626 scenario3 := &gauge.Scenario{627 Heading: &gauge.Heading{Value: "Third Scenario"},628 Span: &gauge.Span{Start: 4, End: 6},629 Tags: &gauge.Tags{RawValues: [][]string{myTags}},630 }631 spec1 := &gauge.Specification{632 Items: []gauge.Item{scenario1, scenario2, scenario3},633 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},634 }635 var specs []*gauge.Specification636 specs = append(specs, spec1)637 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag1 & tag2")638 c.Assert(len(filteredSpecs[0].Scenarios), Equals, 2)639 c.Assert(filteredSpecs[0].Scenarios[0], Equals, scenario2)640 c.Assert(filteredSpecs[0].Scenarios[1], Equals, scenario3)641 c.Assert(len(otherSpecs), Equals, 1)642 c.Assert(len(otherSpecs[0].Scenarios), Equals, 1)643 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario1)644}645func (s *MySuite) TestToFilterScenariosByUnavailableTags(c *C) {646 myTags := []string{"tag1", "tag2"}647 scenario1 := &gauge.Scenario{648 Heading: &gauge.Heading{Value: "First Scenario"},649 Span: &gauge.Span{Start: 1, End: 3},650 }651 scenario2 := &gauge.Scenario{652 Heading: &gauge.Heading{Value: "Second Scenario"},653 Span: &gauge.Span{Start: 4, End: 6},654 Tags: &gauge.Tags{RawValues: [][]string{myTags}},655 }656 scenario3 := &gauge.Scenario{657 Heading: &gauge.Heading{Value: "Third Scenario"},658 Span: &gauge.Span{Start: 4, End: 6},659 }660 spec1 := &gauge.Specification{661 Items: []gauge.Item{scenario1, scenario2, scenario3},662 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},663 }664 var specs []*gauge.Specification665 specs = append(specs, spec1)666 filteredSpecs, otherSpecs := filterSpecsByTags(specs, "tag3")667 c.Assert(len(filteredSpecs), Equals, 0)668 c.Assert(len(otherSpecs), Equals, 1)669 c.Assert(len(otherSpecs[0].Scenarios), Equals, 3)670 c.Assert(otherSpecs[0].Scenarios[0], Equals, scenario1)671 c.Assert(otherSpecs[0].Scenarios[1], Equals, scenario2)672 c.Assert(otherSpecs[0].Scenarios[2], Equals, scenario3)673}674func (s *MySuite) TestFilterScenariosByName(c *C) {675 scenario1 := &gauge.Scenario{676 Heading: &gauge.Heading{Value: "First Scenario"},677 }678 scenario2 := &gauge.Scenario{679 Heading: &gauge.Heading{Value: "Second Scenario"},680 }681 spec1 := &gauge.Specification{682 Items: []gauge.Item{scenario1, scenario2},683 Scenarios: []*gauge.Scenario{scenario1, scenario2},684 }685 var scenarios = []string{"First Scenario"}686 var specs []*gauge.Specification687 specs = append(specs, spec1)688 c.Assert(len(specs[0].Scenarios), Equals, 2)689 specs = filterSpecsByScenarioName(specs, scenarios)690 c.Assert(len(specs[0].Scenarios), Equals, 1)691}692func (s *MySuite) TestFilterScenarioWhichDoesNotExists(c *C) {693 scenario1 := &gauge.Scenario{694 Heading: &gauge.Heading{Value: "First Scenario"},695 }696 scenario2 := &gauge.Scenario{697 Heading: &gauge.Heading{Value: "Second Scenario"},698 }699 spec1 := &gauge.Specification{700 Items: []gauge.Item{scenario1, scenario2},701 Scenarios: []*gauge.Scenario{scenario1, scenario2},702 }703 var scenarios = []string{"Third Scenario"}704 var specs []*gauge.Specification705 specs = append(specs, spec1)706 c.Assert(len(specs[0].Scenarios), Equals, 2)707 specs = filterSpecsByScenarioName(specs, scenarios)708 c.Assert(len(specs), Equals, 0)709}710func (s *MySuite) TestFilterMultipleScenariosByName(c *C) {711 scenario1 := &gauge.Scenario{712 Heading: &gauge.Heading{Value: "First Scenario"},713 }714 scenario2 := &gauge.Scenario{715 Heading: &gauge.Heading{Value: "Second Scenario"},716 }717 spec1 := &gauge.Specification{718 Items: []gauge.Item{scenario1, scenario2},719 Scenarios: []*gauge.Scenario{scenario1, scenario2},720 }721 var scenarios = []string{"First Scenario", "Second Scenario"}722 var specs []*gauge.Specification723 specs = append(specs, spec1)724 c.Assert(len(specs[0].Scenarios), Equals, 2)725 specs = filterSpecsByScenarioName(specs, scenarios)726 c.Assert(len(specs[0].Scenarios), Equals, 2)727}728func (s *MySuite) TestFilterInvalidScenarios(c *C) {729 scenario1 := &gauge.Scenario{730 Heading: &gauge.Heading{Value: "First Scenario"},731 }732 scenario2 := &gauge.Scenario{733 Heading: &gauge.Heading{Value: "Second Scenario"},734 }735 spec1 := &gauge.Specification{736 Items: []gauge.Item{scenario1, scenario2},737 Scenarios: []*gauge.Scenario{scenario1, scenario2},738 }739 var scenarios = []string{"First Scenario", "Third Scenario"}740 var specs []*gauge.Specification741 specs = append(specs, spec1)742 c.Assert(len(specs[0].Scenarios), Equals, 2)743 filteredScenarios := filterValidScenarios(specs, scenarios)744 c.Assert(len(filteredScenarios), Equals, 1)745 c.Assert(filteredScenarios[0], Equals, "First Scenario")746}747func (s *MySuite) TestScenarioTagFilterShouldNotRemoveNonScenarioKindItems(c *C) {748 scenario1 := &gauge.Scenario{749 Heading: &gauge.Heading{Value: "First Scenario"},750 Span: &gauge.Span{Start: 1, End: 3},751 }752 scenario2 := &gauge.Scenario{753 Heading: &gauge.Heading{Value: "Second Scenario"},754 Span: &gauge.Span{Start: 4, End: 6},755 Tags: &gauge.Tags{RawValues: [][]string{{"tag2"}}},756 }757 scenario3 := &gauge.Scenario{758 Heading: &gauge.Heading{Value: "Third Scenario"},759 Span: &gauge.Span{Start: 7, End: 10},760 Tags: &gauge.Tags{RawValues: [][]string{{"tag1"}}},761 }762 spec := &gauge.Specification{763 Items: []gauge.Item{scenario1, scenario2, scenario3, &gauge.Table{}, &gauge.Comment{Value: "Comment", LineNo: 1}, &gauge.Step{}},764 Scenarios: []*gauge.Scenario{scenario1, scenario2, scenario3},765 }766 specWithFilteredItems, specWithOtherItems := filterSpecsByTags([]*gauge.Specification{spec}, "tag1 | tag2")767 c.Assert(len(specWithFilteredItems), Equals, 1)768 c.Assert(len(specWithFilteredItems[0].Items), Equals, 5)769 c.Assert(len(specWithOtherItems), Equals, 1)770 c.Assert(len(specWithOtherItems[0].Items), Equals, 4)771}...

Full Screen

Full Screen

filterSpecsByTags

Using AI Code Generation

copy

Full Screen

1func main() {2 specs := []spec.Spec{3 {4 Tags: []string{"tag1", "tag2"},5 },6 {7 Tags: []string{"tag2", "tag3"},8 },9 {10 Tags: []string{"tag1", "tag3"},11 },12 {13 Tags: []string{"tag1", "tag2", "tag3"},14 },15 }16 tags = []string{"tag1", "tag2"}17 specs = filter.FilterSpecsByTags(specs, tags)18 fmt.Println(specs)19}20[{[tag1 tag2]} {[tag1 tag2 tag3]}]21func main() {22 specs := []spec.Spec{23 {24 Tags: []string{"tag1", "tag2"},25 },26 {27 Tags: []string{"tag2", "tag3"},28 },29 {30 Tags: []string{"tag1", "tag3"},31 },32 {33 Tags: []string{"tag1", "tag2", "tag3"},34 },35 }36 tags = []string{"tag2", "tag3"}37 specs = filter.FilterSpecsByTags(specs, tags)38 fmt.Println(specs)39}40[{[tag2 tag3]} {[tag1 tag2 tag3]}]41func main() {42 specs := []spec.Spec{43 {44 Tags: []string{"tag1", "tag2"},45 },46 {47 Tags: []string{"tag2", "tag3"},48 },49 {50 Tags: []string{"tag1", "tag3"},51 },52 {53 Tags: []string{"tag1", "tag2", "tag3"},54 },55 }56 tags = []string{"tag1", "tag2", "tag3"}57 specs = filter.FilterSpecsByTags(specs, tags)58 fmt.Println(specs)59}60[{[tag1 tag2 tag3]}]61func main() {

Full Screen

Full Screen

filterSpecsByTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 config.DefaultReporterConfig = types.ReporterConfig{4 }5 fmt.Println(config.DefaultReporterConfig.SlowSpecThreshold)6}7import (8func main() {9 config.DefaultReporterConfig = types.ReporterConfig{10 }11 fmt.Println(config.DefaultReporterConfig.SlowSpecThreshold)12}13import (14func main() {15 config.DefaultReporterConfig = types.ReporterConfig{16 }17 fmt.Println(config.DefaultReporterConfig.SlowSpecThreshold)18}19import (20func main() {21 config.DefaultReporterConfig = types.ReporterConfig{22 }23 fmt.Println(config.DefaultReporterConfig.SlowSpecThreshold)24}25import (26func main() {27 config.DefaultReporterConfig = types.ReporterConfig{28 }29 fmt.Println(config.DefaultReporterConfig.SlowSpecThreshold)30}

Full Screen

Full Screen

filterSpecsByTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 filter := Filter{}4 filterSpecs := filter.filterSpecsByTags([]string{"tag1", "tag2"})5 fmt.Println(filterSpecs)6}7import (8func main() {9 filter := Filter{}10 filterSpecs := filter.filterSpecsByTags([]string{"tag1", "tag2"})11 fmt.Println(filterSpecs)12}13import (14func main() {15 filter := Filter{}16 filterSpecs := filter.filterSpecsByTags([]string{"tag1", "tag2"})17 fmt.Println(filterSpecs)18}19import (20func main() {21 filter := Filter{}22 filterSpecs := filter.filterSpecsByTags([]string{"tag1", "tag2"})23 fmt.Println(filterSpecs)24}25import (26func main() {27 filter := Filter{}28 filterSpecs := filter.filterSpecsByTags([]string{"tag1", "tag2"})29 fmt.Println(filterSpecs)30}31import (32func main() {33 filter := Filter{}34 filterSpecs := filter.filterSpecsByTags([]string{"tag1", "tag2"})35 fmt.Println(filterSpecs)36}37import (38func main() {39 filter := Filter{}40 filterSpecs := filter.filterSpecsByTags([]string{"tag1", "tag2"})41 fmt.Println(filterSpecs)42}43import (44func main() {45 filter := Filter{}46 filterSpecs := filter.filterSpecsByTags([]string{"tag1", "tag2"})47 fmt.Println(filterSpecs)

Full Screen

Full Screen

filterSpecsByTags

Using AI Code Generation

copy

Full Screen

1func main() {2 filter := NewFilter()3 filterSpecs := []FilterSpec{4 FilterSpec{Tags: []string{"tag1", "tag2"}},5 FilterSpec{Tags: []string{"tag1", "tag3"}},6 FilterSpec{Tags: []string{"tag3", "tag4"}},7 FilterSpec{Tags: []string{"tag2", "tag4"}},8 }9 tags := []string{"tag1", "tag2"}10 filter.FilterSpecsByTags(filterSpecs, tags)11}12func main() {13 filter := NewFilter()14 filterSpecs := []FilterSpec{15 FilterSpec{Tags: []string{"tag1", "tag2"}},16 FilterSpec{Tags: []string{"tag1", "tag3"}},17 FilterSpec{Tags: []string{"tag3", "tag4"}},18 FilterSpec{Tags: []string{"tag2", "tag4"}},19 }20 tags := []string{"tag1", "tag2"}21 filter.FilterSpecsByTags(filterSpecs, tags)22}23func main() {24 filter := NewFilter()25 filterSpecs := []FilterSpec{26 FilterSpec{Tags: []string{"tag1", "tag2"}},27 FilterSpec{Tags: []string{"tag1", "tag3"}},28 FilterSpec{Tags: []string{"tag3", "tag4"}},29 FilterSpec{Tags: []string{"tag2", "tag4"}},30 }31 tags := []string{"tag1", "tag2"}32 filter.FilterSpecsByTags(filterSpecs, tags)33}34func main() {35 filter := NewFilter()36 filterSpecs := []FilterSpec{37 FilterSpec{Tags: []string{"tag1", "tag2"}},38 FilterSpec{Tags: []string{"tag1", "tag3"}},39 FilterSpec{Tags: []string{"tag3", "tag4"}},40 FilterSpec{Tags: []string{"tag2", "tag4"}},41 }42 tags := []string{"tag1", "tag2"}

Full Screen

Full Screen

filterSpecsByTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 specs := []spec{4 spec{"spec1", []string{"tag1", "tag2", "tag3"}},5 spec{"spec2", []string{"tag1", "tag2"}},6 spec{"spec3", []string{"tag1", "tag3"}},7 spec{"spec4", []string{"tag1", "tag3", "tag4"}},8 spec{"spec5", []string{"tag2", "tag3", "tag4"}},9 }10 tags := []string{"tag1", "tag3"}11 filteredSpecs := filter.filterSpecsByTags(specs, tags)12 fmt.Println(filteredSpecs)13}14type filter struct{}15type spec struct {16}17func (filter) filterSpecsByTags(specs []spec, tags []string) []spec {18 for _, spec := range specs {19 for _, tag := range tags {20 for _, specTag := range spec.tags {21 if tag == specTag {22 }23 }24 if !found {25 }26 }27 if found {28 filteredSpecs = append(filteredSpecs, spec)29 }30 }31}32[{spec1 [tag1 tag2 tag3]} {spec3 [tag1 tag3]} {spec4 [tag1 tag3 tag4]}]

Full Screen

Full Screen

filterSpecsByTags

Using AI Code Generation

copy

Full Screen

1func main() {2 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag1", "tag2"}})3 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag1"}})4 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag1", "tag3"}})5 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag1", "tag2", "tag3"}})6 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag2", "tag3"}})7 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag1", "tag2", "tag3", "tag4"}})8 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag3"}})9 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag1", "tag2", "tag3", "tag4", "tag5"}})10 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag1", "tag2", "tag3", "tag4", "tag5", "tag6"}})11 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7"}})12 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8"}})13 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9"}})14 filterSpecs = append(filterSpecs, filter.Spec{Tags: []string{"tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tag10"}})

Full Screen

Full Screen

filterSpecsByTags

Using AI Code Generation

copy

Full Screen

1import (2type Filter struct {3}4type FilterSpec struct {5}6func filterSpecsByTags(filterSpecs []FilterSpec, tags []string) []FilterSpec {7 for _, spec := range filterSpecs {8 if len(spec.Filter.Tags) == 0 {9 filteredSpecs = append(filteredSpecs, spec)10 }11 for _, tag := range tags {12 for _, specTag := range spec.Filter.Tags {13 if tag == specTag {14 filteredSpecs = append(filteredSpecs, spec)15 }16 }17 }18 }19}20func main() {21 file, err := os.Open("filterSpecs.json")22 if err != nil {23 log.Fatal(err)24 }25 defer file.Close()26 reader := bufio.NewReader(file)27 for {28 line, err := reader.ReadString('29 if err != nil {30 if err != io.EOF {31 log.Fatal(err)32 }33 }34 line = strings.TrimSpace(line)35 if len(line) == 0 {36 }37 if err := json.Unmarshal([]byte(line), &filterSpec); err != nil {38 log.Fatal(err)39 }40 filterSpecs = append(filterSpecs, filterSpec)41 }42 file, err = os.Open("tags.txt")43 if err != nil {44 log.Fatal(err)45 }46 defer file.Close()47 reader = bufio.NewReader(file)48 for {49 line, err := reader.ReadString('50 if err != nil {51 if err != io.EOF {52 log.Fatal(err)53 }54 }55 line = strings.TrimSpace(line)56 if len(line) == 0 {

Full Screen

Full Screen

filterSpecsByTags

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 filter := gauge.NewFilter()4 specs := filter.SpecsNames()5 fmt.Println("specs are", specs)6 tags := gauge.GetTags()7 fmt.Println("tags are", tags)8 filteredSpecs := filter.FilterSpecsByTags(specs, tags)9 fmt.Println("filtered specs are", filteredSpecs)10}11import (12func main() {13 filter := gauge.NewFilter()14 specs := filter.SpecsNames()15 scenarios := filter.ScenarioNames(specs)16 fmt.Println("scenarios are", scenarios)17 tags := gauge.GetTags()18 fmt.Println("tags are", tags)19 filteredScenarios := filter.FilterScenariosByTags(scenarios, specs, tags)20 fmt.Println("filtered scenarios are", filteredScenarios)21}

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.

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