This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move rand util into rand.go - RandString changed to RandomID and uses 256 bits - Move string util into strings.go
- Loading branch information
Showing
7 changed files
with
67 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2015 Keybase, Inc. All rights reserved. Use of | ||
// this source code is governed by the included BSD license. | ||
|
||
package util | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestRandString(t *testing.T) { | ||
s, err := RandomID("prefix.") | ||
t.Logf("Rand string: %s", s) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !strings.HasPrefix(s, "prefix.") { | ||
t.Errorf("Invalid prefix: %s", s) | ||
} | ||
if len(s)-len("prefix.") != 52 { | ||
t.Errorf("Invalid length: %s (%d)", s, len(s)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2015 Keybase, Inc. All rights reserved. Use of | ||
// this source code is governed by the included BSD license. | ||
|
||
package util | ||
|
||
import "strings" | ||
|
||
// JoinPredicate joins strings with predicate | ||
func JoinPredicate(arr []string, delimeter string, f func(s string) bool) string { | ||
arrNew := make([]string, 0, len(arr)) | ||
for _, s := range arr { | ||
if f(s) { | ||
arrNew = append(arrNew, s) | ||
} | ||
} | ||
return strings.Join(arrNew, delimeter) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2015 Keybase, Inc. All rights reserved. Use of | ||
// this source code is governed by the included BSD license. | ||
|
||
package util | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestJoinPredicate(t *testing.T) { | ||
f := func(s string) bool { return strings.HasPrefix(s, "f") } | ||
s := JoinPredicate([]string{"foo", "bar", "faa"}, "-", f) | ||
if s != "foo-faa" { | ||
t.Errorf("Unexpected output: %s", s) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters