Skip to content

Commit 09994f2

Browse files
committed
Implemented missing AsYaml methods and added tests
1 parent c7859d4 commit 09994f2

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Diff for: arduino/sketch/profiles.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type ProfileRequiredPlatforms []*ProfilePlatformReference
7676

7777
// AsYaml outputs the required platforms as Yaml
7878
func (p *ProfileRequiredPlatforms) AsYaml() string {
79-
res := ""
79+
res := " platforms:\n"
8080
for _, platform := range *p {
8181
res += platform.AsYaml()
8282
}
@@ -89,7 +89,11 @@ type ProfileRequiredLibraries []*ProfileLibraryReference
8989

9090
// AsYaml outputs the required libraries as Yaml
9191
func (p *ProfileRequiredLibraries) AsYaml() string {
92-
return ""
92+
res := " libraries:\n"
93+
for _, lib := range *p {
94+
res += lib.AsYaml()
95+
}
96+
return res
9397
}
9498

9599
// ProfilePlatformReference is a reference to a platform
@@ -187,6 +191,12 @@ func (l *ProfileLibraryReference) UnmarshalYAML(unmarshal func(interface{}) erro
187191
return nil
188192
}
189193

194+
// AsYaml outputs the required library as Yaml
195+
func (l *ProfileLibraryReference) AsYaml() string {
196+
res := fmt.Sprintf(" - %s (%s)\n", l.Library, l.Version)
197+
return res
198+
}
199+
190200
func (l *ProfileLibraryReference) String() string {
191201
return fmt.Sprintf("%s@%s", l.Library, l.Version)
192202
}

Diff for: arduino/sketch/profiles_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import (
2424
)
2525

2626
func TestProjectFileLoading(t *testing.T) {
27-
proj, err := LoadProjectFile(paths.New("testdata", "SketchWithProfiles", "sketch.yml"))
27+
sketchProj := paths.New("testdata", "SketchWithProfiles", "sketch.yml")
28+
proj, err := LoadProjectFile(sketchProj)
2829
require.NoError(t, err)
2930
fmt.Println(proj)
31+
golden, err := sketchProj.ReadFile()
32+
require.NoError(t, err)
33+
require.Equal(t, proj.AsYaml(), string(golden))
3034
}

0 commit comments

Comments
 (0)