Skip to content

Commit 8feeb6a

Browse files
committed
add convenience method to get the source in string format
1 parent 9c74086 commit 8feeb6a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

arduino/sketch/sketch.go

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ func NewItem(itemPath string) (*Item, error) {
4343
return &Item{itemPath, source}, nil
4444
}
4545

46+
// GetSourceStr returns the Source contents in string format
47+
func (i *Item) GetSourceStr() string {
48+
return string(i.Source)
49+
}
50+
4651
// ItemByPath implements sort.Interface for []Item based on
4752
// lexicographic order of the path string.
4853
type ItemByPath []*Item

arduino/sketch/sketch_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestNewItem(t *testing.T) {
3030
assert.Nil(t, err)
3131
assert.Equal(t, sketchItem, item.Path)
3232
assert.Equal(t, []byte(`#include <testlib.h>`), item.Source)
33+
assert.Equal(t, "#include <testlib.h>", item.GetSourceStr())
3334

3435
item, err = sketch.NewItem("doesnt/exist")
3536
assert.Nil(t, item)

0 commit comments

Comments
 (0)