How to use doSkip method of got Package

Best Got code snippet using got.doSkip

search_test.go

Source:search_test.go Github

copy

Full Screen

...98	const (99		skipStream = 1 << iota100		skipGraphQL101	)102	doSkip := func(t *testing.T, skip int) {103		t.Helper()104		if skip&skipStream != 0 && isStreaming {105			t.Skip("does not support streaming")106		}107		if skip&skipGraphQL != 0 && !isStreaming {108			t.Skip("does not support graphql")109		}110	}111	t.Run("visibility", func(t *testing.T) {112		tests := []struct {113			query       string114			wantMissing []string115		}{116			{117				query:       "type:repo visibility:private sgtest",118				wantMissing: []string{},119			},120			{121				query:       "type:repo visibility:public sgtest",122				wantMissing: []string{"github.com/sgtest/private"},123			},124			{125				query:       "type:repo visibility:any sgtest",126				wantMissing: []string{},127			},128		}129		for _, test := range tests {130			t.Run(test.query, func(t *testing.T) {131				results, err := client.SearchRepositories(test.query)132				if err != nil {133					t.Fatal(err)134				}135				missing := results.Exists("github.com/sgtest/private")136				if diff := cmp.Diff(test.wantMissing, missing); diff != "" {137					t.Fatalf("Missing mismatch (-want +got):\n%s", diff)138				}139			})140		}141	})142	t.Run("execute search with search parameters", func(t *testing.T) {143		results, err := client.SearchFiles("repo:^github.com/sgtest/go-diff$ type:file file:.go -file:.md")144		if err != nil {145			t.Fatal(err)146		}147		// Make sure only got .go files and no .md files148		for _, r := range results.Results {149			if !strings.HasSuffix(r.File.Name, ".go") {150				t.Fatalf("Found file name does not end with .go: %s", r.File.Name)151			}152		}153	})154	t.Run("lang: filter", func(t *testing.T) {155		// On our test repositories, `function` has results for go, ts, python, html156		results, err := client.SearchFiles("function lang:go")157		if err != nil {158			t.Fatal(err)159		}160		// Make sure we only got .go files161		for _, r := range results.Results {162			if !strings.Contains(r.File.Name, ".go") {163				t.Fatalf("Found file name does not end with .go: %s", r.File.Name)164			}165		}166	})167	t.Run("excluding repositories", func(t *testing.T) {168		results, err := client.SearchFiles("fmt.Sprintf -repo:jsonrpc2")169		if err != nil {170			t.Fatal(err)171		}172		// Make sure we got some results173		if len(results.Results) == 0 {174			t.Fatal("Want non-zero results but got 0")175		}176		// Make sure we got no results from the excluded repository177		for _, r := range results.Results {178			if strings.Contains(r.Repository.Name, "jsonrpc2") {179				t.Fatal("Got results for excluded repository")180			}181		}182	})183	t.Run("multiple revisions per repository", func(t *testing.T) {184		results, err := client.SearchFiles("repo:sgtest/go-diff$@master:print-options:*refs/heads/ func NewHunksReader")185		if err != nil {186			t.Fatal(err)187		}188		wantExprs := map[string]struct{}{189			"master":        {},190			"print-options": {},191			// These next 2 branches are included because of the *refs/heads/ in the query.192			"test-already-exist-pr": {},193			"bug-fix-wip":           {},194		}195		for _, r := range results.Results {196			delete(wantExprs, r.RevSpec.Expr)197		}198		if len(wantExprs) > 0 {199			missing := make([]string, 0, len(wantExprs))200			for expr := range wantExprs {201				missing = append(missing, expr)202			}203			t.Fatalf("Missing exprs: %v", missing)204		}205	})206	t.Run("repository groups", func(t *testing.T) {207		const repoName = "github.com/sgtest/go-diff"208		err := client.OverwriteSettings(client.AuthenticatedUserID(), fmt.Sprintf(`{"search.repositoryGroups":{"gql_test_group": ["%s"]}}`, repoName))209		if err != nil {210			t.Fatal(err)211		}212		defer func() {213			err := client.OverwriteSettings(client.AuthenticatedUserID(), `{}`)214			if err != nil {215				t.Fatal(err)216			}217		}()218		results, err := client.SearchFiles("repogroup:gql_test_group diff.")219		if err != nil {220			t.Fatal(err)221		}222		// Make sure there are results and all results are from the same repository223		if len(results.Results) == 0 {224			t.Fatal("Unexpected zero result")225		}226		for _, r := range results.Results {227			if r.Repository.Name != repoName {228				t.Fatalf("Repository: want %q but got %q", repoName, r.Repository.Name)229			}230		}231	})232	t.Run("repository search", func(t *testing.T) {233		tests := []struct {234			name        string235			query       string236			zeroResult  bool237			wantMissing []string238		}{239			{240				name:       `archived excluded, zero results`,241				query:      `type:repo archived`,242				zeroResult: true,243			},244			{245				name:  `archived included, nonzero result`,246				query: `type:repo archived archived:yes`,247			},248			{249				name:  `archived included if exact without option, nonzero result`,250				query: `repo:^github\.com/sgtest/archived$`,251			},252			{253				name:       `fork excluded, zero results`,254				query:      `type:repo sgtest/mux`,255				zeroResult: true,256			},257			{258				name:  `fork included, nonzero result`,259				query: `type:repo sgtest/mux fork:yes`,260			},261			{262				name:  `fork included if exact without option, nonzero result`,263				query: `repo:^github\.com/sgtest/mux$`,264			},265			{266				name:  "repohasfile returns results for global search",267				query: "repohasfile:README",268			},269			{270				name:       "multiple repohasfile returns no results if one doesn't match",271				query:      "repohasfile:README repohasfile:thisfiledoesnotexist_1571751",272				zeroResult: true,273			},274			{275				name:  "repo search by name, nonzero result",276				query: "repo:go-diff$",277			},278			{279				name:  "true is an alias for yes when fork is set",280				query: `repo:github\.com/sgtest/mux fork:true`,281			},282			{283				name:  `exclude counts for fork and archive`,284				query: `repo:mux|archived|go-diff`,285				wantMissing: []string{286					"github.com/sgtest/archived",287					"github.com/sgtest/mux",288				},289			},290			{291				name:  `Structural search returns repo results if patterntype set but pattern is empty`,292				query: `repo:^github\.com/sgtest/sourcegraph-typescript$ patterntype:structural`,293			},294		}295		for _, test := range tests {296			t.Run(test.name, func(t *testing.T) {297				results, err := client.SearchRepositories(test.query)298				if err != nil {299					t.Fatal(err)300				}301				if test.zeroResult {302					if len(results) > 0 {303						t.Fatalf("Want zero result but got %d", len(results))304					}305				} else {306					if len(results) == 0 {307						t.Fatal("Want non-zero results but got 0")308					}309				}310				if test.wantMissing != nil {311					missing := results.Exists(test.wantMissing...)312					sort.Strings(missing)313					if diff := cmp.Diff(test.wantMissing, missing); diff != "" {314						t.Fatalf("Missing mismatch (-want +got):\n%s", diff)315					}316				}317			})318		}319	})320	t.Run("global text search", func(t *testing.T) {321		tests := []struct {322			name          string323			query         string324			zeroResult    bool325			minMatchCount int64326			wantAlert     *gqltestutil.SearchAlert327			skip          int328		}{329			// Global search330			{331				name:  "error",332				query: "error",333			},334			{335				name:  "error count:1000",336				query: "error count:1000",337			},338			{339				name:          "something with more than 1000 results and use count:1000",340				query:         ". count:1000",341				minMatchCount: 1000,342			},343			{344				name:          "default limit streaming",345				query:         ".",346				minMatchCount: 500,347				skip:          skipGraphQL,348			},349			{350				name:          "default limit graphql",351				query:         ".",352				minMatchCount: 30,353				skip:          skipStream,354			},355			{356				name:  "regular expression without indexed search",357				query: "index:no patterntype:regexp ^func.*$",358			},359			{360				name:  "fork:only",361				query: "fork:only router",362			},363			{364				name:  "double-quoted pattern, nonzero result",365				query: `"func main() {\n" patterntype:regexp type:file`,366			},367			{368				name:  "exclude repo, nonzero result",369				query: `"func main() {\n" -repo:go-diff patterntype:regexp type:file`,370			},371			{372				name:       "fork:no",373				query:      "fork:no FORK" + "_SENTINEL",374				zeroResult: true,375			},376			{377				name:  "fork:yes",378				query: "fork:yes FORK" + "_SENTINEL",379			},380			{381				name:       "random characters, zero results",382				query:      "asdfalksd+jflaksjdfklas patterntype:literal -repo:sourcegraph",383				zeroResult: true,384			},385			// Repo search386			{387				name:  "repo search by name, case yes, nonzero result",388				query: `repo:^github\.com/sgtest/go-diff$ String case:yes type:file`,389			},390			{391				name:  "non-master branch, nonzero result",392				query: `repo:^github\.com/sgtest/java-langserver$@v1 void sendPartialResult(Object requestId, JsonPatch jsonPatch); patterntype:literal type:file`,393			},394			{395				name:  "indexed multiline search, nonzero result",396				query: `repo:^github\.com/sgtest/java-langserver$ \nimport index:only patterntype:regexp type:file`,397			},398			{399				name:  "unindexed multiline search, nonzero result",400				query: `repo:^github\.com/sgtest/java-langserver$ \nimport index:no patterntype:regexp type:file`,401			},402			{403				name:       "random characters, zero result",404				query:      `repo:^github\.com/sgtest/java-langserver$ doesnot734734743734743exist`,405				zeroResult: true,406			},407			// Filename search408			{409				name:  "search for a known file",410				query: "file:doc.go",411			},412			{413				name:       "search for a non-existent file",414				query:      "file:asdfasdf.go",415				zeroResult: true,416			},417			// Symbol search418			{419				name:  "search for a known symbol",420				query: "type:symbol count:100 patterntype:regexp ^newroute",421			},422			{423				name:       "search for a non-existent symbol",424				query:      "type:symbol asdfasdf",425				zeroResult: true,426			},427			// Commit search428			{429				name:  "commit search, nonzero result",430				query: `repo:^github\.com/sgtest/go-diff$ type:commit`,431			},432			{433				name:       "commit search, non-existent ref",434				query:      `repo:^github\.com/sgtest/go-diff$@ref/noexist type:commit`,435				zeroResult: true,436				wantAlert: &gqltestutil.SearchAlert{437					Title:           "Some repositories could not be searched",438					Description:     `The repository github.com/sgtest/go-diff matched by your repo: filter could not be searched because it does not contain the revision "ref/noexist".`,439					ProposedQueries: nil,440				},441			},442			{443				name:  "commit search, non-zero result message",444				query: `repo:^github\.com/sgtest/sourcegraph-typescript$ type:commit message:test`,445			},446			{447				name:  "commit search, non-zero result pattern",448				query: `repo:^github\.com/sgtest/sourcegraph-typescript$ type:commit test`,449			},450			// Diff search451			{452				name:  "diff search, nonzero result",453				query: `repo:^github\.com/sgtest/go-diff$ type:diff main`,454			},455			// Repohascommitafter456			{457				name:  `Repohascommitafter, nonzero result`,458				query: `repo:^github\.com/sgtest/go-diff$ repohascommitafter:"2019-01-01" test patterntype:literal`,459			},460			// Regex text search461			{462				name:  `regex, unindexed, nonzero result`,463				query: `^func.*$ patterntype:regexp index:only type:file`,464			},465			{466				name:  `regex, fork only, nonzero result`,467				query: `fork:only patterntype:regexp FORK_SENTINEL`,468			},469			{470				name:  `regex, filter by language`,471				query: `\bfunc\b lang:go type:file patterntype:regexp`,472			},473			{474				name:       `regex, filename, zero results`,475				query:      `file:asdfasdf.go patterntype:regexp`,476				zeroResult: true,477			},478			{479				name:  `regexp, filename, nonzero result`,480				query: `file:doc.go patterntype:regexp`,481			},482		}483		for _, test := range tests {484			t.Run(test.name, func(t *testing.T) {485				doSkip(t, test.skip)486				results, err := client.SearchFiles(test.query)487				if err != nil {488					t.Fatal(err)489				}490				if diff := cmp.Diff(test.wantAlert, results.Alert); diff != "" {491					t.Fatalf("Alert mismatch (-want +got):\n%s", diff)492				}493				if test.zeroResult {494					if len(results.Results) > 0 {495						t.Fatalf("Want zero result but got %d", len(results.Results))496					}497				} else {498					if len(results.Results) == 0 {499						t.Fatal("Want non-zero results but got 0")500					}501				}502				if results.MatchCount < test.minMatchCount {503					t.Fatalf("Want at least %d match count but got %d", test.minMatchCount, results.MatchCount)504				}505			})506		}507	})508	t.Run("timeout search options", func(t *testing.T) {509		results, err := client.SearchFiles(`router index:no timeout:1ns`)510		if err != nil {511			t.Fatal(err)512		}513		if results.Alert == nil {514			t.Fatal("Want search alert but got nil")515		}516	})517	t.Run("structural search", func(t *testing.T) {518		tests := []struct {519			name       string520			query      string521			zeroResult bool522			wantAlert  *gqltestutil.SearchAlert523		}{524			{525				name:  "Structural, index only, nonzero result",526				query: `repo:^github\.com/sgtest/go-diff$ make(:[1]) index:only patterntype:structural count:3`,527			},528			{529				name:  "Structural, index only, backcompat, nonzero result",530				query: `repo:^github\.com/sgtest/go-diff$ make(:[1]) lang:go rule:'where "backcompat" == "backcompat"' patterntype:structural`,531			},532			{533				name:  "Structural, unindexed, nonzero result",534				query: `repo:^github\.com/sgtest/go-diff$@adde71 make(:[1]) index:no patterntype:structural count:3`,535			},536			{537				name:  `Structural search quotes are interpreted literally`,538				query: `repo:^github\.com/sgtest/sourcegraph-typescript$ file:^README\.md "basic :[_] access :[_]" patterntype:structural`,539			},540			{541				name:       `Alert to activate structural search mode for :[...] syntax`,542				query:      `repo:^github\.com/sgtest/go-diff$ patterntype:literal i can't :[believe] it's not butter`,543				zeroResult: true,544				wantAlert: &gqltestutil.SearchAlert{545					Title:       "No results",546					Description: "It looks like you may have meant to run a structural search, but it is not toggled.",547					ProposedQueries: []gqltestutil.ProposedQuery{548						{549							Description: "Activate structural search",550							Query:       `repo:^github\.com/sgtest/go-diff$ patterntype:literal i can't :[believe] it's not butter patternType:structural`,551						},552					},553				},554			},555			{556				name:       `Alert to activate structural search mode for ... syntax`,557				query:      `no results for { ... } raises alert repo:^github\.com/sgtest/go-diff$`,558				zeroResult: true,559				wantAlert: &gqltestutil.SearchAlert{560					Title:       "No results",561					Description: "It looks like you may have meant to run a structural search, but it is not toggled.",562					ProposedQueries: []gqltestutil.ProposedQuery{563						{564							Description: "Activate structural search",565							Query:       `no results for { ... } raises alert repo:^github\.com/sgtest/go-diff$ patternType:structural`,566						},567					},568				},569			},570		}571		for _, test := range tests {572			t.Run(test.name, func(t *testing.T) {573				results, err := client.SearchFiles(test.query)574				if err != nil {575					t.Fatal(err)576				}577				if diff := cmp.Diff(test.wantAlert, results.Alert); diff != "" {578					t.Fatalf("Alert mismatch (-want +got):\n%s", diff)579				}580				if test.zeroResult {581					if len(results.Results) > 0 {582						t.Fatalf("Want zero result but got %d", len(results.Results))583					}584				} else {585					if len(results.Results) == 0 {586						t.Fatal("Want non-zero results but got 0")587					}588				}589			})590		}591	})592	t.Run("And/Or queries", func(t *testing.T) {593		tests := []struct {594			name       string595			query      string596			zeroResult bool597			wantAlert  *gqltestutil.SearchAlert598		}{599			{600				name:  `And operator, basic`,601				query: `repo:^github\.com/sgtest/go-diff$ func and main type:file`,602			},603			{604				name:  `Or operator, single and double quoted`,605				query: `repo:^github\.com/sgtest/go-diff$ "func PrintMultiFileDiff" or 'func readLine(' type:file patterntype:regexp`,606			},607			{608				name:  `Literals, grouped parens with parens-as-patterns heuristic`,609				query: `repo:^github\.com/sgtest/go-diff$ (() or ()) type:file patterntype:regexp`,610			},611			{612				name:  `Literals, no grouped parens`,613				query: `repo:^github\.com/sgtest/go-diff$ () or () type:file patterntype:regexp`,614			},615			{616				name:  `Literals, escaped parens`,617				query: `repo:^github\.com/sgtest/go-diff$ \(\) or \(\) type:file patterntype:regexp`,618			},619			{620				name:  `Literals, escaped and unescaped parens, no group`,621				query: `repo:^github\.com/sgtest/go-diff$ () or \(\) type:file patterntype:regexp`,622			},623			{624				name:  `Literals, escaped and unescaped parens, grouped`,625				query: `repo:^github\.com/sgtest/go-diff$ (() or \(\)) type:file patterntype:regexp`,626			},627			{628				name:       `Literals, double paren`,629				query:      `repo:^github\.com/sgtest/go-diff$ ()() or ()()`,630				zeroResult: true,631			},632			{633				name:       `Literals, double paren, dangling paren right side`,634				query:      `repo:^github\.com/sgtest/go-diff$ ()() or main()(`,635				zeroResult: true,636			},637			{638				name:       `Literals, double paren, dangling paren left side`,639				query:      `repo:^github\.com/sgtest/go-diff$ ()( or ()()`,640				zeroResult: true,641			},642			{643				name:  `Mixed regexp and literal`,644				query: `repo:^github\.com/sgtest/go-diff$ patternType:regexp func(.*) or does_not_exist_3744 type:file`,645			},646			{647				name:  `Mixed regexp and literal heuristic`,648				query: `repo:^github\.com/sgtest/go-diff$ func( or func(.*) type:file`,649			},650			{651				name:       `Mixed regexp and quoted literal`,652				query:      `repo:^github\.com/sgtest/go-diff$ "*" and cert.*Load type:file`,653				zeroResult: true,654			},655			{656				name:  `Escape sequences`,657				query: `repo:^github\.com/sgtest/go-diff$ patternType:regexp \' and \" and \\ and /`,658			},659			{660				name:  `Escaped whitespace sequences with 'and'`,661				query: `repo:^github\.com/sgtest/go-diff$ patternType:regexp \ and /`,662			},663			{664				name:  `Concat converted to spaces for literal search`,665				query: `repo:^github\.com/sgtest/go-diff$ file:^diff/print\.go t := or ts Time patterntype:literal`,666			},667			{668				name:  `Literal parentheses match pattern`,669				query: `repo:^github\.com/sgtest/go-diff file:^diff/print\.go Bytes() and Time() patterntype:literal`,670			},671			{672				name:  `Literals, simple not keyword inside group`,673				query: `repo:^github\.com/sgtest/go-diff$ (not .svg) patterntype:literal`,674			},675			{676				name:  `Literals, not keyword and implicit and inside group`,677				query: `repo:^github\.com/sgtest/go-diff$ (a/foo not .svg) patterntype:literal`,678			},679			{680				name:  `Literals, not and and keyword inside group`,681				query: `repo:^github\.com/sgtest/go-diff$ (a/foo and not .svg) patterntype:literal`,682			},683			{684				name:  `Dangling right parens, supported via content: filter`,685				query: `repo:^github\.com/sgtest/go-diff$ content:"diffPath)" and main patterntype:literal`,686			},687			{688				name:       `Dangling right parens, unsupported in literal search`,689				query:      `repo:^github\.com/sgtest/go-diff$ diffPath) and main patterntype:literal`,690				zeroResult: true,691				wantAlert: &gqltestutil.SearchAlert{692					Title:       "Unable To Process Query",693					Description: "Unsupported expression. The combination of parentheses in the query have an unclear meaning. Try using the content: filter to quote patterns that contain parentheses",694				},695			},696			{697				name:       `Dangling right parens, unsupported in literal search, double parens`,698				query:      `repo:^github\.com/sgtest/go-diff$ MarshalTo and OrigName)) patterntype:literal`,699				zeroResult: true,700				wantAlert: &gqltestutil.SearchAlert{701					Title:       "Unable To Process Query",702					Description: "Unsupported expression. The combination of parentheses in the query have an unclear meaning. Try using the content: filter to quote patterns that contain parentheses",703				},704			},705			{706				name:       `Dangling right parens, unsupported in literal search, simple group before right paren`,707				query:      `repo:^github\.com/sgtest/go-diff$ MarshalTo and (m.OrigName)) patterntype:literal`,708				zeroResult: true,709				wantAlert: &gqltestutil.SearchAlert{710					Title:       "Unable To Process Query",711					Description: "Unsupported expression. The combination of parentheses in the query have an unclear meaning. Try using the content: filter to quote patterns that contain parentheses",712				},713			},714			{715				name:       `Dangling right parens, heuristic for literal search, cannot succeed, too confusing`,716				query:      `repo:^github\.com/sgtest/go-diff$ (respObj.Size and (data))) patterntype:literal`,717				zeroResult: true,718				wantAlert: &gqltestutil.SearchAlert{719					Title:       "Unable To Process Query",720					Description: "Unsupported expression. The combination of parentheses in the query have an unclear meaning. Try using the content: filter to quote patterns that contain parentheses",721				},722			},723			{724				name:       `No result for confusing grouping`,725				query:      `repo:^github\.com/sgtest/go-diff file:^README\.md (bar and (foo or x\) ()) patterntype:literal`,726				zeroResult: true,727			},728			{729				name:       `Successful grouping removes alert`,730				query:      `repo:^github\.com/sgtest/go-diff file:^README\.md (bar and (foo or (x\) ())) patterntype:literal`,731				zeroResult: true,732			},733			{734				name:  `No dangling right paren with complex group for literal search`,735				query: `repo:^github\.com/sgtest/go-diff$ (m *FileDiff and (data)) patterntype:literal`,736			},737			{738				name:  `Concat converted to .* for regexp search`,739				query: `repo:^github\.com/sgtest/go-diff$ file:^diff/print\.go t := or ts Time patterntype:regexp type:file`,740			},741			{742				name:  `Structural search uses literal search parser`,743				query: `repo:^github\.com/sgtest/go-diff$ file:^diff/print\.go :[[v]] := ts and printFileHeader(:[_]) patterntype:structural`,744			},745			{746				name:  `Union file matches per file and accurate counts`,747				query: `repo:^github\.com/sgtest/go-diff file:^diff/print\.go func or package`,748			},749			{750				name:  `Intersect file matches per file and accurate counts`,751				query: `repo:^github\.com/sgtest/go-diff file:^diff/print\.go func and package`,752			},753			{754				name:  `Simple combined union and intersect file matches per file and accurate counts`,755				query: `repo:^github\.com/sgtest/go-diff file:^diff/print\.go ((func timePtr and package diff) or return buf.Bytes())`,756			},757			{758				name:  `Complex union of intersect file matches per file and accurate counts`,759				query: `repo:^github\.com/sgtest/go-diff file:^diff/print\.go ((func timePtr and package diff) or (ts == nil and ts.Time()))`,760			},761			{762				name:  `Complex intersect of union file matches per file and accurate counts`,763				query: `repo:^github\.com/sgtest/go-diff file:^diff/print\.go ((func timePtr or package diff) and (ts == nil or ts.Time()))`,764			},765			{766				name:       `Intersect file matches per file against an empty result set`,767				query:      `repo:^github\.com/sgtest/go-diff file:^diff/print\.go func and doesnotexist838338`,768				zeroResult: true,769			},770			{771				name:  `Dedupe union operation`,772				query: `file:diff.go|print.go|parse.go repo:^github\.com/sgtest/go-diff _, :[[x]] := range :[src.] { :[_] } or if :[s1] == :[s2] patterntype:structural`,773			},774		}775		for _, test := range tests {776			t.Run(test.name, func(t *testing.T) {777				results, err := client.SearchFiles(test.query)778				if err != nil {779					t.Fatal(err)780				}781				if diff := cmp.Diff(test.wantAlert, results.Alert); diff != "" {782					t.Fatalf("Alert mismatch (-want +got):\n%s", diff)783				}784				if test.zeroResult {785					if len(results.Results) > 0 {786						t.Fatalf("Want zero result but got %d", len(results.Results))787					}788				} else {789					if len(results.Results) == 0 {790						t.Fatal("Want non-zero results but got 0")791					}792				}793			})794		}795	})796	t.Run("And/Or search expression queries", func(t *testing.T) {797		tests := []struct {798			name            string799			query           string800			zeroResult      bool801			exactMatchCount int64802			wantAlert       *gqltestutil.SearchAlert803			skip            int804		}{805			{806				name:  `Or distributive property on content and file`,807				query: `repo:^github\.com/sgtest/sourcegraph-typescript$ (Fetches OR file:language-server.ts)`,808			},809			{810				name:  `Or distributive property on nested file on content`,811				query: `repo:^github\.com/sgtest/sourcegraph-typescript$ ((file:^renovate\.json extends) or file:progress.ts createProgressProvider)`,812			},813			{814				name:  `Or distributive property on commit`,815				query: `repo:^github\.com/sgtest/sourcegraph-typescript$ (type:diff or type:commit) author:felix yarn`,816			},817			{818				name:            `Or match on both diff and commit returns both`,819				query:           `repo:^github\.com/sgtest/sourcegraph-typescript$ (type:diff or type:commit) subscription after:"june 11 2019" before:"june 13 2019"`,820				exactMatchCount: 2,821			},822			{823				name:            `Or distributive property on rev`,824				query:           `repo:^github\.com/sgtest/mux$ (rev:v1.7.3 or revision:v1.7.2)`,825				exactMatchCount: 2,826			},827			{828				name:            `Or distributive property on rev with file`,829				query:           `repo:^github\.com/sgtest/mux$ (rev:v1.7.3 or revision:v1.7.2) file:README.md`,830				exactMatchCount: 2,831			},832			{833				name:  `Or distributive property on repo`,834				query: `(repo:^github\.com/sgtest/go-diff$@garo/lsif-indexing-campaign:test-already-exist-pr or repo:^github\.com/sgtest/sourcegraph-typescript$) file:README.md #`,835			},836			{837				name:  `Or distributive property on repo where only one repo contains match (tests repo cache is invalidated)`,838				query: `(repo:^github\.com/sgtest/sourcegraph-typescript$ or repo:^github\.com/sgtest/go-diff$) package diff provides`,839			},840			{841				name:            `Or distributive property on commits deduplicates and merges`,842				query:           `repo:^github\.com/sgtest/go-diff$ type:commit (message:add or message:file)`,843				exactMatchCount: 21,844				skip:            skipStream,845			},846		}847		for _, test := range tests {848			t.Run(test.name, func(t *testing.T) {849				doSkip(t, test.skip)850				results, err := client.SearchFiles(test.query)851				if err != nil {852					t.Fatal(err)853				}854				if diff := cmp.Diff(test.wantAlert, results.Alert); diff != "" {855					t.Fatalf("Alert mismatch (-want +got):\n%s", diff)856				}857				if test.zeroResult {858					if len(results.Results) > 0 {859						t.Fatalf("Want zero result but got %d", len(results.Results))860					}861				} else {862					if len(results.Results) == 0 {863						t.Fatal("Want non-zero results but got 0")...

Full Screen

Full Screen

each.go

Source:each.go Github

copy

Full Screen

...31		runVal.Call([]reflect.Value{32			reflect.ValueOf(method.Name),33			reflect.MakeFunc(cbType, func(args []reflect.Value) []reflect.Value {34				t := args[0].Interface().(Testable)35				doSkip(t, method)36				count++37				res := itVal.Call(args)38				return callMethod(t, method, res[0])39			}),40		})41	}42	return43}44func normalizeIteratee(t Testable, iteratee interface{}) reflect.Value {45	t.Helper()46	if iteratee == nil {47		t.Logf("iteratee shouldn't be nil")48		t.FailNow()49	}50	itVal := reflect.ValueOf(iteratee)51	itType := itVal.Type()52	fail := true53	switch itType.Kind() {54	case reflect.Func:55		if itType.NumIn() != 1 || itType.NumOut() != 1 {56			break57		}58		try(func() {59			_ = reflect.New(itType.In(0).Elem()).Interface().(Testable)60			fail = false61		})62	case reflect.Struct:63		fnType := reflect.FuncOf([]reflect.Type{reflect.TypeOf(t)}, []reflect.Type{itType}, false)64		structVal := itVal65		itVal = reflect.MakeFunc(fnType, func(args []reflect.Value) []reflect.Value {66			sub := args[0].Interface().(Testable)67			as := reflect.ValueOf(New(sub))68			c := reflect.New(itType).Elem()69			c.Set(structVal)70			try(func() { c.FieldByName("G").Set(as) })71			return []reflect.Value{c}72		})73		fail = false74	}75	if fail {76		t.Logf("iteratee <%v> should be a struct or <func(got.Testable) Ctx>", itType)77		t.FailNow()78	}79	return itVal80}81func callMethod(t Testable, method reflect.Method, receiver reflect.Value) []reflect.Value {82	args := make([]reflect.Value, method.Type.NumIn())83	args[0] = receiver84	for i := 1; i < len(args); i++ {85		args[i] = reflect.New(method.Type.In(i)).Elem()86	}87	defer func() {88		if err := recover(); err != nil {89			t.Logf("[panic] %v\n%s", err, debug.Stack())90			t.Fail()91		}92	}()93	method.Func.Call(args)94	return []reflect.Value{}95}96func filterMethods(typ reflect.Type) []reflect.Method {97	embedded := map[string]struct{}{}98	for i := 0; i < typ.NumField(); i++ {99		field := typ.Field(i)100		if field.Anonymous {101			for j := 0; j < field.Type.NumMethod(); j++ {102				embedded[field.Type.Method(j).Name] = struct{}{}103			}104		}105	}106	methods := []reflect.Method{}107	onlyList := []reflect.Method{}108	for i := 0; i < typ.NumMethod(); i++ {109		method := typ.Method(i)110		if _, has := embedded[method.Name]; has {111			continue112		}113		if method.Type.NumIn() > 1 && method.Type.In(1) == reflect.TypeOf(Only{}) {114			onlyList = append(onlyList, method)115		}116		methods = append(methods, method)117	}118	if len(onlyList) > 0 {119		return onlyList120	}121	return methods122}123func doSkip(t Testable, method reflect.Method) {124	if method.Type.NumIn() > 1 && method.Type.In(1) == reflect.TypeOf(Skip{}) {125		t.SkipNow()126	}127}128func try(fn func()) {129	defer func() {130		_ = recover()131	}()132	fn()133}...

