Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom5521 committed Oct 19, 2024
1 parent 82e487b commit 26a3ff9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test:
go test -v ./internal/walk/walk_test.go
go test -v ./pkg/v2/gtools/gtools_test.go
5 changes: 4 additions & 1 deletion pkg/v2/gtools/closures.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ func NewFactorySetup(f func(listitem ListItem)) func(*glib.Object) {

func NewFactoryBind(f func(listitem ListItem, pos int)) func(*glib.Object) {
return func(obj *glib.Object) {
i := obj.Cast().(ListItem)
i, ok := obj.Cast().(ListItem)
if !ok {
panic("Invalid interface conversion! glib.Objector -> ListItem")
}
f(i, int(i.Position()))
}
}
2 changes: 2 additions & 0 deletions pkg/v2/gtools/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
)

func ExampleFetchObjects() {
gtk.Init()

const xml = `<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
Expand Down
69 changes: 69 additions & 0 deletions pkg/v2/gtools/gtools_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package gtools_test

import (
"testing"

"github.com/Tom5521/gtk4tools/pkg/v2/gtools"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
)

func TestInitGTK(t *testing.T) {
if !gtk.InitCheck() {
t.Log("Failed to init GTK")
t.FailNow()
}
}

func TestFetch(t *testing.T) {
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkWindow" id="window">
<property name="title">Hello World</property>
</object>
</interface>`

ui := new(
struct {
Window *gtk.Window `gtk:"window"`
},
)

gtools.FetchObjects(ui, xml)

if ui.Window == nil {
t.Log("ui.Window is nil")
t.FailNow()
}
if ui.Window.Title() != "Hello World" {
t.Log("ui.Window.Title() isn't 'Hello World'")
t.Fail()
}
}

var (
modeller gtools.Modeller[string]
items = []string{"1", "2", "3", "4"}
)

func testModeller(t *testing.T) {
if len(items) != modeller.Len() {
t.Log("Modeller len is greater than slices len")
t.FailNow()
}

if items[1] != modeller.At(1) {
t.Log("Modeller item 1 isn't equal to slice item 1")
t.FailNow()
}
}

func TestModel(t *testing.T) {
modeller = gtools.NewModel(items...)
testModeller(t)
}

func TestModelVar(t *testing.T) {
modeller = gtools.NewModelVar(&items)
testModeller(t)
}

0 comments on commit 26a3ff9

Please sign in to comment.