Skip to content

Commit fc3859d

Browse files
committed
Added test for findBestLibraryWithHeader() function
Signed-off-by: Cristian Maglie <[email protected]>
1 parent bc2c38f commit fc3859d

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* This file is part of Arduino Builder.
3+
*
4+
* Arduino Builder is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2017 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package builder
31+
32+
import (
33+
"testing"
34+
35+
"arduino.cc/builder/types"
36+
37+
"github.com/stretchr/testify/require"
38+
)
39+
40+
func TestFindBestLibraryWithHeader(t *testing.T) {
41+
l1 := &types.Library{Name: "Calculus Lib"}
42+
l2 := &types.Library{Name: "Calculus Lib-master"}
43+
l3 := &types.Library{Name: "Calculus Lib Improved"}
44+
l4 := &types.Library{Name: "Another Calculus Lib"}
45+
l5 := &types.Library{Name: "Yet Another Calculus Lib Improved"}
46+
l6 := &types.Library{Name: "AnotherLib"}
47+
48+
// Test exact name matching
49+
res := findBestLibraryWithHeader("calculus_lib.h", []*types.Library{l6, l5, l4, l3, l2, l1})
50+
require.Equal(t, l1.Name, res.Name)
51+
52+
// Test exact name with "-master" postfix matching
53+
res = findBestLibraryWithHeader("calculus_lib.h", []*types.Library{l6, l5, l4, l3, l2})
54+
require.Equal(t, l2.Name, res.Name)
55+
56+
// Test prefix matching
57+
res = findBestLibraryWithHeader("calculus_lib.h", []*types.Library{l6, l5, l4, l3})
58+
require.Equal(t, l3.Name, res.Name)
59+
60+
// Test postfix matching
61+
res = findBestLibraryWithHeader("calculus_lib.h", []*types.Library{l6, l5, l4})
62+
require.Equal(t, l4.Name, res.Name)
63+
64+
// Test "contains"" matching
65+
res = findBestLibraryWithHeader("calculus_lib.h", []*types.Library{l6, l5})
66+
require.Equal(t, l5.Name, res.Name)
67+
68+
// Test none matching
69+
res = findBestLibraryWithHeader("calculus_lib.h", []*types.Library{l6})
70+
require.Nil(t, res)
71+
}

0 commit comments

Comments
 (0)