Skip to content

Commit

Permalink
Fixed issue #115
Browse files Browse the repository at this point in the history
Signed-off-by: quobix <dave@quobix.com>
  • Loading branch information
daveshanley committed Mar 24, 2024
1 parent 8470f90 commit a95d6da
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion git/read_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestExtractHistoryFromFile(t *testing.T) {
history, _ := ExtractHistoryFromFile("./", "read_local.go", c, e, 25)
<-d
assert.NotNil(t, history)
assert.Equal(t, "adding read_local.go to test repo code", history[len(history)-1].Message)
assert.Equal(t, "refactoring sketch code", history[len(history)-1].Message)
}

func TestExtractHistoryFromFile_Fail(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion tui/build_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func buildTreeNode(root *tview.TreeNode, object any) *tview.TreeNode {
continue

case reflect.TypeOf([]*whatChangedModel.Change{}):
topChanges = append(topChanges, field.Elem().Interface().([]*whatChangedModel.Change)...)
slice, ok := field.Interface().([]*whatChangedModel.Change)
if !ok {
continue
}
topChanges = append(topChanges, slice...)
continue

case reflect.TypeOf(&whatChangedModel.InfoChanges{}):
Expand Down
31 changes: 31 additions & 0 deletions tui/build_tree_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2023-2024 Princess Beef Heavy Industries, LLC / Dave Shanley
// https://pb33f.io

package tui

import (
whatChangedModel "github.com/pb33f/libopenapi/what-changed/model"
"github.com/rivo/tview"
"github.com/stretchr/testify/assert"
"testing"
)

// reported in https://github.com/pb33f/openapi-changes/issues/115
func TestBuildTreeModel_SliceOfChanges(t *testing.T) {

// create a dummy slice of whatChangedModel slice
changed := []*whatChangedModel.Change{
{
ChangeType: whatChangedModel.PropertyAdded,
},
{
ChangeType: whatChangedModel.PropertyRemoved,
},
}

p := &whatChangedModel.PropertyChanges{Changes: changed}=
f := tview.TreeNode{}
v := buildTreeNode(&f, p)
assert.NotNil(t, v)
assert.Equal(t, 2, len(v.GetChildren()))
}

0 comments on commit a95d6da

Please sign in to comment.