Skip to content

Commit 59c2348

Browse files
committed
Fix sorting of platforms and boards (#1282)
1 parent 20e77aa commit 59c2348

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

Diff for: commands/board/list.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"net/http"
2323
"regexp"
2424
"sort"
25+
"strings"
2526
"sync"
2627

2728
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
@@ -151,7 +152,7 @@ func identify(pm *packagemanager.PackageManager, port *commands.BoardPort) ([]*r
151152

152153
// Sort by FQBN alphabetically
153154
sort.Slice(boards, func(i, j int) bool {
154-
return boards[i].Fqbn < boards[j].Fqbn
155+
return strings.ToLower(boards[i].Fqbn) < strings.ToLower(boards[j].Fqbn)
155156
})
156157

157158
// Put Arduino boards before others in case there are non Arduino boards with identical VID:PID combination

Diff for: commands/core/list.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package core
1717

1818
import (
1919
"sort"
20+
"strings"
2021

2122
"github.com/arduino/arduino-cli/commands"
2223
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -71,7 +72,7 @@ func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) {
7172
}
7273
// Sort result alphabetically and put deprecated platforms at the bottom
7374
sort.Slice(res, func(i, j int) bool {
74-
return res[i].Name < res[j].Name
75+
return strings.ToLower(res[i].Name) < strings.ToLower(res[j].Name)
7576
})
7677
sort.SliceStable(res, func(i, j int) bool {
7778
if !res[i].Deprecated && res[j].Deprecated {

Diff for: commands/core/search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
117117
// Sort result alphabetically and put deprecated platforms at the bottom
118118
sort.Slice(
119119
out, func(i, j int) bool {
120-
return out[i].Name < out[j].Name
120+
return strings.ToLower(out[i].Name) < strings.ToLower(out[j].Name)
121121
})
122122
sort.SliceStable(
123123
out, func(i, j int) bool {

Diff for: test/test_core.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,8 @@ def test_core_search_sorted_results(run_command, httpserver):
550550
deprecated = [l for l in lines if l[2].startswith("[DEPRECATED]")]
551551

552552
# verify that results are already sorted correctly
553-
assert not_deprecated == sorted(not_deprecated, key=lambda tokens: tokens[2])
554-
assert deprecated == sorted(deprecated, key=lambda tokens: tokens[2])
553+
assert not_deprecated == sorted(not_deprecated, key=lambda tokens: tokens[2].lower())
554+
assert deprecated == sorted(deprecated, key=lambda tokens: tokens[2].lower())
555555

556556
# verify that deprecated platforms are the last ones
557557
assert lines == not_deprecated + deprecated
@@ -565,8 +565,8 @@ def test_core_search_sorted_results(run_command, httpserver):
565565
deprecated = [p for p in platforms if p.get("deprecated")]
566566

567567
# verify that results are already sorted correctly
568-
assert not_deprecated == sorted(not_deprecated, key=lambda keys: keys["name"])
569-
assert deprecated == sorted(deprecated, key=lambda keys: keys["name"])
568+
assert not_deprecated == sorted(not_deprecated, key=lambda keys: keys["name"].lower())
569+
assert deprecated == sorted(deprecated, key=lambda keys: keys["name"].lower())
570570
# verify that deprecated platforms are the last ones
571571
assert platforms == not_deprecated + deprecated
572572

@@ -593,8 +593,8 @@ def test_core_list_sorted_results(run_command, httpserver):
593593
deprecated = [l for l in lines if l[3].startswith("[DEPRECATED]")]
594594

595595
# verify that results are already sorted correctly
596-
assert not_deprecated == sorted(not_deprecated, key=lambda tokens: tokens[3])
597-
assert deprecated == sorted(deprecated, key=lambda tokens: tokens[3])
596+
assert not_deprecated == sorted(not_deprecated, key=lambda tokens: tokens[3].lower())
597+
assert deprecated == sorted(deprecated, key=lambda tokens: tokens[3].lower())
598598

599599
# verify that deprecated platforms are the last ones
600600
assert lines == not_deprecated + deprecated
@@ -609,8 +609,8 @@ def test_core_list_sorted_results(run_command, httpserver):
609609
deprecated = [p for p in platforms if p.get("deprecated")]
610610

611611
# verify that results are already sorted correctly
612-
assert not_deprecated == sorted(not_deprecated, key=lambda keys: keys["name"])
613-
assert deprecated == sorted(deprecated, key=lambda keys: keys["name"])
612+
assert not_deprecated == sorted(not_deprecated, key=lambda keys: keys["name"].lower())
613+
assert deprecated == sorted(deprecated, key=lambda keys: keys["name"].lower())
614614
# verify that deprecated platforms are the last ones
615615
assert platforms == not_deprecated + deprecated
616616

0 commit comments

Comments
 (0)