Skip to content

Commit

Permalink
Test suite, code linting: rules 'contains, empty, formatter'
Browse files Browse the repository at this point in the history
  • Loading branch information
deining committed Jan 15, 2025
1 parent 974873f commit 1101fef
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 37 deletions.
9 changes: 4 additions & 5 deletions cmd/fyne/internal/commands/package-unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package commands

import (
"bytes"
"strings"
"testing"

"fyne.io/fyne/v2/cmd/fyne/internal/templates"
Expand All @@ -24,14 +23,14 @@ func TestDesktopFileSource(t *testing.T) {

err := templates.DesktopFileUNIX.Execute(buf, tplData)
require.NoError(t, err)
assert.False(t, strings.Contains(buf.String(), "[X-Fyne"))
assert.NotContains(t, buf.String(), "[X-Fyne")

tplData.SourceRepo = "https://example.com"
tplData.SourceDir = "cmd/name"

err = templates.DesktopFileUNIX.Execute(buf, tplData)
require.NoError(t, err)
assert.True(t, strings.Contains(buf.String(), "[X-Fyne"))
assert.True(t, strings.Contains(buf.String(), "Repo=https://example.com"))
assert.True(t, strings.Contains(buf.String(), "Dir=cmd/name"))
assert.Contains(t, buf.String(), "[X-Fyne")
assert.Contains(t, buf.String(), "Repo=https://example.com")
assert.Contains(t, buf.String(), "Dir=cmd/name")
}
4 changes: 2 additions & 2 deletions container/apptabs_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func Test_tabButtonRenderer_EmptyDeleteAdd(t *testing.T) {
tabs.Resize(fyne.NewSize(300, 200))

tabRenderer := cache.Renderer(tabs).(*appTabsRenderer)
assert.Len(t, tabRenderer.bar.Objects[0].(*fyne.Container).Objects, 0)
assert.Empty(t, tabRenderer.bar.Objects[0].(*fyne.Container).Objects)

tabs.Append(item1)
assert.Len(t, tabRenderer.bar.Objects[0].(*fyne.Container).Objects, 1)

tabs.Remove(item1)
assert.Len(t, tabRenderer.bar.Objects[0].(*fyne.Container).Objects, 0)
assert.Empty(t, tabRenderer.bar.Objects[0].(*fyne.Container).Objects)
}
4 changes: 2 additions & 2 deletions container/apptabs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ func TestAppTabs_SelectedIndex(t *testing.T) {

func TestAppTabs_Empty(t *testing.T) {
tabs := NewAppTabs()
assert.Len(t, tabs.Items, 0)
assert.Empty(t, tabs.Items)
assert.Equal(t, -1, tabs.SelectedIndex())
assert.Nil(t, tabs.Selected())
min := tabs.MinSize()
assert.Equal(t, float32(0), min.Width)
assert.Equal(t, theme.Padding(), min.Height)

tabs = &AppTabs{}
assert.Len(t, tabs.Items, 0)
assert.Empty(t, tabs.Items)
assert.Nil(t, tabs.Selected())
assert.NotNil(t, test.TempWidgetRenderer(t, tabs)) // doesn't crash
}
Expand Down
4 changes: 2 additions & 2 deletions container/doctabs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ func TestDocTabs_SelectedIndex(t *testing.T) {

func TestDocTabs_Empty(t *testing.T) {
tabs := container.NewDocTabs()
assert.Len(t, tabs.Items, 0)
assert.Empty(t, tabs.Items)
assert.Equal(t, -1, tabs.SelectedIndex())
assert.Nil(t, tabs.Selected())
min := tabs.MinSize()
assert.Equal(t, float32(0), min.Width)
assert.Equal(t, 4*theme.Padding()+theme.IconInlineSize(), min.Height)

tabs = &container.DocTabs{}
assert.Len(t, tabs.Items, 0)
assert.Empty(t, tabs.Items)
assert.Nil(t, tabs.Selected())
assert.NotNil(t, test.TempWidgetRenderer(t, tabs)) // doesn't crash
}
Expand Down
2 changes: 1 addition & 1 deletion container/layouts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestNewBorder_Nil(t *testing.T) {
b := NewBorder(nil, nil, nil, nil)
assert.Len(t, b.Objects, 0)
assert.Empty(t, b.Objects)
b = NewBorder(canvas.NewRectangle(color.Black), canvas.NewRectangle(color.Black), canvas.NewRectangle(color.Black), canvas.NewRectangle(color.Black))
assert.Len(t, b.Objects, 4)

Expand Down
2 changes: 1 addition & 1 deletion container/multiplewindows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestMultipleWindows_Add(t *testing.T) {
m := NewMultipleWindows()
assert.Zero(t, len(m.Windows))
assert.Empty(t, m.Windows)

m.Add(NewInnerWindow("1", widget.NewLabel("Inside")))
assert.Len(t, m.Windows, 1)
Expand Down
6 changes: 3 additions & 3 deletions data/binding/bindtrees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ func TestExternalFloatTree_Reload(t *testing.T) {

func TestNewStringTree(t *testing.T) {
f := NewStringTree()
assert.Len(t, f.ChildIDs(DataTreeRootID), 0)
assert.Empty(t, f.ChildIDs(DataTreeRootID))

_, err := f.GetValue("NaN")
require.Error(t, err)
}

func TestStringTree_Append(t *testing.T) {
f := NewStringTree()
assert.Len(t, f.ChildIDs(DataTreeRootID), 0)
assert.Empty(t, f.ChildIDs(DataTreeRootID))

f.Append(DataTreeRootID, "5", "five")
assert.Len(t, f.ChildIDs(DataTreeRootID), 1)
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestStringTree_Remove(t *testing.T) {

f.Remove("5")
assert.Len(t, f.ChildIDs(DataTreeRootID), 1)
assert.Len(t, f.ChildIDs("5"), 0)
assert.Empty(t, f.ChildIDs("5"))
}

func TestFloatTree_Set(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion data/binding/treebinding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestTreeBase_GetItem(t *testing.T) {

func TestListBase_IDs(t *testing.T) {
data := newSimpleTree()
assert.Len(t, data.ChildIDs(""), 0)
assert.Empty(t, data.ChildIDs(""))

data.appendItem(NewFloat(), "1", "")
assert.Len(t, data.ChildIDs(""), 1)
Expand Down
4 changes: 2 additions & 2 deletions internal/animation/animation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestGLDriver_StopAnimation(t *testing.T) {
}
run.Stop(a)
run.animationMutex.RLock()
assert.Zero(t, len(run.animations))
assert.Empty(t, run.animations)
run.animationMutex.RUnlock()
}

Expand Down Expand Up @@ -108,6 +108,6 @@ func TestGLDriver_StopAnimationImmediatelyAndInsideTick(t *testing.T) {
// animations stopped inside tick are really stopped in the next runner cycle
time.Sleep(time.Second/60 + 100*time.Millisecond)
run.animationMutex.RLock()
assert.Zero(t, len(run.animations))
assert.Empty(t, run.animations)
run.animationMutex.RUnlock()
}
10 changes: 5 additions & 5 deletions internal/cache/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func TestCacheClean(t *testing.T) {
tm.setTime(11, 22)
Clean(true)
assert.Len(t, svgs, 0)
assert.Equal(t, 0, renderers.Len())
assert.Len(t, canvases, 0)
assert.Empty(t, renderers)
assert.Empty(t, canvases)
assert.Equal(t, 40, destroyedRenderersCnt)
})

Expand All @@ -131,7 +131,7 @@ func TestCacheClean(t *testing.T) {
Clean(false)
assert.False(t, skippedCleanWithCanvasRefresh)
assert.Equal(t, tm.now, lastClean)
assert.Equal(t, 0, renderers.Len())
assert.Empty(t, renderers)
})
}

Expand Down Expand Up @@ -170,8 +170,8 @@ func TestCleanCanvas(t *testing.T) {
}

CleanCanvas(dcanvas2)
assert.Equal(t, 0, renderers.Len())
assert.Len(t, canvases, 0)
assert.Empty(t, renderers)
assert.Empty(t, canvases)
assert.Equal(t, 42, destroyedRenderersCnt)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cache/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestTextCacheGet(t *testing.T) {
ResetThemeCaches()
assert.Len(t, fontSizeCache, 0)
assert.Empty(t, fontSizeCache)

bound, base := GetFontMetrics("hi", 10, fyne.TextStyle{}, nil)
assert.True(t, bound.IsZero())
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/common/canvas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func TestCanvas_OverlayStack(t *testing.T) {
o.Remove(c)
assert.Equal(t, 2, len(o.List()))
o.Remove(a)
assert.Equal(t, 0, len(o.List()))
assert.Empty(t, o.List())
}

func deleteAt(c *fyne.Container, index int) {
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/glfw/window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ func TestWindow_TabWithModifierToTriggersShortcut(t *testing.T) {
w.keyPressed(nil, glfw.KeyTab, 0, glfw.Press, 0)
w.keyPressed(nil, glfw.KeyTab, 0, glfw.Release, 0)

assert.Equal(t, 0, len(content.capturedShortcuts))
assert.Empty(t, content.capturedShortcuts)

// Tab with ctrl or alt is not passed
w.keyPressed(nil, glfw.KeyTab, 0, glfw.Press, glfw.ModControl)
Expand Down
8 changes: 4 additions & 4 deletions internal/driver/mobile/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (

func TestMobileFilter(t *testing.T) {
f := mobileFilter(nil)
assert.Len(t, f.Extensions, 0)
assert.Len(t, f.MimeTypes, 0)
assert.Empty(t, f.Extensions)
assert.Empty(t, f.MimeTypes)

f = mobileFilter(storage.NewExtensionFileFilter([]string{".png"}))
assert.Len(t, f.Extensions, 1)
assert.Len(t, f.MimeTypes, 0)
assert.Empty(t, f.MimeTypes)

f = mobileFilter(storage.NewMimeTypeFileFilter([]string{"text/plain"}))
assert.Len(t, f.Extensions, 0)
assert.Empty(t, f.Extensions)
assert.Len(t, f.MimeTypes, 1)
}
2 changes: 1 addition & 1 deletion internal/repository/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestInMemoryRepositoryParsingWithEmptyList(t *testing.T) {

listing, err := storage.List(foo)
require.NoError(t, err)
assert.Len(t, listing, 0)
assert.Empty(t, listing)
}

func TestInMemoryRepositoryParsing(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions internal/svg/svg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"image/color"
"os"
"path/filepath"
"strings"
"testing"

"github.com/srwiley/oksvg"
Expand Down Expand Up @@ -170,7 +169,7 @@ func TestSVG_ReplaceFillColor(t *testing.T) {
t.Fatal(err)
}
assert.NotEqual(t, string(src), string(res))
assert.True(t, strings.Contains(string(res), "#ff0000"))
assert.Contains(t, string(res), "#ff0000")
}

func TestSVG_ReplaceFillColor_Ellipse(t *testing.T) {
Expand All @@ -192,7 +191,7 @@ func TestSVG_ReplaceFillColor_Ellipse(t *testing.T) {
t.Fatal(err)
}
assert.NotEqual(t, string(src), string(res))
assert.True(t, strings.Contains(string(res), "#ff0000"))
assert.Contains(t, string(res), "#ff0000")
}

func helperDrawSVG(t *testing.T, data []byte) image.Image {
Expand Down
3 changes: 1 addition & 2 deletions internal/test/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package test_test

import (
"bytes"
"fmt"
"image"
"image/color"
"image/draw"
Expand Down Expand Up @@ -66,7 +65,7 @@ func TestNewCheckedImage(t *testing.T) {
}
for y, xv := range expectedColorValues {
for x, v := range xv {
assert.Equal(t, color.NRGBA{R: v, G: v, B: v, A: 0xff}, img.At(x, y), fmt.Sprintf("color value at %d,%d", x, y))
assert.Equal(t, color.NRGBA{R: v, G: v, B: v, A: 0xff}, img.At(x, y), "color value at %d,%d", x, y)
}
}
}
Expand Down

0 comments on commit 1101fef

Please sign in to comment.