当前位置: 首页>>代码示例>>Golang>>正文


Golang strings.Repeat函数代码示例

本文整理汇总了Golang中strings.Repeat函数的典型用法代码示例。如果您正苦于以下问题:Golang Repeat函数的具体用法?Golang Repeat怎么用?Golang Repeat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Repeat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Usage

func Usage(cmd string) {
	fmt.Println(strings.Repeat("-", 100))
	fmt.Println("Ssh version Check by haifeng11")
	fmt.Println("Usage:")
	fmt.Printf("%s iplist_file\n", cmd)
	fmt.Println(strings.Repeat("-", 100))
}
开发者ID:xiaoxiaoleo,项目名称:crack_ssh,代码行数:7,代码来源:checkssh.go

示例2: TestKVPutError

func TestKVPutError(t *testing.T) {
	defer testutil.AfterTest(t)

	var (
		maxReqBytes = 1.5 * 1024 * 1024
		quota       = int64(maxReqBytes * 1.2)
	)
	clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1, QuotaBackendBytes: quota})
	defer clus.Terminate(t)

	kv := clientv3.NewKV(clus.RandClient())
	ctx := context.TODO()

	_, err := kv.Put(ctx, "", "bar")
	if err != rpctypes.ErrEmptyKey {
		t.Fatalf("expected %v, got %v", rpctypes.ErrEmptyKey, err)
	}

	_, err = kv.Put(ctx, "key", strings.Repeat("a", int(maxReqBytes+100))) // 1.5MB
	if err != rpctypes.ErrRequestTooLarge {
		t.Fatalf("expected %v, got %v", rpctypes.ErrRequestTooLarge, err)
	}

	_, err = kv.Put(ctx, "foo1", strings.Repeat("a", int(maxReqBytes-50)))
	if err != nil { // below quota
		t.Fatal(err)
	}

	time.Sleep(500 * time.Millisecond) // give enough time for commit

	_, err = kv.Put(ctx, "foo2", strings.Repeat("a", int(maxReqBytes-50)))
	if err != rpctypes.ErrNoSpace { // over quota
		t.Fatalf("expected %v, got %v", rpctypes.ErrNoSpace, err)
	}
}
开发者ID:ringtail,项目名称:etcd,代码行数:35,代码来源:kv_test.go

示例3: formatTwoColumns

func formatTwoColumns(w io.Writer, indent, padding, width int, rows [][2]string) {
	// Find size of first column.
	s := 0
	for _, row := range rows {
		if c := len(row[0]); c > s && c < 30 {
			s = c
		}
	}

	indentStr := strings.Repeat(" ", indent)
	offsetStr := strings.Repeat(" ", s+padding)

	for _, row := range rows {
		buf := bytes.NewBuffer(nil)
		doc.ToText(buf, row[1], "", preIndent, width-s-padding-indent)
		lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")
		fmt.Fprintf(w, "%s%-*s%*s", indentStr, s, row[0], padding, "")
		if len(row[0]) >= 30 {
			fmt.Fprintf(w, "\n%s%s", indentStr, offsetStr)
		}
		fmt.Fprintf(w, "%s\n", lines[0])
		for _, line := range lines[1:] {
			fmt.Fprintf(w, "%s%s%s\n", indentStr, offsetStr, line)
		}
	}
}
开发者ID:CameloeAnthony,项目名称:ghostunnel,代码行数:26,代码来源:usage.go

示例4: TestValidFieldNames

