|
| 1 | +// This file is part of arduino-cli. |
| 2 | +// |
| 3 | +// Copyright 2020 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 license@arduino.cc. |
| 15 | + |
| 16 | +package builder |
| 17 | + |
| 18 | +import ( |
| 19 | + "testing" |
| 20 | + |
| 21 | + properties "github.com/arduino/go-properties-orderedmap" |
| 22 | + "github.com/stretchr/testify/require" |
| 23 | +) |
| 24 | + |
| 25 | +func TestRecipeFinder(t *testing.T) { |
| 26 | + t.Run("NumberedRecipes", func(t *testing.T) { |
| 27 | + buildProperties := properties.NewMap() |
| 28 | + buildProperties.Set("recipe.test", "test") |
| 29 | + buildProperties.Set("recipe.1.test", "test2") |
| 30 | + buildProperties.Set("recipe.2.test", "test3") |
| 31 | + recipes := findRecipes(buildProperties, "recipe", ".test") |
| 32 | + require.Equal(t, []string{"recipe.1.test", "recipe.2.test"}, recipes) |
| 33 | + }) |
| 34 | + t.Run("NumberedRecipesWithGaps", func(t *testing.T) { |
| 35 | + buildProperties := properties.NewMap() |
| 36 | + buildProperties.Set("recipe.test", "test") |
| 37 | + buildProperties.Set("recipe.2.test", "test3") |
| 38 | + buildProperties.Set("recipe.0.test", "test2") |
| 39 | + recipes := findRecipes(buildProperties, "recipe", ".test") |
| 40 | + require.Equal(t, []string{"recipe.0.test", "recipe.2.test"}, recipes) |
| 41 | + }) |
| 42 | + t.Run("NumberedRecipesWithGapsAndDifferentLenghtNumbers", func(t *testing.T) { |
| 43 | + buildProperties := properties.NewMap() |
| 44 | + buildProperties.Set("recipe.test", "test") |
| 45 | + buildProperties.Set("recipe.12.test", "test3") |
| 46 | + buildProperties.Set("recipe.2.test", "test2") |
| 47 | + recipes := findRecipes(buildProperties, "recipe", ".test") |
| 48 | + // The order is sorted alphabetically, not numerically |
| 49 | + require.Equal(t, []string{"recipe.12.test", "recipe.2.test"}, recipes) |
| 50 | + }) |
| 51 | + t.Run("NumberedRecipesWithGapsAndNumbers", func(t *testing.T) { |
| 52 | + buildProperties := properties.NewMap() |
| 53 | + buildProperties.Set("recipe.test", "test") |
| 54 | + buildProperties.Set("recipe.12.test", "test3") |
| 55 | + buildProperties.Set("recipe.02.test", "test2") |
| 56 | + buildProperties.Set("recipe.09.test", "test2") |
| 57 | + recipes := findRecipes(buildProperties, "recipe", ".test") |
| 58 | + require.Equal(t, []string{"recipe.02.test", "recipe.09.test", "recipe.12.test"}, recipes) |
| 59 | + }) |
| 60 | + t.Run("UnnumberedRecipies", func(t *testing.T) { |
| 61 | + buildProperties := properties.NewMap() |
| 62 | + buildProperties.Set("recipe.test", "test") |
| 63 | + buildProperties.Set("recipe.a.test", "test3") |
| 64 | + buildProperties.Set("recipe.b.test", "test2") |
| 65 | + recipes := findRecipes(buildProperties, "recipe", ".test") |
| 66 | + require.Equal(t, []string{"recipe.a.test", "recipe.b.test"}, recipes) |
| 67 | + }) |
| 68 | + t.Run("ObjcopyRecipies/1", func(t *testing.T) { |
| 69 | + buildProperties := properties.NewMap() |
| 70 | + buildProperties.Set("recipe.objcopy.eep.pattern", "test") |
| 71 | + buildProperties.Set("recipe.objcopy.hex.pattern", "test") |
| 72 | + recipes := findRecipes(buildProperties, "recipe.objcopy", ".pattern") |
| 73 | + require.Equal(t, []string{"recipe.objcopy.eep.pattern", "recipe.objcopy.hex.pattern"}, recipes) |
| 74 | + }) |
| 75 | + t.Run("ObjcopyRecipies/2", func(t *testing.T) { |
| 76 | + buildProperties := properties.NewMap() |
| 77 | + buildProperties.Set("recipe.objcopy.partitions.bin.pattern", "test") |
| 78 | + recipes := findRecipes(buildProperties, "recipe.objcopy", ".pattern") |
| 79 | + require.Equal(t, []string{"recipe.objcopy.partitions.bin.pattern"}, recipes) |
| 80 | + }) |
| 81 | +} |
0 commit comments