mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-18 18:58:54 +02:00
Swap go code to use the 'range N' syntax added in go 1.22
This commit is contained in:
@@ -67,7 +67,7 @@ func BuildUpdateInfo(version string) shared.UpdateInfo {
|
||||
func decrementVersionIfInvalid(initialVersion string) string {
|
||||
// Decrements the version up to 5 times if the version doesn't have valid binaries yet.
|
||||
version := initialVersion
|
||||
for i := 0; i < 5; i++ {
|
||||
for range 5 {
|
||||
updateInfo := BuildUpdateInfo(version)
|
||||
err := assertValidUpdate(updateInfo)
|
||||
if err == nil {
|
||||
|
@@ -648,7 +648,7 @@ func testRepeatedCommandThenQuery(t *testing.T, tester shellTester) {
|
||||
}
|
||||
|
||||
// Run a command many times
|
||||
for i := 0; i < 25; i++ {
|
||||
for i := range 25 {
|
||||
tester.RunInteractiveShell(t, fmt.Sprintf("echo mycommand-%d", i))
|
||||
}
|
||||
|
||||
@@ -688,7 +688,7 @@ func testRepeatedCommandAndQuery(t *testing.T, tester shellTester) {
|
||||
}
|
||||
|
||||
// Run a command many times
|
||||
for i := 0; i < 25; i++ {
|
||||
for i := range 25 {
|
||||
tester.RunInteractiveShell(t, fmt.Sprintf("echo mycommand-%d", i))
|
||||
out = hishtoryQuery(t, tester, fmt.Sprintf("mycommand-%d", i))
|
||||
if strings.Count(out, "\n") != 3 {
|
||||
@@ -707,7 +707,7 @@ func testRepeatedEnableDisable(t *testing.T, tester shellTester) {
|
||||
installHishtory(t, tester, "")
|
||||
|
||||
// Run a command many times
|
||||
for i := 0; i < 25; i++ {
|
||||
for i := range 25 {
|
||||
tester.RunInteractiveShell(t, fmt.Sprintf(`echo mycommand-%d
|
||||
hishtory disable
|
||||
echo shouldnotshowup
|
||||
@@ -767,7 +767,7 @@ echo hello2
|
||||
func waitForBackgroundSavesToComplete(t testing.TB) {
|
||||
lastOut := ""
|
||||
lastErr := ""
|
||||
for i := 0; i < 20; i++ {
|
||||
for range 20 {
|
||||
cmd := exec.Command(getPidofCommand(), "hishtory")
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
@@ -2942,7 +2942,7 @@ func TestSetConfigNoCorruption(t *testing.T) {
|
||||
conf, err := hctx.GetConfig()
|
||||
require.NoError(t, err)
|
||||
var doneWg sync.WaitGroup
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := range 10 {
|
||||
doneWg.Add(1)
|
||||
go func(i int) {
|
||||
// Make a new config of a varied length
|
||||
|
@@ -1065,7 +1065,7 @@ func splitEscaped(query string, separator rune, maxSplit int) []string {
|
||||
runeQuery := []rune(query)
|
||||
isInDoubleQuotedString := false
|
||||
isInSingleQuotedString := false
|
||||
for i := 0; i < len(runeQuery); i++ {
|
||||
for i := range len(runeQuery) {
|
||||
if (maxSplit < 0 || splits < maxSplit) && runeQuery[i] == separator && !isInSingleQuotedString && !isInDoubleQuotedString {
|
||||
if string(token) != "" {
|
||||
tokens = append(tokens, string(token))
|
||||
@@ -1120,7 +1120,7 @@ func heuristicIgnoreUnclosedQuote(isCurrentlyInQuotedString bool, quoteType rune
|
||||
|
||||
func containsUnescaped(query, token string) bool {
|
||||
runeQuery := []rune(query)
|
||||
for i := 0; i < len(runeQuery); i++ {
|
||||
for i := range len(runeQuery) {
|
||||
if runeQuery[i] == '\\' && i+1 < len(runeQuery) {
|
||||
i++
|
||||
} else if string(runeQuery[i:i+len(token)]) == token {
|
||||
|
@@ -530,7 +530,7 @@ func getRows(ctx context.Context, columnNames []string, shellName, defaultFilter
|
||||
var filteredData []*data.HistoryEntry
|
||||
seenCommands := make(map[string]bool)
|
||||
|
||||
for i := 0; i < numEntries; i++ {
|
||||
for i := range numEntries {
|
||||
if i < len(searchResults) {
|
||||
entry := searchResults[i]
|
||||
|
||||
@@ -1011,5 +1011,4 @@ func TuiQuery(ctx context.Context, shellName string, initialQueryArray []string)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: support custom key bindings
|
||||
// TODO: make the help page wrap
|
||||
|
@@ -214,7 +214,7 @@ func checkError(err error) {
|
||||
}
|
||||
|
||||
func buildServer() string {
|
||||
for i := 0; i < 100; i++ {
|
||||
for range 100 {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to getwd: %v", err))
|
||||
|
Reference in New Issue
Block a user