Full Screen

Full Screen

day_18_test.go

Source:day_18_test.go Github

copy

Full Screen

...64			exp:  3488,65			skip: true,66		},67	}68	doSkip := false69	for i, test := range tests {70		if doSkip && test.skip {71			t.Logf("skip %d", i+1)72			continue73		}74		t.Run(fmt.Sprintf("test #%02d", i), func(t *testing.T) {75			p, err := sfish.Parse(test.in)76			testutil.CheckUnexpectedError(t, err)77			res := p.Magnitude()78			if res != test.exp {79				t.Fatalf("want %d, have %d", test.exp, res)80			}81		})82	}83}84func TestMagnitudeOfFinalSum(t *testing.T) {...

Full Screen

Full Screen

doSkip

Using AI Code Generation

copy

Full Screen

1got.doSkip();2got.doSkip();3got.doSkip();4got.doSkip();5got.doSkip();6got.doSkip();7got.doSkip();8got.doSkip();9got.doSkip();10got.doSkip();11got.doSkip();12got.doSkip();13got.doSkip();14got.doSkip();15got.doSkip();16got.doSkip();17got.doSkip();18got.doSkip();19got.doSkip();20got.doSkip();21got.doSkip();22got.doSkip();23got.doSkip();

Full Screen

Full Screen

doSkip

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	fmt.Println(got.DoSkip())4}5import (6func main() {7	fmt.Println(got.DoSkip())8}9import (10func main() {11	fmt.Println(got.DoSkip())12}13import (14func main() {15	fmt.Println(got.DoSkip())16}17import (18func main() {19	fmt.Println(got.DoSkip())20}21import (22func main() {23	fmt.Println(got.DoSkip())24}25import (26func main() {27	fmt.Println(got.DoSkip())28}29import (30func main() {31	fmt.Println(got.DoSkip())32}33import (34func main() {35	fmt.Println(got.DoSkip())36}37import (38func main() {39	fmt.Println(got.DoSkip())40}41import (42func main() {43	fmt.Println(got.DoSkip())44}45import (46func main() {47	fmt.Println(got.DoSkip())48}

Full Screen

Full Screen

doSkip

Using AI Code Generation

copy

Full Screen

1import "fmt"2type got struct {3}4func (g *got) doSkip() {5}6func main() {7    g := got{}8    g.doSkip()9    fmt.Println(g.x)10}11import "fmt"12type got struct {13}14func (g got) doSkip() {15}16func main() {17    g := got{}18    g.doSkip()19    fmt.Println(g.x)20}

Full Screen

Full Screen

doSkip

Using AI Code Generation

copy

Full Screen

1import "got"2import "fmt"3func main() {4    g := got.Got{}5    g.DoSkip()6    fmt.Println("done")7}8import "fmt"9type Got struct {10}11func (g *Got) DoSkip() {12    fmt.Println("skipping")13}14import (15type Card struct {16}17type Player struct {18}19func main() {20    rand.Seed(time.Now().UTC().UnixNano())21    deck = createDeck()22    deck = shuffle(deck)23    player.Hand = append(player.Hand, deck[0])24    dealer.Hand = append(dealer.Hand, deck[0])25    player.Hand = append(player.Hand, deck[0])26    dealer.Hand = append(dealer.Hand, deck[0])27    player.Score = getScore(player.Hand)28    dealer.Score = getScore(dealer.Hand)29    fmt.Println(player)30    fmt.Println(dealer)31}32func createDeck() []Card {33    suits := []string{"Hearts", "Diamonds", "Clubs", "Spades"}34    names := []string{"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}35    values := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10,

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful