From f68655fda890223241985564ac41609f458270d2 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Fri, 7 May 2021 17:32:15 +0200 Subject: [PATCH] Fix sorting of platforms and boards --- commands/board/list.go | 3 ++- commands/core/list.go | 3 ++- commands/core/search.go | 2 +- test/test_core.py | 16 ++++++++-------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/commands/board/list.go b/commands/board/list.go index a804b9908c2..098faec7f72 100644 --- a/commands/board/list.go +++ b/commands/board/list.go @@ -22,6 +22,7 @@ import ( "net/http" "regexp" "sort" + "strings" "sync" "github.com/arduino/arduino-cli/arduino/cores/packagemanager" @@ -151,7 +152,7 @@ func identify(pm *packagemanager.PackageManager, port *commands.BoardPort) ([]*r // Sort by FQBN alphabetically sort.Slice(boards, func(i, j int) bool { - return boards[i].Fqbn < boards[j].Fqbn + return strings.ToLower(boards[i].Fqbn) < strings.ToLower(boards[j].Fqbn) }) // Put Arduino boards before others in case there are non Arduino boards with identical VID:PID combination diff --git a/commands/core/list.go b/commands/core/list.go index 2e69fa04c44..708759e7f20 100644 --- a/commands/core/list.go +++ b/commands/core/list.go @@ -17,6 +17,7 @@ package core import ( "sort" + "strings" "github.com/arduino/arduino-cli/commands" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" @@ -71,7 +72,7 @@ func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) { } // Sort result alphabetically and put deprecated platforms at the bottom sort.Slice(res, func(i, j int) bool { - return res[i].Name < res[j].Name + return strings.ToLower(res[i].Name) < strings.ToLower(res[j].Name) }) sort.SliceStable(res, func(i, j int) bool { if !res[i].Deprecated && res[j].Deprecated { diff --git a/commands/core/search.go b/commands/core/search.go index b2d81cbe8d0..e6942cd140a 100644 --- a/commands/core/search.go +++ b/commands/core/search.go @@ -117,7 +117,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse // Sort result alphabetically and put deprecated platforms at the bottom sort.Slice( out, func(i, j int) bool { - return out[i].Name < out[j].Name + return strings.ToLower(out[i].Name) < strings.ToLower(out[j].Name) }) sort.SliceStable( out, func(i, j int) bool { diff --git a/test/test_core.py b/test/test_core.py index 7bc5db64348..6500222ac6f 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -550,8 +550,8 @@ def test_core_search_sorted_results(run_command, httpserver): deprecated = [l for l in lines if l[2].startswith("[DEPRECATED]")] # verify that results are already sorted correctly - assert not_deprecated == sorted(not_deprecated, key=lambda tokens: tokens[2]) - assert deprecated == sorted(deprecated, key=lambda tokens: tokens[2]) + assert not_deprecated == sorted(not_deprecated, key=lambda tokens: tokens[2].lower()) + assert deprecated == sorted(deprecated, key=lambda tokens: tokens[2].lower()) # verify that deprecated platforms are the last ones assert lines == not_deprecated + deprecated @@ -565,8 +565,8 @@ def test_core_search_sorted_results(run_command, httpserver): deprecated = [p for p in platforms if p.get("deprecated")] # verify that results are already sorted correctly - assert not_deprecated == sorted(not_deprecated, key=lambda keys: keys["name"]) - assert deprecated == sorted(deprecated, key=lambda keys: keys["name"]) + assert not_deprecated == sorted(not_deprecated, key=lambda keys: keys["name"].lower()) + assert deprecated == sorted(deprecated, key=lambda keys: keys["name"].lower()) # verify that deprecated platforms are the last ones assert platforms == not_deprecated + deprecated @@ -593,8 +593,8 @@ def test_core_list_sorted_results(run_command, httpserver): deprecated = [l for l in lines if l[3].startswith("[DEPRECATED]")] # verify that results are already sorted correctly - assert not_deprecated == sorted(not_deprecated, key=lambda tokens: tokens[3]) - assert deprecated == sorted(deprecated, key=lambda tokens: tokens[3]) + assert not_deprecated == sorted(not_deprecated, key=lambda tokens: tokens[3].lower()) + assert deprecated == sorted(deprecated, key=lambda tokens: tokens[3].lower()) # verify that deprecated platforms are the last ones assert lines == not_deprecated + deprecated @@ -609,8 +609,8 @@ def test_core_list_sorted_results(run_command, httpserver): deprecated = [p for p in platforms if p.get("deprecated")] # verify that results are already sorted correctly - assert not_deprecated == sorted(not_deprecated, key=lambda keys: keys["name"]) - assert deprecated == sorted(deprecated, key=lambda keys: keys["name"]) + assert not_deprecated == sorted(not_deprecated, key=lambda keys: keys["name"].lower()) + assert deprecated == sorted(deprecated, key=lambda keys: keys["name"].lower()) # verify that deprecated platforms are the last ones assert platforms == not_deprecated + deprecated