Skip to content

Commit 92d5c8b

Browse files
authored
CHORE: 0.2.0 pre-release (#30)
1 parent bd23bdb commit 92d5c8b

File tree

22 files changed

+278
-131
lines changed

22 files changed

+278
-131
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build:
1111
test:
1212
go test ./...
1313

14-
coverage:
14+
cov:
1515
go test -coverprofile=.coverage ./...
1616

1717
clean:

assets/components.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"tests": "Tests"
2+
"^([Tt]ests|.*_test|test_.*)$": "Tests",
3+
"^(.*[Cc]ontrollers?)$": "Controllers"
34
}

internal/retrievers/mapping/mapping_test.go renamed to internal/mapping/mapping_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/stretchr/testify/assert"
99
"github.com/stretchr/testify/suite"
1010

11-
"github.com/statloc/core/internal/retrievers/mapping"
11+
"github.com/statloc/core/internal/mapping"
1212
)
1313

1414
type MappingSuite struct {
@@ -19,11 +19,11 @@ type MappingSuite struct {
1919
}
2020

2121
func (s *MappingSuite) SetupSuite() {
22-
rawExtensions, _ := os.ReadFile(filepath.Join("..", "..", "..", "assets", "extensions.json"))
22+
rawExtensions, _ := os.ReadFile(filepath.Join("..", "..", "assets", "languages.json"))
2323
s.extensions = string(rawExtensions)
24-
rawComponents, _ := os.ReadFile(filepath.Join("..", "..", "..", "assets", "components.json"))
24+
rawComponents, _ := os.ReadFile(filepath.Join("..", "..", "assets", "components.json"))
2525
s.components = string(rawComponents)
26-
rawBroken, _ := os.ReadFile(filepath.Join("..", "..", "..", "testdata", "broken.json.txt"))
26+
rawBroken, _ := os.ReadFile(filepath.Join("..", "..", "testdata", "broken.json.txt"))
2727
s.broken = string(rawBroken)
2828
}
2929

@@ -41,7 +41,7 @@ func (s *MappingSuite) TestLoadMapping() {
4141
)
4242

4343
assert.NotNil(s.T(), mapping.Components)
44-
assert.NotNil(s.T(), mapping.Extensions)
44+
assert.NotNil(s.T(), mapping.Languages)
4545
}
4646

4747
func TestMappingSuite(t *testing.T) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
var (
9-
Extensions ExtensionsMapping
9+
Languages LanguagesMapping
1010
Components ComponentsMapping
1111
)
1212

@@ -19,8 +19,8 @@ func LoadJSON[mapType any](content string) mapType {
1919
return mapping
2020
}
2121

22-
func Load(rawComponents string, rawExtensions string) (ComponentsMapping, ExtensionsMapping) {
22+
func Load(rawComponents string, rawExtensions string) (ComponentsMapping, LanguagesMapping) {
2323
Components = LoadJSON[ComponentsMapping](rawComponents)
24-
Extensions = LoadJSON[ExtensionsMapping](rawExtensions)
25-
return Components, Extensions
24+
Languages = LoadJSON[LanguagesMapping](rawExtensions)
25+
return Components, Languages
2626
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ type (
55
ComponentsMapping = map[string]string
66

77
// file extension as as a key, category(language or file type) name as a value
8-
ExtensionsMapping = map[string]string
8+
LanguagesMapping = map[string]string
99
)

internal/matching/matching.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package matching
2+
3+
import "regexp"
4+
5+
func FindMatch[valueType any](s string, mapping map[string]valueType) (value valueType, exists bool) {
6+
for key, value := range mapping {
7+
matches, _ := regexp.MatchString(key, s)
8+
if matches {
9+
return value, true
10+
}
11+
}
12+
return
13+
}

internal/matching/matching_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package matching_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/suite"
8+
9+
"github.com/statloc/core/internal/matching"
10+
)
11+
12+
type MatchingSuite struct {
13+
suite.Suite
14+
mapping map[string]string
15+
wrongMapping map[string]string
16+
}
17+
18+
func (s *MatchingSuite) SetupSuite() {
19+
s.mapping = map[string]string{
20+
"^wrong$": "1",
21+
"^some_strin.?$": "2",
22+
"^some_[Ss].*$": "3",
23+
}
24+
s.wrongMapping = map[string]string{
25+
"^wrong$": "1",
26+
"^some_strin.?$": "2",
27+
}
28+
}
29+
30+
func (s *MatchingSuite) TestFindMatch() {
31+
response, exists := matching.FindMatch[string]("some_String", s.mapping)
32+
33+
assert.True(s.T(), exists)
34+
assert.Equal(s.T(), "3", response)
35+
36+
_, exists = matching.FindMatch[string]("some_String", s.wrongMapping)
37+
38+
assert.False(s.T(), exists)
39+
}
40+
41+
func TestMatchingSuite(t *testing.T) {
42+
suite.Run(t, new(MatchingSuite))
43+
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package tree
22

3-
import "fmt"
4-
53
type PathError struct {
6-
Path string
4+
Message string
75
}
86

97
func (e *PathError) Error() string {
10-
return fmt.Sprintf("%s is not a directory", e.Path)
8+
return e.Message
119
}

0 commit comments

Comments
 (0)