Swap go code to use the 'range N' syntax added in go 1.22

This commit is contained in:
David Dworken
2025-02-04 21:44:51 -08:00
parent 3f34db597a
commit ed38fd1b02
5 changed files with 10 additions and 11 deletions

View File

@@ -67,7 +67,7 @@ func BuildUpdateInfo(version string) shared.UpdateInfo {
func decrementVersionIfInvalid(initialVersion string) string { func decrementVersionIfInvalid(initialVersion string) string {
// Decrements the version up to 5 times if the version doesn't have valid binaries yet. // Decrements the version up to 5 times if the version doesn't have valid binaries yet.
version := initialVersion version := initialVersion
for i := 0; i < 5; i++ { for range 5 {
updateInfo := BuildUpdateInfo(version) updateInfo := BuildUpdateInfo(version)
err := assertValidUpdate(updateInfo) err := assertValidUpdate(updateInfo)
if err == nil { if err == nil {

View File

@@ -648,7 +648,7 @@ func testRepeatedCommandThenQuery(t *testing.T, tester shellTester) {
} }
// Run a command many times // Run a command many times
for i := 0; i < 25; i++ { for i := range 25 {
tester.RunInteractiveShell(t, fmt.Sprintf("echo mycommand-%d", i)) 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 // Run a command many times
for i := 0; i < 25; i++ { for i := range 25 {
tester.RunInteractiveShell(t, fmt.Sprintf("echo mycommand-%d", i)) tester.RunInteractiveShell(t, fmt.Sprintf("echo mycommand-%d", i))
out = hishtoryQuery(t, tester, fmt.Sprintf("mycommand-%d", i)) out = hishtoryQuery(t, tester, fmt.Sprintf("mycommand-%d", i))
if strings.Count(out, "\n") != 3 { if strings.Count(out, "\n") != 3 {
@@ -707,7 +707,7 @@ func testRepeatedEnableDisable(t *testing.T, tester shellTester) {
installHishtory(t, tester, "") installHishtory(t, tester, "")
// Run a command many times // Run a command many times
for i := 0; i < 25; i++ { for i := range 25 {
tester.RunInteractiveShell(t, fmt.Sprintf(`echo mycommand-%d tester.RunInteractiveShell(t, fmt.Sprintf(`echo mycommand-%d
hishtory disable hishtory disable
echo shouldnotshowup echo shouldnotshowup
@@ -767,7 +767,7 @@ echo hello2
func waitForBackgroundSavesToComplete(t testing.TB) { func waitForBackgroundSavesToComplete(t testing.TB) {
lastOut := "" lastOut := ""
lastErr := "" lastErr := ""
for i := 0; i < 20; i++ { for range 20 {
cmd := exec.Command(getPidofCommand(), "hishtory") cmd := exec.Command(getPidofCommand(), "hishtory")
var stdout bytes.Buffer var stdout bytes.Buffer
var stderr bytes.Buffer var stderr bytes.Buffer
@@ -2942,7 +2942,7 @@ func TestSetConfigNoCorruption(t *testing.T) {
conf, err := hctx.GetConfig() conf, err := hctx.GetConfig()
require.NoError(t, err) require.NoError(t, err)
var doneWg sync.WaitGroup var doneWg sync.WaitGroup
for i := 0; i < 10; i++ { for i := range 10 {
doneWg.Add(1) doneWg.Add(1)
go func(i int) { go func(i int) {
// Make a new config of a varied length // Make a new config of a varied length

View File

@@ -1065,7 +1065,7 @@ func splitEscaped(query string, separator rune, maxSplit int) []string {
runeQuery := []rune(query) runeQuery := []rune(query)
isInDoubleQuotedString := false isInDoubleQuotedString := false
isInSingleQuotedString := 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 (maxSplit < 0 || splits < maxSplit) && runeQuery[i] == separator && !isInSingleQuotedString && !isInDoubleQuotedString {
if string(token) != "" { if string(token) != "" {
tokens = append(tokens, string(token)) tokens = append(tokens, string(token))
@@ -1120,7 +1120,7 @@ func heuristicIgnoreUnclosedQuote(isCurrentlyInQuotedString bool, quoteType rune
func containsUnescaped(query, token string) bool { func containsUnescaped(query, token string) bool {
runeQuery := []rune(query) runeQuery := []rune(query)
for i := 0; i < len(runeQuery); i++ { for i := range len(runeQuery) {
if runeQuery[i] == '\\' && i+1 < len(runeQuery) { if runeQuery[i] == '\\' && i+1 < len(runeQuery) {
i++ i++
} else if string(runeQuery[i:i+len(token)]) == token { } else if string(runeQuery[i:i+len(token)]) == token {

View File

@@ -530,7 +530,7 @@ func getRows(ctx context.Context, columnNames []string, shellName, defaultFilter
var filteredData []*data.HistoryEntry var filteredData []*data.HistoryEntry
seenCommands := make(map[string]bool) seenCommands := make(map[string]bool)
for i := 0; i < numEntries; i++ { for i := range numEntries {
if i < len(searchResults) { if i < len(searchResults) {
entry := searchResults[i] entry := searchResults[i]
@@ -1011,5 +1011,4 @@ func TuiQuery(ctx context.Context, shellName string, initialQueryArray []string)
return nil return nil
} }
// TODO: support custom key bindings
// TODO: make the help page wrap // TODO: make the help page wrap

View File

@@ -214,7 +214,7 @@ func checkError(err error) {
} }
func buildServer() string { func buildServer() string {
for i := 0; i < 100; i++ { for range 100 {
wd, err := os.Getwd() wd, err := os.Getwd()
if err != nil { if err != nil {
panic(fmt.Sprintf("failed to getwd: %v", err)) panic(fmt.Sprintf("failed to getwd: %v", err))