|
| 1 | +// This file is part of arduino-cli. |
| 2 | +// |
| 3 | +// Copyright 2025 ARDUINO SA (http://www.arduino.cc/) |
| 4 | +// |
| 5 | +// This software is released under the GNU General Public License version 3, |
| 6 | +// which covers the main part of arduino-cli. |
| 7 | +// The terms of this license can be found at: |
| 8 | +// https://www.gnu.org/licenses/gpl-3.0.en.html |
| 9 | +// |
| 10 | +// You can be released from the requirements of the above licenses by purchasing |
| 11 | +// a commercial license. Buying such a license is mandatory if you want to |
| 12 | +// modify or otherwise use the software for commercial activities involving the |
| 13 | +// Arduino software without disclosing the source code of your own applications. |
| 14 | +// To purchase a commercial license, send an email to [email protected]. |
| 15 | + |
| 16 | +package libraries |
| 17 | + |
| 18 | +import ( |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/stretchr/testify/require" |
| 22 | +) |
| 23 | + |
| 24 | +func TestDependencyExtract(t *testing.T) { |
| 25 | + check := func(depDefinition string, name []string, ver []string) { |
| 26 | + dep, err := extractDependenciesList(depDefinition) |
| 27 | + require.NoError(t, err) |
| 28 | + require.NotNil(t, dep) |
| 29 | + require.Len(t, dep, len(name)) |
| 30 | + for i := range name { |
| 31 | + require.Equal(t, name[i], dep[i].Name, depDefinition) |
| 32 | + require.Equal(t, ver[i], dep[i].VersionConstraint.String(), depDefinition) |
| 33 | + } |
| 34 | + } |
| 35 | + invalid := func(depends string) { |
| 36 | + dep, err := extractDependenciesList(depends) |
| 37 | + require.Nil(t, dep) |
| 38 | + require.Error(t, err) |
| 39 | + } |
| 40 | + check("ciao", []string{"ciao"}, []string{""}) |
| 41 | + check("MyLib (>1.2.3)", []string{"MyLib"}, []string{">1.2.3"}) |
| 42 | + check("MyLib (>=1.2.3)", []string{"MyLib"}, []string{">=1.2.3"}) |
| 43 | + check("MyLib (<1.2.3)", []string{"MyLib"}, []string{"<1.2.3"}) |
| 44 | + check("MyLib (<=1.2.3)", []string{"MyLib"}, []string{"<=1.2.3"}) |
| 45 | + check("MyLib (!=1.2.3)", []string{"MyLib"}, []string{"!(=1.2.3)"}) |
| 46 | + check("MyLib (>1.0.0 && <2.1.0)", []string{"MyLib"}, []string{"(>1.0.0 && <2.1.0)"}) |
| 47 | + check("MyLib (<1.0.0 || >2.0.0)", []string{"MyLib"}, []string{"(<1.0.0 || >2.0.0)"}) |
| 48 | + check("MyLib ((>0.1.0 && <2.0.0) || >2.1.0)", []string{"MyLib"}, []string{"((>0.1.0 && <2.0.0) || >2.1.0)"}) |
| 49 | + check("MyLib ()", []string{"MyLib"}, []string{""}) |
| 50 | + check("MyLib (>=1.2.3),AnotherLib, YetAnotherLib (=1.0.0)", |
| 51 | + []string{"MyLib", "AnotherLib", "YetAnotherLib"}, |
| 52 | + []string{">=1.2.3", "", "=1.0.0"}) |
| 53 | + invalid("MyLib,,AnotherLib") |
| 54 | + invalid("(MyLib)") |
| 55 | + invalid("MyLib(=1.2.3)") |
| 56 | + check("Arduino Uno WiFi Dev Ed Library, LoRa Node (^2.1.2)", |
| 57 | + []string{"Arduino Uno WiFi Dev Ed Library", "LoRa Node"}, |
| 58 | + []string{"", "^2.1.2"}) |
| 59 | + check("Arduino Uno WiFi Dev Ed Library , LoRa Node (^2.1.2)", |
| 60 | + []string{"Arduino Uno WiFi Dev Ed Library", "LoRa Node"}, |
| 61 | + []string{"", "^2.1.2"}) |
| 62 | + check("Arduino_OAuth, ArduinoHttpClient (<0.3.0), NonExistentLib", |
| 63 | + []string{"Arduino_OAuth", "ArduinoHttpClient", "NonExistentLib"}, |
| 64 | + []string{"", "<0.3.0", ""}) |
| 65 | + check("", []string{}, []string{}) |
| 66 | +} |
0 commit comments