func TestValidFieldNames(t *testing.T) {
	testCases := []struct {
		name  string
		valid bool
	}{
		{"Normal", true},
		{"Also_OK_123", true},
		{"Not so great", false},
		{"lower_case", false},
		{"Exclaim!", false},
		{"Hello세상아 안녕", false},
		{"", false},
		{"Hεllo", false},
		{strings.Repeat("A", 500), true},
		{strings.Repeat("A", 501), false},
	}

	for _, tc := range testCases {
		_, _, err := saveDoc(&FieldList{
			Field{Name: tc.name, Value: "val"},
		})
		if err != nil && !strings.Contains(err.Error(), "invalid field name") {
			t.Errorf("unexpected err %q for field name %q", err, tc.name)
		}
		if (err == nil) != tc.valid {
			t.Errorf("field %q: expected valid %t, received err %v", tc.name, tc.valid, err)
		}
	}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:29,代码来源:search_test.go

示例5: TestIsDelegation

func TestIsDelegation(t *testing.T) {
	f := require.False
	tr := require.True
	for val, check := range map[string]func(require.TestingT, bool, ...interface{}){
		// false checks
		path.Join(CanonicalTargetsRole, strings.Repeat("x", 255-len(CanonicalTargetsRole))): f,
		"":                                                                                  f,
		CanonicalRootRole:                                                                   f,
		path.Join(CanonicalRootRole, "level1"):                                              f,
		CanonicalTargetsRole:                                                                f,
		CanonicalTargetsRole + "/":                                                          f,
		path.Join(CanonicalTargetsRole, "level1") + "/":                                     f,
		path.Join(CanonicalTargetsRole, "UpperCase"):                                        f,
		path.Join(CanonicalTargetsRole, "directory") + "/../../traversal":                   f,
		CanonicalTargetsRole + "///test/middle/slashes":                                     f,
		CanonicalTargetsRole + "/./././":                                                    f,
		path.Join("  ", CanonicalTargetsRole, "level1"):                                     f,
		path.Join("  "+CanonicalTargetsRole, "level1"):                                      f,
		path.Join(CanonicalTargetsRole, "level1"+"  "):                                      f,
		path.Join(CanonicalTargetsRole, "white   space"+"level2"):                           f,
		path.Join(CanonicalTargetsRole, strings.Repeat("x", 256-len(CanonicalTargetsRole))): f,

		// true checks
		path.Join(CanonicalTargetsRole, "level1"):                     tr,
		path.Join(CanonicalTargetsRole, "level1", "level2", "level3"): tr,
		path.Join(CanonicalTargetsRole, "under_score"):                tr,
		path.Join(CanonicalTargetsRole, "hyphen-hyphen"):              tr,
	} {
		check(t, IsDelegation(val))
	}

}
开发者ID:jfrazelle,项目名称:notary,代码行数:32,代码来源:roles_test.go

示例6: TestValidateLogGroupName

func TestValidateLogGroupName(t *testing.T) {
	validNames := []string{
		"ValidLogGroupName",
		"ValidLogGroup.Name",
		"valid/Log-group",
		"1234",
		"YadaValid#0123",
		"Also_valid-name",
		strings.Repeat("W", 512),
	}
	for _, v := range validNames {
		_, errors := validateLogGroupName(v, "name")
		if len(errors) != 0 {
			t.Fatalf("%q should be a valid Log Metric Filter Transformation Name: %q", v, errors)
		}
	}

	invalidNames := []string{
		"Here is a name with: colon",
		"and here is another * invalid name",
		"also $ invalid",
		"This . is also %% [email protected]!)+(",
		"*",
		"",
		// length > 512
		strings.Repeat("W", 513),
	}
	for _, v := range invalidNames {
		_, errors := validateLogGroupName(v, "name")
		if len(errors) == 0 {
			t.Fatalf("%q should be an invalid Log Metric Filter Transformation Name", v)
		}
	}
}
开发者ID:TheWeatherCompany,项目名称:terraform,代码行数:34,代码来源:validators_test.go

示例7: TestValidateS3BucketLifecycleRuleId

func TestValidateS3BucketLifecycleRuleId(t *testing.T) {
	validId := []string{
		"YadaHereAndThere",
		"Valid-5Rule_ID",
		"This . is also %% [email protected]!)+*(:ID",
		"1234",
		strings.Repeat("W", 255),
	}
	for _, v := range validId {
		_, errors := validateS3BucketLifecycleRuleId(v, "id")
		if len(errors) != 0 {
			t.Fatalf("%q should be a valid lifecycle rule id: %q", v, errors)
		}
	}

	invalidId := []string{
		// length > 255
		strings.Repeat("W", 256),
	}
	for _, v := range invalidId {
		_, errors := validateS3BucketLifecycleRuleId(v, "id")
		if len(errors) == 0 {
			t.Fatalf("%q should be an invalid lifecycle rule id", v)
		}
	}
}
开发者ID:TheWeatherCompany,项目名称:terraform,代码行数:26,代码来源:validators_test.go

示例8: TestIsValidLabelValue

func TestIsValidLabelValue(t *testing.T) {
	successCases := []string{
		"simple",
		"now-with-dashes",
		"1-starts-with-num",
		"end-with-num-1",
		"1234",                  // only num
		strings.Repeat("a", 63), // to the limit
		"", // empty value
	}
	for i := range successCases {
		if !IsValidLabelValue(successCases[i]) {
			t.Errorf("case %s expected success", successCases[i])
		}
	}

	errorCases := []string{
		"nospecialchars%^[email protected]",
		"Tama-nui-te-rā.is.Māori.sun",
		"\\backslashes\\are\\bad",
		"-starts-with-dash",
		"ends-with-dash-",
		".starts.with.dot",
		"ends.with.dot.",
		strings.Repeat("a", 64), // over the limit
	}
	for i := range errorCases {
		if IsValidLabelValue(errorCases[i]) {
			t.Errorf("case[%d] expected failure", i)
		}
	}
}
开发者ID:leonfs,项目名称:romulus,代码行数:32,代码来源:validation_test.go

示例9: TestIsDNS952Label

func TestIsDNS952Label(t *testing.T) {
	goodValues := []string{
		"a", "ab", "abc", "a1", "a-1", "a--1--2--b",
		strings.Repeat("a", 24),
	}
	for _, val := range goodValues {
		if !IsDNS952Label(val) {
			t.Errorf("expected true for '%s'", val)
		}
	}

	badValues := []string{
		"0", "01", "012", "1a", "1-a", "1--a--b--2",
		"", "A", "ABC", "aBc", "A1", "A-1", "1-A",
		"-", "a-", "-a", "1-", "-1",
		"_", "a_", "_a", "a_b", "1_", "_1", "1_2",
		".", "a.", ".a", "a.b", "1.", ".1", "1.2",
		" ", "a ", " a", "a b", "1 ", " 1", "1 2",
		strings.Repeat("a", 25),
	}
	for _, val := range badValues {
		if IsDNS952Label(val) {
			t.Errorf("expected false for '%s'", val)
		}
	}
}
开发者ID:leonfs,项目名称:romulus,代码行数:26,代码来源:validation_test.go

示例10: TestBasic

func TestBasic(t *testing.T) {
	testLiterals(t, []string{
		strings.Repeat("a", 1000),
		strings.Repeat("b", 97270),
		strings.Repeat("c", 8000),
	})
}
开发者ID:camarox53,项目名称:coreos-baremetal,代码行数:7,代码来源:record_test.go

示例11: Eureka

func (s *SudokuSolver) Eureka(O *Solution) {
	grid := make([][]int, s.Dim)
	for i := 0; i < s.Dim; i++ {
		grid[i] = make([]int, s.Dim)
	}
	for _, n := range *O {
		nodes := make([]*Node, 4)
		nodes = append(nodes, n)
		for m := n.Right; n != m; m = m.Right {
			nodes = append(nodes, m)
		}
		x, y, digit := s.coverToGrid(nodes)
		grid[x][y] = digit
	}
	sdim := int(math.Sqrt(float64(s.Dim)))
	delim := "+" + strings.Repeat(strings.Repeat("-", sdim*2+1)+"+", sdim)
	for i, line := range grid {
		if i%sdim == 0 {
			fmt.Println(delim)
		}
		for j, cell := range line {
			if j%sdim == 0 {
				if j > 0 {
					fmt.Print(" ")
				}
				fmt.Print("|")
			}
			fmt.Print(" ", cell)
		}
		fmt.Print(" |\n")
	}
	fmt.Println(delim)
}
开发者ID:qur2,项目名称:go-cover,代码行数:33,代码来源:sudoku.go

示例12: TestNoIndexOnSliceProperties

func TestNoIndexOnSliceProperties(t *testing.T) {
	// Check that ExcludeFromIndexes is set on the inner elements,
	// rather than the top-level ArrayValue value.
	ctx := context.Background()
	pl := PropertyList{
		Property{
			Name: "repeated",
			Value: []interface{}{
				123,
				false,
				"short",
				strings.Repeat("a", 1503),
			},
			NoIndex: true,
		},
	}
	key := NewKey(ctx, "dummy", "dummy", 0, nil)

	entity, err := saveEntity(key, &pl)
	if err != nil {
		t.Fatalf("saveEntity: %v", err)
	}

	want := &pb.Value{
		ValueType: &pb.Value_ArrayValue{&pb.ArrayValue{[]*pb.Value{
			{ValueType: &pb.Value_IntegerValue{123}, ExcludeFromIndexes: true},
			{ValueType: &pb.Value_BooleanValue{false}, ExcludeFromIndexes: true},
			{ValueType: &pb.Value_StringValue{"short"}, ExcludeFromIndexes: true},
			{ValueType: &pb.Value_StringValue{strings.Repeat("a", 1503)}, ExcludeFromIndexes: true},
		}}},
	}
	if got := entity.Properties["repeated"]; !proto.Equal(got, want) {
		t.Errorf("Entity proto differs\ngot:  %v\nwant: %v", got, want)
	}
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:35,代码来源:datastore_test.go

示例13: TestRandomBuildTag

func TestRandomBuildTag(t *testing.T) {
	tests := []struct {
		namespace, name string
		want            string
	}{
		{"test", "build-1", "test/build-1:f1f85ff5"},
		// For long build namespace + build name, the returned random build tag
		// would be longer than the limit of reference.NameTotalLengthMax (255
		// chars). We do not truncate the repository name because it could create an
		// invalid repository name (e.g., namespace=abc, name=d, repo=abc/d,
		// trucated=abc/ -> invalid), so we simply take a SHA1 hash of the
		// repository name (which is guaranteed to be a valid repository name) and
		// preserve the random tag.
		{
			"namespace" + strings.Repeat(".namespace", 20),
			"name" + strings.Repeat(".name", 20),
			"47c1d5c686ce4563521c625457e79ca23c07bc27:f1f85ff5",
		},
	}
	for _, tt := range tests {
		rand.Seed(0)
		got := randomBuildTag(tt.namespace, tt.name)
		if !reflect.DeepEqual(got, tt.want) {
			t.Errorf("randomBuildTag(%q, %q) = %q, want %q", tt.namespace, tt.name, got, tt.want)
		}
	}
}
开发者ID:richm,项目名称:origin,代码行数:27,代码来源:common_test.go

示例14: UpgradesSequentialReads_ExistingReader

func (t *RandomReaderTest) UpgradesSequentialReads_ExistingReader() {
	t.object.Size = 1 << 40
	const readSize = 10

	// Simulate an existing reader at the correct offset, which will be exhausted
	// by the read below.
	const existingSize = 3
	r := strings.NewReader(strings.Repeat("x", existingSize))

	t.rr.wrapped.reader = ioutil.NopCloser(r)
	t.rr.wrapped.cancel = func() {}
	t.rr.wrapped.start = 1
	t.rr.wrapped.limit = 1 + existingSize

	// The bucket should be asked to read up to the end of the object.
	r = strings.NewReader(strings.Repeat("x", readSize-existingSize))
	rc := ioutil.NopCloser(r)

	ExpectCall(t.bucket, "NewReader")(
		Any(),
		AllOf(rangeStartIs(1+existingSize), rangeLimitIs(t.object.Size))).
		WillOnce(Return(rc, nil))

	// Call through.
	buf := make([]byte, readSize)
	t.rr.ReadAt(buf, 1)

	// Check the state now.
	ExpectEq(1+readSize, t.rr.wrapped.start)
	ExpectEq(t.object.Size, t.rr.wrapped.limit)
}
开发者ID:horzadome,项目名称:gcsfuse,代码行数:31,代码来源:random_reader_test.go

示例15: CreateTable

func CreateTable(tbl PicklesTableArgument) string {
	Html := ""
	if len(tbl.HeaderRow) > 0 {
		Html += "<table>"
		for n, y := range tbl.DataRows {
			if n == 1 && y[0] == strings.Repeat("-", strings.Count(y[0], "")-1) {
				continue
			}
			if n == len(tbl.DataRows)-1 && y[0] == strings.Repeat("-", strings.Count(y[0], "")-1) {
				continue
			}
			//fmt.Printf("ligne %d grp[%s] chaine lue [%s] taille:[%d] chaine de tiret [%s]\n",n,y,y[0],strings.Count(y[0],""),strings.Repeat("-", strings.Count(y[0],"")))
			Html += "<tr>"
			for _, z := range y {
				if n == 0 {
					Html += fmt.Sprintf("<th>%s</th>", z)
				} else {
					Html += fmt.Sprintf("<td>%s</td>", z)
				}
			}
			Html += "</tr>"
			//fmt.Printf("TableArgument.DataRows[%d]: %v\n", n,y)
		}
		Html += "</table>"
		// debug log.Fatalf("Stop %s",Html)

	}
	return Html
}
开发者ID:StephaneTy-Pro,项目名称:Pickles2TesLink,代码行数:29,代码来源:Pickles2TestLink.go


注:本文中的strings.Repeat函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。