diff --git a/app/cloud_test.go b/app/cloud_test.go index 45b82f9eb0..7d0757ff3e 100644 --- a/app/cloud_test.go +++ b/app/cloud_test.go @@ -68,13 +68,13 @@ func TestFyneApp_transitionCloud_Storage(t *testing.T) { a.Storage().Create("nothere") l := a.Storage().List() - assert.Equal(t, 1, len(l)) + assert.Len(t, l, 1) p := &mockCloud{} a.SetCloudProvider(p) l = a.Storage().List() - assert.Equal(t, 0, len(l)) + assert.Empty(t, l) } type mockCloud struct { diff --git a/app/icon_cache_file_test.go b/app/icon_cache_file_test.go index 3a810a0eb7..165cf82294 100644 --- a/app/icon_cache_file_test.go +++ b/app/icon_cache_file_test.go @@ -27,8 +27,8 @@ func TestCachedIcon_PATH(t *testing.T) { } info, err := os.Stat(path) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "icon.png", info.Name()) - assert.Nil(t, err) + assert.NoError(t, err) } diff --git a/app/preferences_test.go b/app/preferences_test.go index 2a7e733cb0..63f6ce5e02 100644 --- a/app/preferences_test.go +++ b/app/preferences_test.go @@ -24,7 +24,7 @@ func TestPreferences_Remove(t *testing.T) { p.RemoveValue("keyString") err := p.saveToFile(p.storagePath()) - assert.Nil(t, err) + assert.NoError(t, err) // check it doesn't write values that were removed p = loadPreferences("dummy") @@ -49,7 +49,7 @@ func TestPreferences_Save(t *testing.T) { path := p.storagePath() defer os.Remove(path) err := p.saveToFile(path) - assert.Nil(t, err) + assert.NoError(t, err) expected, err := os.ReadFile(filepath.Join("testdata", "preferences.json")) if err != nil { @@ -64,7 +64,7 @@ func TestPreferences_Save(t *testing.T) { // check it reads the saved output p = loadPreferences("dummy") assert.Equal(t, "value", p.String("keyString")) - assert.Equal(t, 3, len(p.StringList("keyStringList"))) + assert.Len(t, p.StringList("keyStringList"), 3) } func TestPreferences_Save_OverwriteFast(t *testing.T) { @@ -96,9 +96,9 @@ func TestPreferences_Load(t *testing.T) { assert.Equal(t, []int{1, 2, 3}, p.IntList("keyIntList")) assert.Equal(t, 3.5, p.Float("keyFloat")) assert.Equal(t, []float64{1.1, 2.2, 3.3}, p.FloatList("keyFloatList")) - assert.Equal(t, true, p.Bool("keyBool")) + assert.True(t, p.Bool("keyBool")) assert.Equal(t, []bool{true, false, true}, p.BoolList("keyBoolList")) - assert.Equal(t, 0, len(p.StringList("keyEmptyList"))) + assert.Empty(t, p.StringList("keyEmptyList")) } func TestPreferences_EmptyLoad(t *testing.T) { diff --git a/app/settings_test.go b/app/settings_test.go index ade718653e..e393c282d2 100644 --- a/app/settings_test.go +++ b/app/settings_test.go @@ -106,7 +106,7 @@ func TestCustomTheme(t *testing.T) { set.SetTheme(ctheme) set.setupTheme() - assert.True(t, set.Theme() == ctheme) + assert.Equal(t, set.Theme(), ctheme) assert.Equal(t, internalapp.DefaultVariant(), set.ThemeVariant()) err := set.loadFromFile(filepath.Join("testdata", "light-theme.json")) @@ -114,7 +114,7 @@ func TestCustomTheme(t *testing.T) { t.Error(err) } set.setupTheme() - assert.True(t, set.Theme() == ctheme) + assert.Equal(t, set.Theme(), ctheme) assert.Equal(t, theme.VariantLight, set.ThemeVariant()) err = set.loadFromFile(filepath.Join("testdata", "dark-theme.json")) @@ -122,7 +122,7 @@ func TestCustomTheme(t *testing.T) { t.Error(err) } set.setupTheme() - assert.True(t, set.Theme() == ctheme) + assert.Equal(t, set.Theme(), ctheme) assert.Equal(t, theme.VariantDark, set.ThemeVariant()) err = os.Setenv("FYNE_THEME", "light") @@ -130,7 +130,7 @@ func TestCustomTheme(t *testing.T) { t.Error(err) } set.setupTheme() - assert.True(t, set.Theme() == ctheme) + assert.Equal(t, set.Theme(), ctheme) assert.Equal(t, theme.VariantLight, set.ThemeVariant()) err = os.Setenv("FYNE_THEME", "dark") @@ -138,7 +138,7 @@ func TestCustomTheme(t *testing.T) { t.Error(err) } set.setupTheme() - assert.True(t, set.Theme() == ctheme) + assert.Equal(t, set.Theme(), ctheme) assert.Equal(t, theme.VariantDark, set.ThemeVariant()) err = os.Setenv("FYNE_THEME", "") @@ -146,6 +146,6 @@ func TestCustomTheme(t *testing.T) { t.Error(err) } set.setupTheme() - assert.True(t, set.Theme() == ctheme) + assert.Equal(t, set.Theme(), ctheme) assert.Equal(t, theme.VariantDark, set.ThemeVariant()) } diff --git a/app/storage_test.go b/app/storage_test.go index 31651b7953..33eafab4a8 100644 --- a/app/storage_test.go +++ b/app/storage_test.go @@ -12,9 +12,9 @@ func TestStore_RootURI(t *testing.T) { d := makeStoreDocs(id, &store{a: a}) w, err := d.Create("test") - assert.Nil(t, err) + assert.NoError(t, err) err = w.Close() - assert.Nil(t, err) + assert.NoError(t, err) err = d.Remove("test") - assert.Nil(t, err) + assert.NoError(t, err) } diff --git a/canvas/base_internal_test.go b/canvas/base_internal_test.go index 324ffe8752..8a6f872a77 100644 --- a/canvas/base_internal_test.go +++ b/canvas/base_internal_test.go @@ -12,8 +12,8 @@ func TestBase_MinSize(t *testing.T) { base := &baseObject{} min := base.MinSize() - assert.True(t, min.Width > 0) - assert.True(t, min.Height > 0) + assert.Positive(t, min.Width) + assert.Positive(t, min.Height) } func TestBase_Move(t *testing.T) { diff --git a/canvas/circle_test.go b/canvas/circle_test.go index b03ce1d339..ccc38eada6 100644 --- a/canvas/circle_test.go +++ b/canvas/circle_test.go @@ -14,8 +14,8 @@ func TestCircle_MinSize(t *testing.T) { circle := canvas.NewCircle(color.Black) min := circle.MinSize() - assert.True(t, min.Width > 0) - assert.True(t, min.Height > 0) + assert.Positive(t, min.Width) + assert.Positive(t, min.Height) } func TestCircle_FillColor(t *testing.T) { @@ -44,9 +44,9 @@ func TestCircle_Move(t *testing.T) { circle.Resize(fyne.NewSize(50, 50)) start := fyne.Position{X: 0, Y: 0} - assert.True(t, circle.Position() == start) + assert.Equal(t, circle.Position(), start) target := fyne.Position{X: 10, Y: 75} circle.Move(target) - assert.True(t, circle.Position() == target) + assert.Equal(t, circle.Position(), target) } diff --git a/canvas/gradient_test.go b/canvas/gradient_test.go index 68dbf5bd42..933caf9787 100644 --- a/canvas/gradient_test.go +++ b/canvas/gradient_test.go @@ -1,7 +1,6 @@ package canvas_test import ( - "fmt" "image" "image/color" "image/draw" @@ -27,7 +26,7 @@ func TestNewHorizontalGradient(t *testing.T) { } for y, xv := range expectedAlphaValues { for x, v := range xv { - assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y)) + assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y) } } @@ -53,7 +52,7 @@ func TestNewHorizontalGradient_Flipped(t *testing.T) { } for y, xv := range expectedAlphaValues { for x, v := range xv { - assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y)) + assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y) } } @@ -78,7 +77,7 @@ func TestNewVerticalGradient(t *testing.T) { } for y, xv := range expectedAlphaValues { for x, v := range xv { - assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y)) + assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y) } } @@ -104,7 +103,7 @@ func TestNewVerticalGradient_Flipped(t *testing.T) { } for y, xv := range expectedAlphaValues { for x, v := range xv { - assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y)) + assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y) } } @@ -129,7 +128,7 @@ func TestNewLinearGradient_45(t *testing.T) { } for y, xv := range expectedAlphaValues { for x, v := range xv { - assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y)) + assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y) } } @@ -156,7 +155,7 @@ func TestNewLinearGradient_225(t *testing.T) { } for y, xv := range expectedAlphaValues { for x, v := range xv { - assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y)) + assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y) } } @@ -183,7 +182,7 @@ func TestNewLinearGradient_135(t *testing.T) { } for y, xv := range expectedAlphaValues { for x, v := range xv { - assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y)) + assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y) } } @@ -210,7 +209,7 @@ func TestNewLinearGradient_315(t *testing.T) { } for y, xv := range expectedAlphaValues { for x, v := range xv { - assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y)) + assert.Equal(t, color.NRGBA{0, 0, 0, v}, smallImg.At(x, y), "alpha value at %d,%d", x, y) } } @@ -238,7 +237,7 @@ func TestNewRadialGradient(t *testing.T) { } for y, xv := range expectedAlphaValues { for x, v := range xv { - assert.Equal(t, color.NRGBA{0, 0, 0, v}, imgOddDiameter.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y)) + assert.Equal(t, color.NRGBA{0, 0, 0, v}, imgOddDiameter.At(x, y), "alpha value at %d,%d", x, y) } } } @@ -255,7 +254,7 @@ func TestNewRadialGradient(t *testing.T) { } for y, xv := range expectedAlphaValues { for x, v := range xv { - assert.Equal(t, color.NRGBA{0, 0, 0, v}, imgEvenDiameter.At(x, y), fmt.Sprintf("alpha value at %d,%d", x, y)) + assert.Equal(t, color.NRGBA{0, 0, 0, v}, imgEvenDiameter.At(x, y), "alpha value at %d,%d", x, y) } } } diff --git a/canvas/image_test.go b/canvas/image_test.go index 6122a9d0a6..9b6d5c7b75 100644 --- a/canvas/image_test.go +++ b/canvas/image_test.go @@ -41,7 +41,7 @@ func TestNewImageFromReader(t *testing.T) { pwd, _ := os.Getwd() path := filepath.Join(filepath.Dir(pwd), "theme", "icons", "fyne.png") read, err := os.Open(path) - assert.Nil(t, err) + assert.NoError(t, err) defer read.Close() img := canvas.NewImageFromReader(read, "fyne.png") diff --git a/canvas/line_test.go b/canvas/line_test.go index edb7aa7327..8ded6aad3b 100644 --- a/canvas/line_test.go +++ b/canvas/line_test.go @@ -14,8 +14,8 @@ func TestLine_MinSize(t *testing.T) { line := canvas.NewLine(color.Black) min := line.MinSize() - assert.True(t, min.Width > 0) - assert.True(t, min.Height > 0) + assert.Positive(t, min.Width) + assert.Positive(t, min.Height) } func TestLine_Move(t *testing.T) { diff --git a/canvas/rectangle_test.go b/canvas/rectangle_test.go index e7125c1352..7c4994ec49 100644 --- a/canvas/rectangle_test.go +++ b/canvas/rectangle_test.go @@ -16,8 +16,8 @@ func TestRectangle_MinSize(t *testing.T) { rect := canvas.NewRectangle(color.Black) min := rect.MinSize() - assert.True(t, min.Width > 0) - assert.True(t, min.Height > 0) + assert.Positive(t, min.Width) + assert.Positive(t, min.Height) } func TestRectangle_FillColor(t *testing.T) { diff --git a/canvas/text_test.go b/canvas/text_test.go index 558e6f22c8..4bee9182e9 100644 --- a/canvas/text_test.go +++ b/canvas/text_test.go @@ -33,12 +33,12 @@ func TestText_MinSize(t *testing.T) { text := canvas.NewText("Test", color.NRGBA{0, 0, 0, 0xff}) min := text.MinSize() - assert.True(t, min.Width > 0) - assert.True(t, min.Height > 0) + assert.Positive(t, min.Width) + assert.Positive(t, min.Height) text = canvas.NewText("Test2", color.NRGBA{0, 0, 0, 0xff}) min2 := text.MinSize() - assert.True(t, min2.Width > min.Width) + assert.Greater(t, min2.Width, min.Width) } func TestText_MinSize_NoMultiLine(t *testing.T) { @@ -47,7 +47,7 @@ func TestText_MinSize_NoMultiLine(t *testing.T) { text = canvas.NewText("Bre\nak", color.NRGBA{0, 0, 0, 0xff}) min2 := text.MinSize() - assert.True(t, min2.Width > min.Width) + assert.Greater(t, min2.Width, min.Width) assert.True(t, min2.Height == min.Height) } diff --git a/container_test.go b/container_test.go index 0bd01e8de2..58f7ae56b5 100644 --- a/container_test.go +++ b/container_test.go @@ -10,22 +10,22 @@ import ( func TestContainer_Add(t *testing.T) { box := new(dummyObject) container := NewContainerWithLayout(new(customLayout)) - assert.Equal(t, 0, len(container.Objects)) + assert.Empty(t, container.Objects) assert.Equal(t, float32(10), container.MinSize().Width) assert.Equal(t, float32(0), container.MinSize().Height) container.Add(box) - assert.Equal(t, 1, len(container.Objects)) + assert.Len(t, container.Objects, 1) assert.Equal(t, float32(10), container.MinSize().Width) assert.Equal(t, float32(10), container.MinSize().Height) oldLength := len(container.Objects) container.Add(nil) - assert.Equal(t, oldLength, len(container.Objects)) + assert.Len(t, container.Objects, oldLength) box2 := new(dummyObject) container.Add(box2) - assert.Equal(t, 2, len(container.Objects)) + assert.Len(t, container.Objects, 2) assert.Equal(t, float32(10), container.MinSize().Width) assert.Equal(t, float32(20), container.MinSize().Height) assert.Equal(t, float32(0), box2.Position().X) @@ -95,12 +95,12 @@ func TestContainer_Remove(t *testing.T) { box1 := new(dummyObject) box2 := new(dummyObject) container := NewContainerWithLayout(new(customLayout), box1, box2) - assert.Equal(t, 2, len(container.Objects)) + assert.Len(t, container.Objects, 2) assert.Equal(t, float32(10), container.MinSize().Width) assert.Equal(t, float32(20), container.MinSize().Height) container.Remove(box1) - assert.Equal(t, 1, len(container.Objects)) + assert.Len(t, container.Objects, 1) assert.Equal(t, float32(10), container.MinSize().Width) assert.Equal(t, float32(10), container.MinSize().Height) assert.Equal(t, float32(0), box2.Position().X) @@ -125,7 +125,7 @@ func TestContainer_Remove_Race(t *testing.T) { }() } wg.Wait() - assert.Equal(t, 0, len(container.Objects)) + assert.Empty(t, container.Objects) } func TestContainer_Add_Race(t *testing.T) { @@ -139,17 +139,17 @@ func TestContainer_Add_Race(t *testing.T) { }() } wg.Wait() - assert.Equal(t, 100, len(container.Objects)) + assert.Len(t, container.Objects, 100) } func TestContainer_RemoveAll(t *testing.T) { box1 := new(dummyObject) box2 := new(dummyObject) container := NewContainerWithLayout(new(customLayout), box1, box2) - assert.Equal(t, 2, len(container.Objects)) + assert.Len(t, container.Objects, 2) container.RemoveAll() - assert.Equal(t, 0, len(container.Objects)) + assert.Empty(t, container.Objects) } func TestContainer_Show(t *testing.T) { diff --git a/dialog/color_test.go b/dialog/color_test.go index 7641c5d669..b74808d242 100644 --- a/dialog/color_test.go +++ b/dialog/color_test.go @@ -148,13 +148,13 @@ func Test_recent_color(t *testing.T) { t.Run("Empty", func(t *testing.T) { test.NewTempApp(t) colors := readRecentColors() - assert.Equal(t, 0, len(colors)) + assert.Empty(t, colors) }) t.Run("Single", func(t *testing.T) { test.NewTempApp(t) writeRecentColor("#ff0000") // Red colors := readRecentColors() - assert.Equal(t, 1, len(colors)) + assert.Len(t, colors, 1) assert.Equal(t, "#ff0000", colors[0]) }) t.Run("Order", func(t *testing.T) { @@ -164,7 +164,7 @@ func Test_recent_color(t *testing.T) { writeRecentColor("#00ff00") // Green writeRecentColor("#0000ff") // Blue colors := readRecentColors() - assert.Equal(t, 3, len(colors)) + assert.Len(t, colors, 3) assert.Equal(t, "#0000ff", colors[0]) assert.Equal(t, "#00ff00", colors[1]) assert.Equal(t, "#ff0000", colors[2]) @@ -177,7 +177,7 @@ func Test_recent_color(t *testing.T) { writeRecentColor("#0000ff") // Blue writeRecentColor("#ff0000") // Red again colors := readRecentColors() - assert.Equal(t, 3, len(colors)) + assert.Len(t, colors, 3) assert.Equal(t, "#ff0000", colors[0]) // Red assert.Equal(t, "#0000ff", colors[1]) // Blue assert.Equal(t, "#00ff00", colors[2]) // Green @@ -196,7 +196,7 @@ func Test_recent_color(t *testing.T) { writeRecentColor("#00ffff") // Cyan writeRecentColor("#ff00ff") // Magenta colors := readRecentColors() - assert.Equal(t, 7, len(colors)) + assert.Len(t, colors, 7) assert.Equal(t, "#ff00ff", colors[0]) // Magenta assert.Equal(t, "#00ffff", colors[1]) // Cyan assert.Equal(t, "#ffff00", colors[2]) // Yellow diff --git a/dialog/confirm_test.go b/dialog/confirm_test.go index a17839558d..4f7579f177 100644 --- a/dialog/confirm_test.go +++ b/dialog/confirm_test.go @@ -27,8 +27,8 @@ func TestDialog_ConfirmDoubleCallback(t *testing.T) { assert.False(t, cnf.win.Hidden) go test.Tap(cnf.dismiss) - assert.EqualValues(t, <-ch, 43) - assert.EqualValues(t, <-ch, 42) + assert.EqualValues(t, 43, <-ch) + assert.EqualValues(t, 42, <-ch) assert.True(t, cnf.win.Hidden) } @@ -44,7 +44,7 @@ func TestDialog_ConfirmCallbackOnlyOnClosed(t *testing.T) { assert.False(t, cnf.win.Hidden) go test.Tap(cnf.dismiss) - assert.EqualValues(t, <-ch, 43) + assert.EqualValues(t, 43, <-ch) assert.True(t, cnf.win.Hidden) } @@ -59,7 +59,7 @@ func TestDialog_ConfirmCallbackOnlyOnConfirm(t *testing.T) { assert.False(t, cnf.win.Hidden) go test.Tap(cnf.dismiss) - assert.EqualValues(t, <-ch, 42) + assert.EqualValues(t, 42, <-ch) assert.True(t, cnf.win.Hidden) } diff --git a/dialog/entry_test.go b/dialog/entry_test.go index d53e80fcdf..57089c478b 100644 --- a/dialog/entry_test.go +++ b/dialog/entry_test.go @@ -16,7 +16,7 @@ func TestEntryDialog_Confirm(t *testing.T) { test.Type(ed.entry, "123") test.Tap(ed.confirm) - assert.Equal(t, value, "123", "Control form should be confirmed with no validation") + assert.Equal(t, "123", value, "Control form should be confirmed with no validation") } func TestEntryDialog_Dismiss(t *testing.T) { @@ -28,5 +28,5 @@ func TestEntryDialog_Dismiss(t *testing.T) { test.Type(ed.entry, "XYZ") test.Tap(ed.cancel) - assert.Equal(t, value, "123", "Control form should not change value on dismiss") + assert.Equal(t, "123", value, "Control form should not change value on dismiss") } diff --git a/dialog/file_other_test.go b/dialog/file_other_test.go index c026a36917..bd124702a5 100644 --- a/dialog/file_other_test.go +++ b/dialog/file_other_test.go @@ -18,6 +18,6 @@ func TestFileDialog_LoadPlaces(t *testing.T) { f := &fileDialog{} places := f.getPlaces() - assert.Equal(t, 1, len(places)) + assert.Len(t, places, 1) assert.Equal(t, "Computer", places[0].locName) } diff --git a/dialog/file_test.go b/dialog/file_test.go index 434ebff9c8..0bb6f50987 100644 --- a/dialog/file_test.go +++ b/dialog/file_test.go @@ -220,9 +220,9 @@ func TestShowFileOpen(t *testing.T) { open := buttons.Objects[1].(*widget.Button) //body breadcrumb := ui.Objects[0].(*container.Split).Trailing.(*fyne.Container).Objects[0].(*container.Scroll).Content.(*fyne.Container).Objects[0].(*fyne.Container) - assert.Greater(t, len(breadcrumb.Objects), 0) + assert.NotEmpty(t, breadcrumb.Objects) - assert.Nil(t, err) + assert.NoError(t, err) components := strings.Split(testData.String()[7:], "/") if components[0] == "" { // Splitting a unix path will give a "" at the beginning, but we actually want the path bar to show "/". @@ -236,7 +236,7 @@ func TestShowFileOpen(t *testing.T) { files := ui.Objects[0].(*container.Split).Trailing.(*fyne.Container).Objects[1].(*container.Scroll).Content.(*fyne.Container).Objects[0].(*widget.GridWrap) objects := test.TempWidgetRenderer(t, files).Objects()[0].(*container.Scroll).Content.(*fyne.Container).Objects - assert.Greater(t, len(objects), 0) + assert.NotEmpty(t, objects) fileName := test.TempWidgetRenderer(t, objects[0].(fyne.Widget)).Objects()[1].(*fileDialogItem).name assert.Equal(t, "(Parent)", fileName) @@ -259,12 +259,12 @@ func TestShowFileOpen(t *testing.T) { test.Tap(open) assert.Nil(t, win.Canvas().Overlays().Top()) - assert.Nil(t, openErr) + assert.NoError(t, openErr) assert.Equal(t, target.location.String(), chosen.URI().String()) err = chosen.Close() - assert.Nil(t, err) + assert.NoError(t, err) } func TestHiddenFiles(t *testing.T) { @@ -305,7 +305,7 @@ func TestHiddenFiles(t *testing.T) { files := ui.Objects[0].(*container.Split).Trailing.(*fyne.Container).Objects[1].(*container.Scroll).Content.(*fyne.Container).Objects[0].(*widget.GridWrap) objects := test.TempWidgetRenderer(t, files).Objects()[0].(*container.Scroll).Content.(*fyne.Container).Objects - assert.Greater(t, len(objects), 0) + assert.NotEmpty(t, objects) var target *fileDialogItem for _, icon := range objects { @@ -352,7 +352,7 @@ func TestShowFileSave(t *testing.T) { files := ui.Objects[0].(*container.Split).Trailing.(*fyne.Container).Objects[1].(*container.Scroll).Content.(*fyne.Container).Objects[0].(*widget.GridWrap) objects := test.TempWidgetRenderer(t, files).Objects()[0].(*container.Scroll).Content.(*fyne.Container).Objects - assert.Greater(t, len(objects), 0) + assert.NotEmpty(t, objects) item := test.TempWidgetRenderer(t, objects[0].(fyne.Widget)).Objects()[1].(*fileDialogItem) assert.Equal(t, "(Parent)", item.name) @@ -392,7 +392,7 @@ func TestShowFileSave(t *testing.T) { test.Type(nameEntry, "v2_") test.Tap(save) assert.Nil(t, win.Canvas().Overlays().Top()) - assert.Nil(t, saveErr) + assert.NoError(t, saveErr) targetParent, err := storage.Parent(target.location) if err != nil { t.Error(err) @@ -401,10 +401,10 @@ func TestShowFileSave(t *testing.T) { assert.Equal(t, expectedPath.String(), chosen.URI().String()) err = chosen.Close() - assert.Nil(t, err) + assert.NoError(t, err) pathString := expectedPath.String()[len(expectedPath.Scheme())+3:] err = os.Remove(pathString) - assert.Nil(t, err) + assert.NoError(t, err) } func TestFileFilters(t *testing.T) { @@ -432,7 +432,7 @@ func TestFileFilters(t *testing.T) { for _, uri := range f.dialog.data { ok, _ := storage.CanList(uri) if !ok { - assert.Equal(t, uri.Extension(), ".png") + assert.Equal(t, ".png", uri.Extension()) count++ } } @@ -446,7 +446,7 @@ func TestFileFilters(t *testing.T) { for _, uri := range f.dialog.data { ok, _ := storage.CanList(uri) if !ok { - assert.Equal(t, uri.MimeType(), "image/jpeg") + assert.Equal(t, "image/jpeg", uri.MimeType()) count++ } } @@ -461,7 +461,7 @@ func TestFileFilters(t *testing.T) { ok, _ := storage.CanList(uri) if !ok { mimeType := strings.Split(uri.MimeType(), "/")[0] - assert.Equal(t, mimeType, "image") + assert.Equal(t, "image", mimeType) count++ } } @@ -474,7 +474,7 @@ func TestView(t *testing.T) { win := test.NewTempWindow(t, widget.NewLabel("Content")) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { - assert.Nil(t, err) + assert.NoError(t, err) assert.Nil(t, reader) }, win) @@ -536,7 +536,7 @@ func TestSetView(t *testing.T) { fyne.CurrentApp().Preferences().SetInt(viewLayoutKey, int(defaultView)) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { - assert.Nil(t, err) + assert.NoError(t, err) assert.Nil(t, reader) }, win) @@ -592,7 +592,7 @@ func TestSetViewPreferences(t *testing.T) { prefs.SetInt(viewLayoutKey, int(GridView)) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { - assert.Nil(t, err) + assert.NoError(t, err) assert.Nil(t, reader) }, win) @@ -626,7 +626,7 @@ func TestViewPreferences(t *testing.T) { prefs.SetInt(viewLayoutKey, -1) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { - assert.Nil(t, err) + assert.NoError(t, err) assert.Nil(t, reader) }, win) @@ -662,7 +662,7 @@ func TestFileFavorites(t *testing.T) { win := test.NewTempWindow(t, widget.NewLabel("Content")) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { - assert.Nil(t, err) + assert.NoError(t, err) assert.Nil(t, reader) }, win) @@ -680,7 +680,7 @@ func TestFileFavorites(t *testing.T) { assert.Len(t, dlg.dialog.favorites, len(favoriteLocations)+len(places)) favoritesList := ui.Objects[0].(*container.Split).Leading.(*widget.List) - assert.Equal(t, favoritesList.Length(), len(dlg.dialog.favorites)) + assert.Len(t, dlg.dialog.favorites, favoritesList.Length()) for i := 0; i < favoritesList.Length(); i++ { favoritesList.Select(i) @@ -696,7 +696,7 @@ func TestFileFavorites(t *testing.T) { } ok, err := storage.Exists(dlg.dialog.dir) - assert.Nil(t, err) + assert.NoError(t, err) assert.True(t, ok) } @@ -758,7 +758,7 @@ func TestCreateNewFolderInDir(t *testing.T) { win := test.NewTempWindow(t, widget.NewLabel("Content")) folderDialog := NewFolderOpen(func(lu fyne.ListableURI, err error) { - assert.Nil(t, err) + assert.NoError(t, err) }, win) folderDialog.SetConfirmText("Choose") folderDialog.SetDismissText("Cancel") diff --git a/dialog/file_xdg_test.go b/dialog/file_xdg_test.go index 1d7887e245..73fc8d038e 100644 --- a/dialog/file_xdg_test.go +++ b/dialog/file_xdg_test.go @@ -22,7 +22,7 @@ func TestFavoriteLocations(t *testing.T) { } homeDir, err := os.UserHomeDir() - assert.Nil(t, err) + assert.NoError(t, err) homeURI := storage.NewFileURI(homeDir) for name, subdir := range expected { diff --git a/dialog/fileitem_test.go b/dialog/fileitem_test.go index 6882ec05b2..1aa82df66c 100644 --- a/dialog/fileitem_test.go +++ b/dialog/fileitem_test.go @@ -118,11 +118,11 @@ func TestFileItem_Wrap(t *testing.T) { label := test.TempWidgetRenderer(t, item).(*fileItemRenderer).text assert.Equal(t, "filename", label.Text) texts := test.TempWidgetRenderer(t, label).Objects() - assert.Equal(t, 1, len(texts)) + assert.Len(t, texts, 1) item.setLocation(storage.NewFileURI("/path/to/averylongfilename.svg"), false, false) rich := test.TempWidgetRenderer(t, label).Objects()[0].(*widget.RichText) texts = test.TempWidgetRenderer(t, rich).Objects() - assert.Equal(t, 2, len(texts)) + assert.Len(t, texts, 2) assert.Equal(t, "averylon", texts[0].(*canvas.Text).Text) } diff --git a/dialog/folder_test.go b/dialog/folder_test.go index 7cbec1374e..7b94df0b63 100644 --- a/dialog/folder_test.go +++ b/dialog/folder_test.go @@ -42,7 +42,7 @@ func TestShowFolderOpen(t *testing.T) { open := buttons.Objects[1].(*widget.Button) files := ui.Objects[0].(*container.Split).Trailing.(*fyne.Container).Objects[1].(*container.Scroll).Content.(*fyne.Container).Objects[0].(*widget.GridWrap) - assert.Greater(t, len(d.dialog.data), 0) + assert.NotEmpty(t, d.dialog.data) item := test.TempWidgetRenderer(t, files).Objects()[0].(*container.Scroll).Content.(*fyne.Container).Objects[0] fileName := test.TempWidgetRenderer(t, item.(fyne.Widget)).Objects()[1].(*fileDialogItem).name @@ -68,7 +68,7 @@ func TestShowFolderOpen(t *testing.T) { test.Tap(open) assert.Nil(t, win.Canvas().Overlays().Top()) - assert.Nil(t, openErr) + assert.NoError(t, openErr) assert.Equal(t, (*target).String(), chosen.String()) } diff --git a/dialog/form_test.go b/dialog/form_test.go index 7d3503f8ef..8cdb72e7f4 100644 --- a/dialog/form_test.go +++ b/dialog/form_test.go @@ -138,14 +138,14 @@ func TestFormDialog_Submit(t *testing.T) { validatingEntry.SetText("cba") form.Submit() - assert.Equal(t, false, confirmed) - assert.Equal(t, false, form.win.Hidden) + assert.False(t, confirmed) + assert.False(t, form.win.Hidden) validatingEntry.SetText("abc") form.Submit() - assert.Equal(t, true, confirmed) - assert.Equal(t, true, form.win.Hidden) + assert.True(t, confirmed) + assert.True(t, form.win.Hidden) } func validatingFormDialog(result *formDialogResult, parent fyne.Window) *FormDialog { diff --git a/dialog/information_test.go b/dialog/information_test.go index 3adcf68028..8187ea3503 100644 --- a/dialog/information_test.go +++ b/dialog/information_test.go @@ -114,16 +114,13 @@ func TestDialog_ErrorCallback(t *testing.T) { func TestDialog_ErrorCapitalize(t *testing.T) { err := errors.New("here is an error msg") d := NewError(err, test.NewTempWindow(t, nil)) - assert.Equal(t, d.(*dialog).content.(*widget.Label).Text, - "Here is an error msg") + assert.Equal(t, "Here is an error msg", d.(*dialog).content.(*widget.Label).Text) err = errors.New("這是一條錯誤訊息") d = NewError(err, test.NewTempWindow(t, nil)) - assert.Equal(t, d.(*dialog).content.(*widget.Label).Text, - "這是一條錯誤訊息") + assert.Equal(t, "這是一條錯誤訊息", d.(*dialog).content.(*widget.Label).Text) err = errors.New("") d = NewError(err, test.NewTempWindow(t, nil)) - assert.Equal(t, d.(*dialog).content.(*widget.Label).Text, - "") + assert.Equal(t, "", d.(*dialog).content.(*widget.Label).Text) } diff --git a/internal/clip_test.go b/internal/clip_test.go index feafb9f6c5..bb0fb8b607 100644 --- a/internal/clip_test.go +++ b/internal/clip_test.go @@ -23,7 +23,7 @@ func TestClipStack_Intersect(t *testing.T) { assert.Equal(t, fyne.NewPos(25, 25), i.pos) assert.Equal(t, fyne.NewSize(50, 25), i.size) - assert.Equal(t, 2, len(c.clips)) + assert.Len(t, c.clips, 2) _ = c.Pop() p2 = fyne.NewPos(50, 50) @@ -32,7 +32,7 @@ func TestClipStack_Intersect(t *testing.T) { assert.Equal(t, fyne.NewPos(50, 50), i.pos) assert.Equal(t, fyne.NewSize(55, 50), i.size) - assert.Equal(t, 2, len(c.clips)) + assert.Len(t, c.clips, 2) } func TestClipStack_Pop(t *testing.T) { @@ -47,7 +47,7 @@ func TestClipStack_Pop(t *testing.T) { i := c.Pop() assert.Equal(t, p, i.pos) assert.Equal(t, s, i.size) - assert.Equal(t, 0, len(c.clips)) + assert.Empty(t, c.clips) } func TestClipStack_Push(t *testing.T) { @@ -58,5 +58,5 @@ func TestClipStack_Push(t *testing.T) { i := c.Push(p, s) assert.Equal(t, p, i.pos) assert.Equal(t, s, i.size) - assert.Equal(t, 1, len(c.clips)) + assert.Len(t, c.clips, 1) } diff --git a/internal/docs_test.go b/internal/docs_test.go index 7ca221269e..20b3c421ea 100644 --- a/internal/docs_test.go +++ b/internal/docs_test.go @@ -14,15 +14,15 @@ func TestDocs_Create(t *testing.T) { repository.Register("file", intRepo.NewInMemoryRepository("file")) docs := &Docs{storage.NewFileURI("/tmp/docs/create")} exist, err := storage.Exists(docs.RootDocURI) - assert.Nil(t, err) + assert.NoError(t, err) assert.False(t, exist) w, err := docs.Create("test") - assert.Nil(t, err) + assert.NoError(t, err) _ = w.Close() exist, err = storage.Exists(docs.RootDocURI) - assert.Nil(t, err) + assert.NoError(t, err) assert.True(t, exist) } @@ -30,11 +30,11 @@ func TestDocs_Create_ErrAlreadyExists(t *testing.T) { repository.Register("file", intRepo.NewInMemoryRepository("file")) docs := &Docs{storage.NewFileURI("/tmp/docs/create")} exist, err := storage.Exists(docs.RootDocURI) - assert.Nil(t, err) + assert.NoError(t, err) assert.False(t, exist) w, err := docs.Create("test") - assert.Nil(t, err) + assert.NoError(t, err) _, _ = w.Write([]byte{}) _ = w.Close() _, err = docs.Create("test") @@ -45,7 +45,7 @@ func TestDocs_List(t *testing.T) { repository.Register("file", intRepo.NewInMemoryRepository("file")) docs := &Docs{storage.NewFileURI("/tmp/docs/list")} list := docs.List() - assert.Zero(t, len(list)) + assert.Empty(t, list) w, _ := docs.Create("1") _, _ = w.Write([]byte{}) @@ -55,7 +55,7 @@ func TestDocs_List(t *testing.T) { _ = w.Close() list = docs.List() - assert.Equal(t, 2, len(list)) + assert.Len(t, list, 2) } func TestDocs_Save(t *testing.T) { @@ -63,22 +63,22 @@ func TestDocs_Save(t *testing.T) { repository.Register("file", r) docs := &Docs{storage.NewFileURI("/tmp/docs/save")} w, err := docs.Create("save.txt") - assert.Nil(t, err) + assert.NoError(t, err) _, _ = w.Write([]byte{}) _ = w.Close() u := w.URI() exist, err := r.Exists(u) - assert.Nil(t, err) + assert.NoError(t, err) assert.True(t, exist) w, err = docs.Save("save.txt") - assert.Nil(t, err) + assert.NoError(t, err) n, err := w.Write([]byte("save")) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, 4, n) err = w.Close() - assert.Nil(t, err) + assert.NoError(t, err) } func TestDocs_Save_ErrNotExists(t *testing.T) { diff --git a/internal/preferences_test.go b/internal/preferences_test.go index 968c2b8453..f98fad57b9 100644 --- a/internal/preferences_test.go +++ b/internal/preferences_test.go @@ -11,7 +11,7 @@ func TestPrefs_SetBool(t *testing.T) { p := NewInMemoryPreferences() p.SetBool("testBool", true) - assert.Equal(t, true, p.Bool("testBool")) + assert.True(t, p.Bool("testBool")) } func TestPrefs_Bool(t *testing.T) { @@ -20,10 +20,10 @@ func TestPrefs_Bool(t *testing.T) { val["testBool"] = true }) - assert.Equal(t, true, p.Bool("testBool")) + assert.True(t, p.Bool("testBool")) p.SetString("testBool", "fail") - assert.Equal(t, false, p.Bool("testBool")) + assert.False(t, p.Bool("testBool")) } func TestPrefs_BoolListWithFallback(t *testing.T) { @@ -40,7 +40,7 @@ func TestPrefs_BoolListWithFallback(t *testing.T) { func TestPrefs_BoolWithFallback(t *testing.T) { p := NewInMemoryPreferences() - assert.Equal(t, true, p.BoolWithFallback("testBool", true)) + assert.True(t, p.BoolWithFallback("testBool", true)) p.SetBool("testBool", false) assert.Equal(t, 1, p.IntWithFallback("testBool", 1)) p.SetString("testBool", "fail") @@ -50,7 +50,7 @@ func TestPrefs_BoolWithFallback(t *testing.T) { func TestPrefs_Bool_Zero(t *testing.T) { p := NewInMemoryPreferences() - assert.Equal(t, false, p.Bool("testBool")) + assert.False(t, p.Bool("testBool")) } func TestPrefs_SetFloat(t *testing.T) { @@ -114,7 +114,7 @@ func TestPrefs_IntWithFallback(t *testing.T) { }) assert.Equal(t, 5, p.IntWithFallback("testInt", 2)) - assert.Equal(t, true, p.BoolWithFallback("testInt", true)) + assert.True(t, p.BoolWithFallback("testInt", true)) assert.Equal(t, 5.0, p.FloatWithFallback("testInt", 1.2)) @@ -152,7 +152,7 @@ func TestPrefs_StringWithFallback(t *testing.T) { }) assert.Equal(t, "value", p.StringWithFallback("test", "default")) - assert.Equal(t, true, p.BoolWithFallback("test", true)) + assert.True(t, p.BoolWithFallback("test", true)) assert.Equal(t, "value", p.StringWithFallback("test", "default")) } @@ -193,7 +193,7 @@ func TestRemoveValue(t *testing.T) { p.RemoveValue("number") p.RemoveValue("month") - assert.Equal(t, false, p.Bool("dummy")) + assert.False(t, p.Bool("dummy")) assert.Equal(t, float64(0), p.Float("pi")) assert.Equal(t, 0, p.Int("number")) assert.Equal(t, "", p.String("month")) diff --git a/layout/borderlayout_test.go b/layout/borderlayout_test.go index f1ffc4f36d..83b785f135 100644 --- a/layout/borderlayout_test.go +++ b/layout/borderlayout_test.go @@ -22,7 +22,7 @@ func TestNewBorderContainer(t *testing.T) { middle := canvas.NewRectangle(color.NRGBA{0, 0, 0, 0}) c := container.NewBorder(top, nil, nil, right, middle) - assert.Equal(t, 3, len(c.Objects)) + assert.Len(t, c.Objects, 3) c.Resize(fyne.NewSize(100, 100)) assert.Equal(t, float32(0), top.Position().X) diff --git a/log_test.go b/log_test.go index f047ba8bc8..7078f970ee 100644 --- a/log_test.go +++ b/log_test.go @@ -32,17 +32,17 @@ func TestLogError(t *testing.T) { err := errors.New("dummy error") output := bufferLog(t, "Testing errors", err) - assert.Equal(t, 3, len(output)) - assert.True(t, strings.Contains(output[0], "Testing errors")) - assert.True(t, strings.Contains(output[1], "Cause")) - assert.True(t, strings.Contains(output[1], "dummy")) - assert.True(t, strings.Contains(output[2], "At")) + assert.Len(t, output, 3) + assert.Contains(t, output[0], "Testing errors") + assert.Contains(t, output[1], "Cause") + assert.Contains(t, output[1], "dummy") + assert.Contains(t, output[2], "At") } func TestLogErrorNoErr(t *testing.T) { output := bufferLog(t, "Testing errors", nil) - assert.Equal(t, 2, len(output)) - assert.True(t, strings.Contains(output[0], "Testing errors")) - assert.True(t, strings.Contains(output[1], "At")) + assert.Len(t, output, 2) + assert.Contains(t, output[0], "Testing errors") + assert.Contains(t, output[1], "At") } diff --git a/storage/filter_test.go b/storage/filter_test.go index 549d8a7657..b019906280 100644 --- a/storage/filter_test.go +++ b/storage/filter_test.go @@ -14,12 +14,12 @@ func TestFileFilter(t *testing.T) { filter := storage.NewExtensionFileFilter([]string{".jpg", ".png"}) assert.NotNil(t, filter) - assert.Equal(t, true, filter.Matches(storage.NewURI("content:///otherapp/something/pic.JPG"))) - assert.Equal(t, true, filter.Matches(storage.NewURI("content:///otherapp/something/pic.jpg"))) + assert.True(t, filter.Matches(storage.NewURI("content:///otherapp/something/pic.JPG"))) + assert.True(t, filter.Matches(storage.NewURI("content:///otherapp/something/pic.jpg"))) - assert.Equal(t, true, filter.Matches(storage.NewURI("content:///otherapp/something/pic.PNG"))) - assert.Equal(t, true, filter.Matches(storage.NewURI("content:///otherapp/something/pic.png"))) + assert.True(t, filter.Matches(storage.NewURI("content:///otherapp/something/pic.PNG"))) + assert.True(t, filter.Matches(storage.NewURI("content:///otherapp/something/pic.png"))) - assert.Equal(t, false, filter.Matches(storage.NewURI("content:///otherapp/something/pic.TIFF"))) - assert.Equal(t, false, filter.Matches(storage.NewURI("content:///otherapp/something/pic.tiff"))) + assert.False(t, filter.Matches(storage.NewURI("content:///otherapp/something/pic.TIFF"))) + assert.False(t, filter.Matches(storage.NewURI("content:///otherapp/something/pic.tiff"))) } diff --git a/storage/repository/generic_test.go b/storage/repository/generic_test.go index 32e87d83da..a23f3e30a8 100644 --- a/storage/repository/generic_test.go +++ b/storage/repository/generic_test.go @@ -21,7 +21,7 @@ func TestGenericParent(t *testing.T) { t.Logf("case %d, input='%s', expect='%s', err='%v'\n", i, c.input, c.expect, c.err) u, err := ParseURI(c.input) - assert.Nil(t, err) + assert.NoError(t, err) res, err := GenericParent(u) assert.Equal(t, c.err, err) @@ -51,7 +51,7 @@ func TestGenericChild(t *testing.T) { t.Logf("case %d, input='%s', component='%s', expect='%s', err='%v'\n", i, c.input, c.component, c.expect, c.err) u, err := ParseURI(c.input) - assert.Nil(t, err) + assert.NoError(t, err) res, err := GenericChild(u, c.component) assert.Equal(t, c.err, err) diff --git a/storage/repository/parse_test.go b/storage/repository/parse_test.go index 1eb2739781..4f8d3c5ba3 100644 --- a/storage/repository/parse_test.go +++ b/storage/repository/parse_test.go @@ -13,40 +13,40 @@ func TestNewFileURI(t *testing.T) { func TestParseURI(t *testing.T) { uri, err := ParseURI("file:///tmp/foo.txt") - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "file:///tmp/foo.txt", uri.String()) uri, err = ParseURI("file:/tmp/foo.txt") - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "file:///tmp/foo.txt", uri.String()) uri, err = ParseURI("file://C:/tmp/foo.txt") - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "file://C:/tmp/foo.txt", uri.String()) } func TestParseInvalidURI(t *testing.T) { uri, err := ParseURI("/tmp/foo.txt") - assert.NotNil(t, err) + assert.Error(t, err) assert.Nil(t, uri) uri, err = ParseURI("file") - assert.NotNil(t, err) + assert.Error(t, err) assert.Nil(t, uri) uri, err = ParseURI("file:") - assert.NotNil(t, err) + assert.Error(t, err) assert.Nil(t, uri) uri, err = ParseURI("file://") - assert.NotNil(t, err) + assert.Error(t, err) assert.Nil(t, uri) uri, err = ParseURI(":foo") - assert.NotNil(t, err) + assert.Error(t, err) assert.Nil(t, uri) uri, err = ParseURI("scheme://0[]/invalid") - assert.NotNil(t, err) + assert.Error(t, err) assert.Nil(t, uri) } diff --git a/storage/resource_test.go b/storage/resource_test.go index fc0b83d4af..30b045d1a7 100644 --- a/storage/resource_test.go +++ b/storage/resource_test.go @@ -10,11 +10,11 @@ import ( func TestLoadResourceFromURI(t *testing.T) { path := filepath.Join("testdata", "test.txt") abs, err := filepath.Abs(path) - assert.Nil(t, err) + assert.NoError(t, err) uri := NewFileURI(abs) res, err := LoadResourceFromURI(uri) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "test.txt", res.Name()) assert.Equal(t, []byte("Text content"), res.Content()) } diff --git a/storage/uri_test.go b/storage/uri_test.go index bae253fd00..56b027d1fe 100644 --- a/storage/uri_test.go +++ b/storage/uri_test.go @@ -19,13 +19,13 @@ func TestURIAuthority(t *testing.T) { // from IETF RFC 3986 s := "foo://example.com:8042/over/there?name=ferret#nose" u, err := storage.ParseURI(s) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "example.com:8042", u.Authority()) // from IETF RFC 3986 s = "urn:example:animal:ferret:nose" u, err = storage.ParseURI(s) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "", u.Authority()) } @@ -33,12 +33,12 @@ func TestURIPath(t *testing.T) { // from IETF RFC 3986 s := "foo://example.com:8042/over/there?name=ferret#nose" u, err := storage.ParseURI(s) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "/over/there", u.Path()) s = "foo:///over/there" u, err = storage.ParseURI(s) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "/over/there", u.Path()) // NOTE: if net/url supported RFC3986, this would pass @@ -50,7 +50,7 @@ func TestURIPath(t *testing.T) { // from IETF RFC 3986 s = "urn:example:animal:ferret:nose" u, err = storage.ParseURI(s) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "example:animal:ferret:nose", u.Path()) } @@ -58,13 +58,13 @@ func TestURIQuery(t *testing.T) { // from IETF RFC 3986 s := "foo://example.com:8042/over/there?name=ferret#nose" u, err := storage.ParseURI(s) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "name=ferret", u.Query()) // from IETF RFC 3986 s = "urn:example:animal:ferret:nose" u, err = storage.ParseURI(s) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "", u.Query()) } @@ -72,13 +72,13 @@ func TestURIFragment(t *testing.T) { // from IETF RFC 3986 s := "foo://example.com:8042/over/there?name=ferret#nose" u, err := storage.ParseURI(s) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "nose", u.Fragment()) // from IETF RFC 3986 s = "urn:example:animal:ferret:nose" u, err = storage.ParseURI(s) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "", u.Fragment()) } @@ -123,15 +123,15 @@ func TestURI_Parent(t *testing.T) { // directory parent, err := storage.Parent(storage.NewURI("file:///foo/bar/baz")) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "file:///foo/bar/", parent.String()) parent, err = storage.Parent(storage.NewFileURI("/foo/bar/baz/")) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "file:///foo/bar/", parent.String()) parent, err = storage.Parent(storage.NewURI("file://C:/foo/bar/baz/")) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "file://C:/foo/bar/", parent.String()) // TODO hook in an http/https handler @@ -162,7 +162,7 @@ func TestURI_Parent(t *testing.T) { assert.Equal(t, "file://C:/foo/bar/baz/", uri.String()) parent, err = storage.Parent(uri) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "file://C:/foo/bar/", parent.String()) } @@ -182,7 +182,7 @@ func TestURI_Parent(t *testing.T) { // Windows supports UNIX-style paths. /C:/ is also a valid path. parent, err = storage.Parent(storage.NewURI("file:///C:/")) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "file:///", parent.String()) } @@ -221,10 +221,10 @@ func TestExists(t *testing.T) { fooExpectedParent, _ := storage.ParseURI("uritest:///foo/bar") fooExists, err := storage.Exists(foo) assert.True(t, fooExists) - assert.Nil(t, err) + assert.NoError(t, err) fooParent, err := storage.Parent(foo) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, fooExpectedParent.String(), fooParent.String()) } @@ -265,27 +265,27 @@ func TestWriteAndDelete(t *testing.T) { // write some data and assert there are no errors fooWriter, err := storage.Writer(foo) - assert.Nil(t, err) + assert.NoError(t, err) assert.NotNil(t, fooWriter) barWriter, err := storage.Writer(bar) - assert.Nil(t, err) + assert.NoError(t, err) assert.NotNil(t, barWriter) bazWriter, err := storage.Writer(baz) - assert.Nil(t, err) + assert.NoError(t, err) assert.NotNil(t, bazWriter) n, err := fooWriter.Write([]byte{1, 2, 3, 4, 5}) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, 5, n) n, err = barWriter.Write([]byte{6, 7, 8, 9}) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, 4, n) n, err = bazWriter.Write([]byte{5, 4, 3, 2, 1, 0}) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, 6, n) fooWriter.Close() @@ -293,53 +293,53 @@ func TestWriteAndDelete(t *testing.T) { bazWriter.Close() bazAppender, err := storage.Appender(baz) - assert.Nil(t, err) + assert.NoError(t, err) n, err = bazAppender.Write([]byte{1, 2, 3, 4, 5}) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, 5, n) bazAppender.Close() // now make sure we can read the data back correctly fooReader, err := storage.Reader(foo) - assert.Nil(t, err) + assert.NoError(t, err) fooData, err := io.ReadAll(fooReader) assert.Equal(t, []byte{1, 2, 3, 4, 5}, fooData) - assert.Nil(t, err) + assert.NoError(t, err) barReader, err := storage.Reader(bar) - assert.Nil(t, err) + assert.NoError(t, err) barData, err := io.ReadAll(barReader) assert.Equal(t, []byte{6, 7, 8, 9}, barData) - assert.Nil(t, err) + assert.NoError(t, err) bazReader, err := storage.Reader(baz) - assert.Nil(t, err) + assert.NoError(t, err) bazData, err := io.ReadAll(bazReader) assert.Equal(t, []byte{5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5}, bazData) - assert.Nil(t, err) + assert.NoError(t, err) // now let's test deletion err = storage.Delete(foo) - assert.Nil(t, err) + assert.NoError(t, err) err = storage.Delete(bar) - assert.Nil(t, err) + assert.NoError(t, err) err = storage.Delete(baz) - assert.Nil(t, err) + assert.NoError(t, err) fooExists, err := storage.Exists(foo) assert.False(t, fooExists) - assert.Nil(t, err) + assert.NoError(t, err) barExists, err := storage.Exists(bar) assert.False(t, barExists) - assert.Nil(t, err) + assert.NoError(t, err) bazExists, err := storage.Exists(baz) assert.False(t, bazExists) - assert.Nil(t, err) + assert.NoError(t, err) } func TestCanWrite(t *testing.T) { @@ -356,15 +356,15 @@ func TestCanWrite(t *testing.T) { fooCanWrite, err := storage.CanWrite(foo) assert.True(t, fooCanWrite) - assert.Nil(t, err) + assert.NoError(t, err) barCanWrite, err := storage.CanWrite(bar) assert.True(t, barCanWrite) - assert.Nil(t, err) + assert.NoError(t, err) bazCanWrite, err := storage.CanWrite(baz) assert.True(t, bazCanWrite) - assert.Nil(t, err) + assert.NoError(t, err) } func TestCanRead(t *testing.T) { @@ -381,15 +381,15 @@ func TestCanRead(t *testing.T) { fooCanRead, err := storage.CanRead(foo) assert.True(t, fooCanRead) - assert.Nil(t, err) + assert.NoError(t, err) barCanRead, err := storage.CanRead(bar) assert.True(t, barCanRead) - assert.Nil(t, err) + assert.NoError(t, err) bazCanRead, err := storage.CanRead(baz) assert.False(t, bazCanRead) - assert.Nil(t, err) + assert.NoError(t, err) } func TestCopy(t *testing.T) { @@ -402,7 +402,7 @@ func TestCopy(t *testing.T) { bar, _ := storage.ParseURI("uritest:///bar") err := storage.Copy(foo, bar) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, m.Data["/foo"], m.Data["/bar"]) } @@ -417,12 +417,12 @@ func TestRepositoryMove(t *testing.T) { bar, _ := storage.ParseURI("uritest:///bar") err := storage.Move(foo, bar) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, []byte{1, 2, 3}, m.Data["/bar"]) exists, err := m.Exists(foo) - assert.Nil(t, err) + assert.NoError(t, err) assert.False(t, exists) } @@ -438,11 +438,11 @@ func TestRepositoryListing(t *testing.T) { foo, _ := storage.ParseURI("uritest:///foo") canList, err := storage.CanList(foo) - assert.Nil(t, err) + assert.NoError(t, err) assert.True(t, canList) listing, err := storage.List(foo) - assert.Nil(t, err) + assert.NoError(t, err) stringListing := []string{} for _, u := range listing { stringListing = append(stringListing, u.String()) @@ -458,13 +458,13 @@ func TestCreateListable(t *testing.T) { foo, _ := storage.ParseURI("uritest:///foo") err := storage.CreateListable(foo) - assert.Nil(t, err) + assert.NoError(t, err) - assert.Equal(t, m.Data["/foo"], []byte{}) + assert.Equal(t, []byte{}, m.Data["/foo"]) // trying to create something we already created should fail err = storage.CreateListable(foo) - assert.NotNil(t, err) + assert.Error(t, err) // NOTE: creating an InMemoryRepository path with a non-extant parent // is specifically not an error, so that case is not tested. diff --git a/test/canvas_test.go b/test/canvas_test.go index 84d9d34a55..873274599d 100644 --- a/test/canvas_test.go +++ b/test/canvas_test.go @@ -15,8 +15,8 @@ func Test_canvas_Capture(t *testing.T) { c.Size() img := c.Capture() - assert.True(t, img.Bounds().Size().X > 0) - assert.True(t, img.Bounds().Size().Y > 0) + assert.Positive(t, img.Bounds().Size().X) + assert.Positive(t, img.Bounds().Size().Y) r1, g1, b1, a1 := theme.Color(theme.ColorNameBackground).RGBA() r2, g2, b2, a2 := img.At(1, 1).RGBA() @@ -49,8 +49,8 @@ func Test_canvas_TransparentCapture(t *testing.T) { c.Size() img := c.Capture() - assert.True(t, img.Bounds().Size().X > 0) - assert.True(t, img.Bounds().Size().Y > 0) + assert.Positive(t, img.Bounds().Size().X) + assert.Positive(t, img.Bounds().Size().Y) r1, g1, b1, a1 := color.Transparent.RGBA() r2, g2, b2, a2 := img.At(1, 1).RGBA() diff --git a/test/test_test.go b/test/test_test.go index c4c515ab13..eb464ce796 100644 --- a/test/test_test.go +++ b/test/test_test.go @@ -70,7 +70,7 @@ func TestAssertRendersToImage(t *testing.T) { assert.False(t, test.AssertRendersToImage(tt, "non_existing_master.png", c), "non existing master is not equal to rendered image") assert.True(t, tt.Failed(), "test failed") _, err := os.Stat("testdata/failed/non_existing_master.png") - assert.Nil(t, err) + assert.NoError(t, err) }) t.Run("matching master", func(t *testing.T) { @@ -88,7 +88,7 @@ func TestAssertRendersToImage(t *testing.T) { assert.False(t, test.AssertRendersToImage(tt, "image_diffing_master.png", c), "existing master is not equal to rendered image") assert.True(t, tt.Failed(), "test should fail") _, err := os.Stat("testdata/failed/image_diffing_master.png") - assert.Nil(t, err) + assert.NoError(t, err) }) if !t.Failed() { diff --git a/theme/json_test.go b/theme/json_test.go index 1b071008bb..b97f640a7d 100644 --- a/theme/json_test.go +++ b/theme/json_test.go @@ -21,7 +21,7 @@ func TestFromJSON(t *testing.T) { "Icons": {"cancel": "file://./testdata/cancel_Paths.svg"} }`) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xc0, G: 0xc0, B: 0xc0, A: 0xff}, th.Color(ColorNameBackground, VariantDark)) assert.Equal(t, &color.NRGBA{R: 0xc0, G: 0xc0, B: 0xc0, A: 0xff}, th.Color(ColorNameBackground, VariantLight)) assert.Equal(t, &color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}, th.Color(ColorNameForeground, VariantLight)) @@ -36,10 +36,10 @@ func TestFromJSON(t *testing.T) { func TestFromTOML_Resource(t *testing.T) { r, err := fyne.LoadResourceFromPath("./testdata/theme.json") - assert.Nil(t, err) + assert.NoError(t, err) th, err := FromJSON(string(r.Content())) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0x30, G: 0x30, B: 0x30, A: 0xff}, th.Color(ColorNameBackground, VariantLight)) assert.Equal(t, &color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}, th.Color(ColorNameForeground, VariantDark)) assert.Equal(t, &color.NRGBA{R: 0xc0, G: 0xc0, B: 0xc0, A: 0xff}, th.Color(ColorNameForeground, VariantLight)) @@ -48,25 +48,25 @@ func TestFromTOML_Resource(t *testing.T) { func TestHexColor(t *testing.T) { c, err := hexColor("#abc").color() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xaa, G: 0xbb, B: 0xcc, A: 0xff}, c) c, err = hexColor("abc").color() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xaa, G: 0xbb, B: 0xcc, A: 0xff}, c) c, err = hexColor("#abcd").color() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xaa, G: 0xbb, B: 0xcc, A: 0xdd}, c) c, err = hexColor("#a1b2c3").color() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xa1, G: 0xb2, B: 0xc3, A: 0xff}, c) c, err = hexColor("a1b2c3").color() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xa1, G: 0xb2, B: 0xc3, A: 0xff}, c) c, err = hexColor("#a1b2c3f4").color() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xa1, G: 0xb2, B: 0xc3, A: 0xf4}, c) c, err = hexColor("a1b2c3f4").color() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, &color.NRGBA{R: 0xa1, G: 0xb2, B: 0xc3, A: 0xf4}, c) } diff --git a/tools/playground/playground_test.go b/tools/playground/playground_test.go index dab78a0ab2..612cc54515 100644 --- a/tools/playground/playground_test.go +++ b/tools/playground/playground_test.go @@ -22,10 +22,10 @@ func TestRender(t *testing.T) { assert.NotNil(t, img) enc, err := encodeImage(img) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAFElEQVR4nGJiwAtGpbECQAAAAP//DogAFaNSFa8AAAAASUVORK5CYII=", enc) bytes, err := base64.StdEncoding.DecodeString(enc) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "PNG", string(bytes)[1:4]) } diff --git a/widget/accordion_internal_test.go b/widget/accordion_internal_test.go index db83052ad7..d9c697f5a3 100644 --- a/widget/accordion_internal_test.go +++ b/widget/accordion_internal_test.go @@ -292,19 +292,19 @@ func TestAccordionRenderer_AddRemove(t *testing.T) { ac.Append(NewAccordionItem("foo1", NewLabel("foobar1"))) ac.Append(NewAccordionItem("foo2", NewLabel("foobar2"))) - assert.Equal(t, 3, len(ac.Items)) - assert.Equal(t, 3, len(ar.headers)) - assert.Equal(t, 2, len(ar.dividers)) + assert.Len(t, ac.Items, 3) + assert.Len(t, ar.headers, 3) + assert.Len(t, ar.dividers, 2) assert.True(t, ar.headers[2].Visible()) assert.True(t, ar.dividers[1].Visible()) ac.RemoveIndex(2) - assert.Equal(t, 2, len(ac.Items)) + assert.Len(t, ac.Items, 2) assert.False(t, ar.headers[2].Visible()) assert.False(t, ar.dividers[1].Visible()) ac.Append(NewAccordionItem("foo3", NewLabel("foobar3"))) - assert.Equal(t, 3, len(ac.Items)) + assert.Len(t, ac.Items, 3) assert.True(t, ar.headers[2].Visible()) assert.True(t, ar.dividers[1].Visible()) } diff --git a/widget/accordion_test.go b/widget/accordion_test.go index 5e90560df9..0d118de26e 100644 --- a/widget/accordion_test.go +++ b/widget/accordion_test.go @@ -17,18 +17,18 @@ func TestAccordion(t *testing.T) { ai := widget.NewAccordionItem("foo", widget.NewLabel("foobar")) t.Run("Initializer", func(t *testing.T) { ac := &widget.Accordion{Items: []*widget.AccordionItem{ai}} - assert.Equal(t, 1, len(ac.Items)) + assert.Len(t, ac.Items, 1) }) t.Run("Constructor", func(t *testing.T) { ac := widget.NewAccordion(ai) - assert.Equal(t, 1, len(ac.Items)) + assert.Len(t, ac.Items, 1) }) } func TestAccordion_Append(t *testing.T) { ac := widget.NewAccordion() ac.Append(widget.NewAccordionItem("foo", widget.NewLabel("foobar"))) - assert.Equal(t, 1, len(ac.Items)) + assert.Len(t, ac.Items, 1) } func TestAccordion_ChangeTheme(t *testing.T) { @@ -537,7 +537,7 @@ func TestAccordion_Remove(t *testing.T) { ai := widget.NewAccordionItem("foo", widget.NewLabel("foobar")) ac := widget.NewAccordion(ai) ac.Remove(ai) - assert.Equal(t, 0, len(ac.Items)) + assert.Empty(t, ac.Items) } func TestAccordion_RemoveIndex(t *testing.T) { @@ -553,7 +553,7 @@ func TestAccordion_RemoveIndex(t *testing.T) { ac := widget.NewAccordion() ac.Append(widget.NewAccordionItem("foo", widget.NewLabel("foobar"))) ac.RemoveIndex(tt.index) - assert.Equal(t, tt.length, len(ac.Items)) + assert.Len(t, ac.Items, tt.length) }) } } diff --git a/widget/bind_helper_test.go b/widget/bind_helper_test.go index 9143d069ed..8e1f585ce9 100644 --- a/widget/bind_helper_test.go +++ b/widget/bind_helper_test.go @@ -33,11 +33,11 @@ func TestBasicBinder(t *testing.T) { item2.Set(200) binder.Bind(item2) waitForBinding() - assert.Equal(t, value, 200) + assert.Equal(t, 200, value) item1.Set(300) waitForBinding() - assert.Equal(t, value, 200) + assert.Equal(t, 200, value) item2.Set(400) waitForBinding() - assert.Equal(t, value, 400) + assert.Equal(t, 400, value) } diff --git a/widget/button_internal_test.go b/widget/button_internal_test.go index 6c00cb25d0..a2c44afd2d 100644 --- a/widget/button_internal_test.go +++ b/widget/button_internal_test.go @@ -146,13 +146,13 @@ func TestButton_Focus(t *testing.T) { render.applyTheme() assert.Equal(t, theme.Color(theme.ColorNameButton), render.background.FillColor) - assert.Equal(t, false, tapped) + assert.False(t, tapped) button.FocusGained() render.Refresh() // force update without waiting assert.Equal(t, blendColor(theme.Color(theme.ColorNameButton), theme.Color(theme.ColorNameFocus)), render.background.FillColor) button.TypedKey(&fyne.KeyEvent{Name: fyne.KeySpace}) - assert.Equal(t, true, tapped) + assert.True(t, tapped) button.FocusLost() render.applyTheme() @@ -164,7 +164,7 @@ func TestButtonRenderer_Layout(t *testing.T) { render := test.TempWidgetRenderer(t, button).(*buttonRenderer) render.Layout(render.MinSize()) - assert.True(t, render.icon.Position().X < render.label.Position().X) + assert.Less(t, render.icon.Position().X, render.label.Position().X) assert.Equal(t, theme.InnerPadding(), render.icon.Position().X) assert.Equal(t, theme.InnerPadding(), render.MinSize().Width-render.label.Position().X-render.label.Size().Width) } diff --git a/widget/button_test.go b/widget/button_test.go index 0ee4d7c923..3ff075a97c 100644 --- a/widget/button_test.go +++ b/widget/button_test.go @@ -17,8 +17,8 @@ func TestButton_MinSize(t *testing.T) { button := widget.NewButton("Hi", nil) min := button.MinSize() - assert.True(t, min.Width > theme.InnerPadding()) - assert.True(t, min.Height > theme.InnerPadding()) + assert.Greater(t, min.Width, theme.InnerPadding()) + assert.Greater(t, min.Height, theme.InnerPadding()) } func TestButton_SetText(t *testing.T) { @@ -28,7 +28,7 @@ func TestButton_SetText(t *testing.T) { button.SetText("Longer") min2 := button.MinSize() - assert.True(t, min2.Width > min1.Width) + assert.Greater(t, min2.Width, min1.Width) assert.Equal(t, min2.Height, min1.Height) } @@ -39,7 +39,7 @@ func TestButton_MinSize_Icon(t *testing.T) { button.SetIcon(theme.CancelIcon()) min2 := button.MinSize() - assert.True(t, min2.Width > min1.Width) + assert.Greater(t, min2.Width, min1.Width) assert.Equal(t, min2.Height, min1.Height) } diff --git a/widget/card_test.go b/widget/card_test.go index f527813a6e..f2fd2edf55 100644 --- a/widget/card_test.go +++ b/widget/card_test.go @@ -16,20 +16,20 @@ import ( func TestCard_SetImage(t *testing.T) { c := widget.NewCard("Title", "sub", widget.NewLabel("Content")) r := test.TempWidgetRenderer(t, c) - assert.Equal(t, 4, len(r.Objects())) // the 3 above plus shadow + assert.Len(t, r.Objects(), 4) // the 3 above plus shadow c.SetImage(canvas.NewImageFromResource(theme.ComputerIcon())) - assert.Equal(t, 5, len(r.Objects())) + assert.Len(t, r.Objects(), 5) } func TestCard_SetContent(t *testing.T) { c := widget.NewCard("Title", "sub", widget.NewLabel("Content")) r := test.TempWidgetRenderer(t, c) - assert.Equal(t, 4, len(r.Objects())) // the 3 above plus shadow + assert.Len(t, r.Objects(), 4) // the 3 above plus shadow newContent := widget.NewLabel("New") c.SetContent(newContent) - assert.Equal(t, 4, len(r.Objects())) + assert.Len(t, r.Objects(), 4) assert.Equal(t, newContent, r.Objects()[3]) } diff --git a/widget/check_group_test.go b/widget/check_group_test.go index 584fde8572..f838d5b9f1 100644 --- a/widget/check_group_test.go +++ b/widget/check_group_test.go @@ -198,22 +198,22 @@ func TestCheckGroup_ToggleSelectionWithSpaceKey(t *testing.T) { func TestCheckGroup_ManipulateOptions(t *testing.T) { check := &widget.CheckGroup{Options: []string{}} - assert.Equal(t, 0, len(check.Options)) + assert.Empty(t, check.Options) check.Append("test1") - assert.Equal(t, 1, len(check.Options)) + assert.Len(t, check.Options, 1) check.SetSelected([]string{"test1"}) - assert.Equal(t, 1, len(check.Selected)) + assert.Len(t, check.Selected, 1) check.Append("test2") - assert.Equal(t, 2, len(check.Options)) + assert.Len(t, check.Options, 2) removed := check.Remove("nope") - assert.Equal(t, false, removed) - assert.Equal(t, 2, len(check.Options)) + assert.False(t, removed) + assert.Len(t, check.Options, 2) removed = check.Remove("test1") - assert.Equal(t, true, removed) - assert.Equal(t, 1, len(check.Options)) - assert.Equal(t, 0, len(check.Selected)) + assert.True(t, removed) + assert.Len(t, check.Options, 1) + assert.Empty(t, check.Selected) } diff --git a/widget/check_internal_test.go b/widget/check_internal_test.go index 7b18b835be..359232ea05 100644 --- a/widget/check_internal_test.go +++ b/widget/check_internal_test.go @@ -17,8 +17,8 @@ func TestCheckSize(t *testing.T) { check := NewCheck("Hi", nil) min := check.MinSize() - assert.True(t, min.Width > theme.InnerPadding()) - assert.True(t, min.Height > theme.InnerPadding()) + assert.Greater(t, min.Width, theme.InnerPadding()) + assert.Greater(t, min.Height, theme.InnerPadding()) } func TestCheckChecked(t *testing.T) { @@ -91,7 +91,7 @@ func TestCheckStateIsCorrectAfterMultipleUpdates(t *testing.T) { expectedCheckedState := false for i := 0; i < 5; i++ { check.SetChecked(expectedCheckedState) - assert.True(t, checkedStateFromCallback == expectedCheckedState) + assert.Equal(t, expectedCheckedState, checkedStateFromCallback) expectedCheckedState = !expectedCheckedState } diff --git a/widget/check_test.go b/widget/check_test.go index 374a362a5a..fa71d72c1b 100644 --- a/widget/check_test.go +++ b/widget/check_test.go @@ -15,26 +15,26 @@ import ( func TestCheck_Binding(t *testing.T) { c := widget.NewCheck("", nil) c.SetChecked(true) - assert.Equal(t, true, c.Checked) + assert.True(t, c.Checked) val := binding.NewBool() c.Bind(val) waitForBinding() - assert.Equal(t, false, c.Checked) + assert.False(t, c.Checked) err := val.Set(true) - assert.Nil(t, err) + assert.NoError(t, err) waitForBinding() - assert.Equal(t, true, c.Checked) + assert.True(t, c.Checked) c.SetChecked(false) v, err := val.Get() - assert.Nil(t, err) - assert.Equal(t, false, v) + assert.NoError(t, err) + assert.False(t, v) c.Unbind() waitForBinding() - assert.Equal(t, false, c.Checked) + assert.False(t, c.Checked) } func TestCheck_Layout(t *testing.T) { @@ -82,16 +82,16 @@ func TestCheck_Layout(t *testing.T) { func TestNewCheckWithData(t *testing.T) { val := binding.NewBool() err := val.Set(true) - assert.Nil(t, err) + assert.NoError(t, err) c := widget.NewCheckWithData("", val) waitForBinding() - assert.Equal(t, true, c.Checked) + assert.True(t, c.Checked) c.SetChecked(false) v, err := val.Get() - assert.Nil(t, err) - assert.Equal(t, false, v) + assert.NoError(t, err) + assert.False(t, v) } func TestCheck_SetText(t *testing.T) { diff --git a/widget/entry_internal_test.go b/widget/entry_internal_test.go index e5e27957fd..85024f2a71 100644 --- a/widget/entry_internal_test.go +++ b/widget/entry_internal_test.go @@ -367,7 +367,7 @@ func TestEntry_PasteFromClipboard_MultilineWrapping(t *testing.T) { entry.pasteFromClipboard(clipboard) - assert.Equal(t, entry.Text, "Testing entry") + assert.Equal(t, "Testing entry", entry.Text) assert.Equal(t, 1, entry.CursorRow) assert.Equal(t, 5, entry.CursorColumn) @@ -413,7 +413,7 @@ func TestEntry_Tab(t *testing.T) { _ = e.Theme() r := cache.Renderer(e.textProvider()).(*textRenderer) - assert.Equal(t, 3, len(r.Objects())) + assert.Len(t, r.Objects(), 3) assert.Equal(t, "a", r.Objects()[0].(*canvas.Text).Text) assert.Equal(t, "\tb", r.Objects()[1].(*canvas.Text).Text) diff --git a/widget/entry_test.go b/widget/entry_test.go index 1b11b34b93..0d7ba2c933 100644 --- a/widget/entry_test.go +++ b/widget/entry_test.go @@ -31,13 +31,13 @@ func TestEntry_Binding(t *testing.T) { assert.Equal(t, "", entry.Text) err := str.Set("Updated") - assert.Nil(t, err) + assert.NoError(t, err) waitForBinding() assert.Equal(t, "Updated", entry.Text) entry.SetText("Typed") v, err := str.Get() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "Typed", v) entry.Unbind() @@ -471,8 +471,8 @@ func TestEntry_MinSize(t *testing.T) { assert.Equal(t, entry.MinSize().Width, min.Width) assert.Equal(t, entry.MinSize().Height, min.Height) - assert.True(t, min.Width > theme.InnerPadding()) - assert.True(t, min.Height > theme.InnerPadding()) + assert.Greater(t, min.Width, theme.InnerPadding()) + assert.Greater(t, min.Height, theme.InnerPadding()) entry.Wrapping = fyne.TextWrapOff entry.Scroll = container.ScrollNone @@ -492,8 +492,8 @@ func TestEntryMultiline_MinSize(t *testing.T) { assert.Equal(t, entry.MinSize().Width, min.Width) assert.Equal(t, entry.MinSize().Height, min.Height) - assert.True(t, min.Width > theme.InnerPadding()) - assert.True(t, min.Height > theme.InnerPadding()) + assert.Greater(t, min.Width, theme.InnerPadding()) + assert.Greater(t, min.Height, theme.InnerPadding()) entry.Wrapping = fyne.TextWrapOff entry.Scroll = container.ScrollNone @@ -1390,14 +1390,14 @@ func TestEntry_SetPlaceHolder(t *testing.T) { entry, window := setupImageTest(t, false) c := window.Canvas() - assert.Equal(t, 0, len(entry.Text)) + assert.Empty(t, entry.Text) entry.SetPlaceHolder("Test") - assert.Equal(t, 0, len(entry.Text)) + assert.Empty(t, entry.Text) test.AssertRendersToMarkup(t, "entry/set_placeholder_set.xml", c) entry.SetText("Hi") - assert.Equal(t, 2, len(entry.Text)) + assert.Len(t, entry.Text, 2) test.AssertRendersToMarkup(t, "entry/set_placeholder_replaced.xml", c) } @@ -1405,15 +1405,15 @@ func TestEntry_SetPlaceHolder_ByField(t *testing.T) { entry, window := setupImageTest(t, false) c := window.Canvas() - assert.Equal(t, 0, len(entry.Text)) + assert.Empty(t, entry.Text) entry.PlaceHolder = "Test" entry.Refresh() - assert.Equal(t, 0, len(entry.Text)) + assert.Empty(t, entry.Text) test.AssertRendersToMarkup(t, "entry/set_placeholder_set.xml", c) entry.SetText("Hi") - assert.Equal(t, 2, len(entry.Text)) + assert.Len(t, entry.Text, 2) test.AssertRendersToMarkup(t, "entry/set_placeholder_replaced.xml", c) } @@ -1553,16 +1553,16 @@ func TestEntry_Append(t *testing.T) { entry := widget.NewEntry() entry.Append("abc") - assert.Equal(t, entry.Text, "abc") + assert.Equal(t, "abc", entry.Text) entry.Append(" def") - assert.Equal(t, entry.Text, "abc def") + assert.Equal(t, "abc def", entry.Text) entry.SetText("") entry.MultiLine = true entry.Append("first line") entry.Append("\nsecond line") - assert.Equal(t, entry.Text, "first line\nsecond line") + assert.Equal(t, "first line\nsecond line", entry.Text) } func TestEntry_Submit(t *testing.T) { @@ -1677,13 +1677,13 @@ func TestEntry_TappedSecondary(t *testing.T) { tapPos := fyne.NewPos(20, 10) test.TapSecondaryAt(entry, tapPos) test.AssertRendersToMarkup(t, "entry/tapped_secondary_full_menu.xml", c) - assert.Equal(t, 1, len(c.Overlays().List())) + assert.Len(t, c.Overlays().List(), 1) c.Overlays().Remove(c.Overlays().Top()) entry.Disable() test.TapSecondaryAt(entry, tapPos) test.AssertRendersToMarkup(t, "entry/tapped_secondary_read_menu.xml", c) - assert.Equal(t, 1, len(c.Overlays().List())) + assert.Len(t, c.Overlays().List(), 1) c.Overlays().Remove(c.Overlays().Top()) entry.Password = true @@ -1695,7 +1695,7 @@ func TestEntry_TappedSecondary(t *testing.T) { entry.Enable() test.TapSecondaryAt(entry, tapPos) test.AssertRendersToMarkup(t, "entry/tapped_secondary_password_menu.xml", c) - assert.Equal(t, 1, len(c.Overlays().List())) + assert.Len(t, c.Overlays().List(), 1) } func TestEntry_TextWrap(t *testing.T) { @@ -1794,7 +1794,7 @@ func TestMultiLineEntry_MinSize(t *testing.T) { multiMin := multi.MinSize() assert.Equal(t, singleMin.Width, multiMin.Width) - assert.True(t, multiMin.Height > singleMin.Height) + assert.Greater(t, multiMin.Height, singleMin.Height) multi.MultiLine = false multi.Refresh() @@ -1805,7 +1805,7 @@ func TestMultiLineEntry_MinSize(t *testing.T) { func TestNewEntryWithData(t *testing.T) { str := binding.NewString() err := str.Set("Init") - assert.Nil(t, err) + assert.NoError(t, err) entry := widget.NewEntryWithData(str) waitForBinding() @@ -1813,7 +1813,7 @@ func TestNewEntryWithData(t *testing.T) { entry.SetText("Typed") v, err := str.Get() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "Typed", v) } @@ -1960,7 +1960,7 @@ func TestSingleLineEntry_SelectionSubmitted(t *testing.T) { entry.TypedShortcut(&fyne.ShortcutSelectAll{}) assert.Equal(t, "abc", entry.SelectedText()) entry.TypedKey(&fyne.KeyEvent{Name: fyne.KeyEnter}) - assert.Equal(t, entry.Text, "abc") + assert.Equal(t, "abc", entry.Text) } func TestMultiLineEntry_EnterWithSelection(t *testing.T) { @@ -1970,7 +1970,7 @@ func TestMultiLineEntry_EnterWithSelection(t *testing.T) { entry.TypedShortcut(&fyne.ShortcutSelectAll{}) assert.Equal(t, "abc", entry.SelectedText()) entry.TypedKey(&fyne.KeyEvent{Name: fyne.KeyEnter}) - assert.Equal(t, entry.Text, "\n") + assert.Equal(t, "\n", entry.Text) } func TestEntry_CarriageReturn(t *testing.T) { diff --git a/widget/form_extend_test.go b/widget/form_extend_test.go index 7cc8a53cdb..0220ea659b 100644 --- a/widget/form_extend_test.go +++ b/widget/form_extend_test.go @@ -17,23 +17,23 @@ func TestForm_Extended_CreateRenderer(t *testing.T) { form.ExtendBaseWidget(form) form.Items = []*FormItem{{Text: "test1", Widget: NewEntry()}} assert.NotNil(t, test.TempWidgetRenderer(t, form)) - assert.Equal(t, 2, len(form.itemGrid.Objects)) + assert.Len(t, form.itemGrid.Objects, 2) form.Append("test2", NewEntry()) - assert.Equal(t, 4, len(form.itemGrid.Objects)) + assert.Len(t, form.itemGrid.Objects, 4) } func TestForm_Extended_Append(t *testing.T) { form := &extendedForm{} form.ExtendBaseWidget(form) form.Items = []*FormItem{{Text: "test1", Widget: NewEntry()}} - assert.Equal(t, 1, len(form.Items)) + assert.Len(t, form.Items, 1) form.Append("test2", NewEntry()) - assert.True(t, len(form.Items) == 2) + assert.Len(t, form.Items, 2) item := &FormItem{Text: "test3", Widget: NewEntry()} form.AppendItem(item) - assert.True(t, len(form.Items) == 3) + assert.Len(t, form.Items, 3) assert.Equal(t, item, form.Items[2]) } diff --git a/widget/form_test.go b/widget/form_test.go index c79742ba6c..c58d93a311 100644 --- a/widget/form_test.go +++ b/widget/form_test.go @@ -19,38 +19,38 @@ func TestFormSize(t *testing.T) { {Text: "test2", Widget: NewEntry()}, }} - assert.Equal(t, 2, len(form.Items)) + assert.Len(t, form.Items, 2) } func TestForm_CreateRenderer(t *testing.T) { form := &Form{Items: []*FormItem{{Text: "test1", Widget: NewEntry()}}} assert.NotNil(t, test.TempWidgetRenderer(t, form)) - assert.Equal(t, 2, len(form.itemGrid.Objects)) + assert.Len(t, form.itemGrid.Objects, 2) form.Append("test2", NewEntry()) - assert.Equal(t, 4, len(form.itemGrid.Objects)) + assert.Len(t, form.itemGrid.Objects, 4) } func TestForm_Append(t *testing.T) { form := &Form{Items: []*FormItem{{Text: "test1", Widget: NewEntry()}}} - assert.Equal(t, 1, len(form.Items)) + assert.Len(t, form.Items, 1) form.Append("test2", NewEntry()) - assert.True(t, len(form.Items) == 2) + assert.Len(t, form.Items, 2) item := &FormItem{Text: "test3", Widget: NewEntry()} form.AppendItem(item) - assert.True(t, len(form.Items) == 3) + assert.Len(t, form.Items, 3) assert.Equal(t, item, form.Items[2]) } func TestForm_Append_Items(t *testing.T) { form := &Form{Items: []*FormItem{{Text: "test1", Widget: NewEntry()}}} - assert.Equal(t, 1, len(form.Items)) + assert.Len(t, form.Items, 1) renderer := test.TempWidgetRenderer(t, form) form.Items = append(form.Items, NewFormItem("test2", NewEntry())) - assert.True(t, len(form.Items) == 2) + assert.Len(t, form.Items, 2) form.Refresh() c := renderer.Objects()[0].(*fyne.Container).Objects[0].(*fyne.Container) diff --git a/widget/gridwrap_test.go b/widget/gridwrap_test.go index 91da46ccef..ec36f50d24 100644 --- a/widget/gridwrap_test.go +++ b/widget/gridwrap_test.go @@ -121,9 +121,9 @@ func TestGridWrap_ScrollToOffset(t *testing.T) { func TestGridWrap_ScrollToTop(t *testing.T) { g := createGridWrap(1000) g.ScrollTo(750) - assert.NotEqual(t, g.offsetY, float32(0)) + assert.NotEqual(t, float32(0), g.offsetY) g.ScrollToTop() - assert.Equal(t, g.offsetY, float32(0)) + assert.Equal(t, float32(0), g.offsetY) } func createGridWrap(items int) *GridWrap { @@ -202,13 +202,13 @@ func TestGridWrap_RefreshItem(t *testing.T) { list.RefreshItem(2) children := list.scroller.Content.(*fyne.Container).Objects - assert.Equal(t, children[1].(*gridWrapItem).child.(*Label).Text, "Text") - assert.Equal(t, children[2].(*gridWrapItem).child.(*Label).Text, "Replace") + assert.Equal(t, "Text", children[1].(*gridWrapItem).child.(*Label).Text) + assert.Equal(t, "Replace", children[2].(*gridWrapItem).child.(*Label).Text) } func TestGridWrap_Selection(t *testing.T) { g := createGridWrap(10) - assert.Zero(t, len(g.selected)) + assert.Empty(t, g.selected) selected := -1 unselected := -1 @@ -223,22 +223,22 @@ func TestGridWrap_Selection(t *testing.T) { } g.Select(0) - assert.Equal(t, 1, len(g.selected)) + assert.Len(t, g.selected, 1) assert.Zero(t, selected) assert.Equal(t, -1, unselected) g.UnselectAll() - assert.Zero(t, len(g.selected)) + assert.Empty(t, g.selected) assert.Equal(t, -1, selected) assert.Zero(t, unselected) g.Select(9) - assert.Equal(t, 1, len(g.selected)) + assert.Len(t, g.selected, 1) assert.Equal(t, 9, selected) assert.Equal(t, -1, unselected) g.Unselect(9) - assert.Zero(t, len(g.selected)) + assert.Empty(t, g.selected) assert.Equal(t, -1, selected) assert.Equal(t, 9, unselected) } diff --git a/widget/hyperlink_test.go b/widget/hyperlink_test.go index 164d51db63..4e099ec008 100644 --- a/widget/hyperlink_test.go +++ b/widget/hyperlink_test.go @@ -20,7 +20,7 @@ import ( func TestHyperlink_MinSize(t *testing.T) { u, err := url.Parse("https://fyne.io/") - assert.Nil(t, err) + assert.NoError(t, err) hyperlink := NewHyperlink("Test", u) hyperlink.CreateRenderer() @@ -43,7 +43,7 @@ func TestHyperlink_Cursor(t *testing.T) { u, err := url.Parse("https://fyne.io/") hyperlink := NewHyperlink("Test", u) - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, desktop.DefaultCursor, hyperlink.Cursor()) hyperlink.hovered = true @@ -139,7 +139,7 @@ func TestHyperlink_Resize(t *testing.T) { func TestHyperlink_SetText(t *testing.T) { u, err := url.Parse("https://fyne.io/") - assert.Nil(t, err) + assert.NoError(t, err) hyperlink := &Hyperlink{Text: "Test", URL: u} hyperlink.CreateRenderer() @@ -151,7 +151,7 @@ func TestHyperlink_SetText(t *testing.T) { func TestHyperlink_SetUrl(t *testing.T) { sURL, err := url.Parse("https://github.com/fyne-io/fyne") - assert.Nil(t, err) + assert.NoError(t, err) // test constructor hyperlink := NewHyperlink("Test", sURL) @@ -159,7 +159,7 @@ func TestHyperlink_SetUrl(t *testing.T) { // test setting functions sURL, err = url.Parse("https://fyne.io") - assert.Nil(t, err) + assert.NoError(t, err) hyperlink.SetURL(sURL) assert.Equal(t, sURL, hyperlink.URL) } diff --git a/widget/icon_extend_test.go b/widget/icon_extend_test.go index e4c86c51c6..dc94f6c8a7 100644 --- a/widget/icon_extend_test.go +++ b/widget/icon_extend_test.go @@ -24,6 +24,6 @@ func TestIcon_Extended_SetResource(t *testing.T) { icon.SetResource(theme.ComputerIcon()) objs := cache.Renderer(icon).Objects() - assert.Equal(t, 1, len(objs)) + assert.Len(t, objs, 1) assert.Equal(t, theme.ComputerIcon(), objs[0].(*canvas.Image).Resource) } diff --git a/widget/icon_internal_test.go b/widget/icon_internal_test.go index 3156870d9b..5b6e9878ae 100644 --- a/widget/icon_internal_test.go +++ b/widget/icon_internal_test.go @@ -13,7 +13,7 @@ func TestNewIcon(t *testing.T) { icon := NewIcon(theme.ConfirmIcon()) render := test.TempWidgetRenderer(t, icon) - assert.Equal(t, 1, len(render.Objects())) + assert.Len(t, render.Objects(), 1) obj := render.Objects()[0] img, ok := obj.(*canvas.Image) if !ok { @@ -26,7 +26,7 @@ func TestIcon_Nil(t *testing.T) { icon := NewIcon(nil) render := test.TempWidgetRenderer(t, icon) - assert.Equal(t, 1, len(render.Objects())) + assert.Len(t, render.Objects(), 1) assert.Nil(t, render.Objects()[0].(*canvas.Image).Resource) } diff --git a/widget/label_extend_test.go b/widget/label_extend_test.go index a0c4b26e44..b4836d8c66 100644 --- a/widget/label_extend_test.go +++ b/widget/label_extend_test.go @@ -24,7 +24,7 @@ func TestLabel_Extended_SetText(t *testing.T) { label := newExtendedLabel("Start") rich := cache.Renderer(label).Objects()[0].(*RichText) objs := cache.Renderer(rich).Objects() - assert.Equal(t, 1, len(objs)) + assert.Len(t, objs, 1) assert.Equal(t, "Start", objs[0].(*canvas.Text).Text) label.SetText("Replace") diff --git a/widget/label_test.go b/widget/label_test.go index 860fed9cad..02c77810a2 100644 --- a/widget/label_test.go +++ b/widget/label_test.go @@ -130,13 +130,13 @@ func TestText_MinSize_MultiLine(t *testing.T) { rich := test.TempWidgetRenderer(t, textMultiLine).Objects()[0].(*RichText) min2 := textMultiLine.MinSize() - assert.True(t, min2.Width < min.Width) - assert.True(t, min2.Height > min.Height) + assert.Less(t, min2.Width, min.Width) + assert.Greater(t, min2.Height, min.Height) yPos := float32(-1) for _, text := range test.TempWidgetRenderer(t, rich).(*textRenderer).Objects() { - assert.True(t, text.Size().Height < min2.Height) - assert.True(t, text.Position().Y > yPos) + assert.Less(t, text.Size().Height, min2.Height) + assert.Greater(t, text.Position().Y, yPos) yPos = text.Position().Y } } diff --git a/widget/list_internal_test.go b/widget/list_internal_test.go index 1361093010..ba83c29126 100644 --- a/widget/list_internal_test.go +++ b/widget/list_internal_test.go @@ -267,12 +267,12 @@ func TestList_Selection(t *testing.T) { children[0].(*listItem).Tapped(&fyne.PointEvent{}) assert.Equal(t, children[0].(*listItem).background.FillColor, theme.Color(theme.ColorNameSelection)) assert.True(t, children[0].(*listItem).background.Visible()) - assert.Equal(t, 1, len(list.selected)) + assert.Len(t, list.selected, 1) assert.Equal(t, 0, list.selected[0]) children[1].(*listItem).Tapped(&fyne.PointEvent{}) assert.Equal(t, children[1].(*listItem).background.FillColor, theme.Color(theme.ColorNameSelection)) assert.True(t, children[1].(*listItem).background.Visible()) - assert.Equal(t, 1, len(list.selected)) + assert.Len(t, list.selected, 1) assert.Equal(t, 1, list.selected[0]) assert.False(t, children[0].(*listItem).background.Visible()) @@ -335,7 +335,7 @@ func TestList_Unselect(t *testing.T) { unselected = -1 list.Select(11) list.Unselect(9) - assert.Equal(t, 1, len(list.selected)) + assert.Len(t, list.selected, 1) assert.Equal(t, -1, unselected) list.UnselectAll() @@ -349,11 +349,11 @@ func TestList_DataChange(t *testing.T) { list, w := setupList(t) children := list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children - assert.Equal(t, children[0].(*listItem).child.(*fyne.Container).Objects[1].(*Label).Text, "Test Item 0") + assert.Equal(t, "Test Item 0", children[0].(*listItem).child.(*fyne.Container).Objects[1].(*Label).Text) changeData(list) list.Refresh() children = list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children - assert.Equal(t, children[0].(*listItem).child.(*fyne.Container).Objects[1].(*Label).Text, "a") + assert.Equal(t, "a", children[0].(*listItem).child.(*fyne.Container).Objects[1].(*Label).Text) test.AssertRendersToMarkup(t, "list/new_data.xml", w.Canvas()) } @@ -362,11 +362,11 @@ func TestList_ItemDataChange(t *testing.T) { list, _ := setupList(t) children := list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children - assert.Equal(t, children[0].(*listItem).child.(*fyne.Container).Objects[1].(*Label).Text, "Test Item 0") + assert.Equal(t, "Test Item 0", children[0].(*listItem).child.(*fyne.Container).Objects[1].(*Label).Text) changeData(list) list.RefreshItem(0) children = list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children - assert.Equal(t, children[0].(*listItem).child.(*fyne.Container).Objects[1].(*Label).Text, "a") + assert.Equal(t, "a", children[0].(*listItem).child.(*fyne.Container).Objects[1].(*Label).Text) } func TestList_SmallList(t *testing.T) { @@ -393,13 +393,13 @@ func TestList_SmallList(t *testing.T) { w.Resize(fyne.NewSize(200, 400)) visibleCount := len(list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children) - assert.Equal(t, visibleCount, 1) + assert.Equal(t, 1, visibleCount) data = append(data, "Test Item 1") list.Refresh() visibleCount = len(list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children) - assert.Equal(t, visibleCount, 2) + assert.Equal(t, 2, visibleCount) test.AssertRendersToMarkup(t, "list/small.xml", w.Canvas()) } @@ -443,13 +443,13 @@ func TestList_RemoveItem(t *testing.T) { w.Resize(fyne.NewSize(200, 400)) visibleCount := len(list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children) - assert.Equal(t, visibleCount, 3) + assert.Equal(t, 3, visibleCount) data = data[:len(data)-1] list.Refresh() visibleCount = len(list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children) - assert.Equal(t, visibleCount, 2) + assert.Equal(t, 2, visibleCount) test.AssertRendersToMarkup(t, "list/item_removed.xml", w.Canvas()) } @@ -477,7 +477,7 @@ func TestList_ScrollThenShrink(t *testing.T) { visibles := list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children visibleCount := len(visibles) - assert.Equal(t, visibleCount, 9) + assert.Equal(t, 9, visibleCount) list.scroller.ScrollToBottom() visibles = list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children @@ -488,7 +488,7 @@ func TestList_ScrollThenShrink(t *testing.T) { visibles = list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children visibleCount = len(visibles) - assert.Equal(t, visibleCount, 1) + assert.Equal(t, 1, visibleCount) assert.Equal(t, "Data 0", visibles[0].(*listItem).child.(*Label).Text) } diff --git a/widget/markdown_test.go b/widget/markdown_test.go index 72a19427a6..1d5b1eec6a 100644 --- a/widget/markdown_test.go +++ b/widget/markdown_test.go @@ -11,7 +11,7 @@ import ( func TestRichTextMarkdown_Blockquote(t *testing.T) { r := NewRichTextFromMarkdown("p1\n\n> quote\n\np2") - assert.Equal(t, 5, len(r.Segments)) + assert.Len(t, r.Segments, 5) if text, ok := r.Segments[2].(*TextSegment); ok { assert.Equal(t, "quote", text.Text) assert.Equal(t, RichTextStyleBlockquote, text.Style) @@ -23,7 +23,7 @@ func TestRichTextMarkdown_Blockquote(t *testing.T) { func TestRichTextMarkdown_Code(t *testing.T) { r := NewRichTextFromMarkdown("a `code` inline") - assert.Equal(t, 4, len(r.Segments)) + assert.Len(t, r.Segments, 4) if text, ok := r.Segments[1].(*TextSegment); ok { assert.Equal(t, "code", text.Text) assert.Equal(t, RichTextStyleCodeInline, text.Style) @@ -32,7 +32,7 @@ func TestRichTextMarkdown_Code(t *testing.T) { } r.ParseMarkdown("``` go\ncode\nblock\n```") - assert.Equal(t, 1, len(r.Segments)) + assert.Len(t, r.Segments, 1) if text, ok := r.Segments[0].(*TextSegment); ok { assert.Equal(t, "code\nblock", text.Text) assert.Equal(t, RichTextStyleCodeBlock, text.Style) @@ -44,7 +44,7 @@ func TestRichTextMarkdown_Code(t *testing.T) { func TestRichTextMarkdown_Code_Incomplete(t *testing.T) { r := NewRichTextFromMarkdown("` ") - assert.Equal(t, 2, len(r.Segments)) + assert.Len(t, r.Segments, 2) if text, ok := r.Segments[0].(*TextSegment); ok { assert.Equal(t, "`", text.Text) assert.Equal(t, RichTextStyleInline, text.Style) @@ -53,16 +53,16 @@ func TestRichTextMarkdown_Code_Incomplete(t *testing.T) { } r.ParseMarkdown("``` ") - assert.Equal(t, 0, len(r.Segments)) + assert.Empty(t, r.Segments) r.ParseMarkdown("~~~ ") - assert.Equal(t, 0, len(r.Segments)) + assert.Empty(t, r.Segments) } func TestRichTextMarkdown_Emphasis(t *testing.T) { r := NewRichTextFromMarkdown("*a*") - assert.Equal(t, 2, len(r.Segments)) + assert.Len(t, r.Segments, 2) if text, ok := r.Segments[0].(*TextSegment); ok { assert.Equal(t, "a", text.Text) assert.True(t, text.Style.TextStyle.Italic) @@ -72,7 +72,7 @@ func TestRichTextMarkdown_Emphasis(t *testing.T) { r.ParseMarkdown("**b**.") - assert.Equal(t, 3, len(r.Segments)) + assert.Len(t, r.Segments, 3) if text, ok := r.Segments[0].(*TextSegment); ok { assert.Equal(t, "b", text.Text) assert.True(t, text.Style.TextStyle.Bold) @@ -84,7 +84,7 @@ func TestRichTextMarkdown_Emphasis(t *testing.T) { func TestRichTextMarkdown_Heading(t *testing.T) { r := NewRichTextFromMarkdown("# Head1\n\n## Head2!\n### Head3\n") - assert.Equal(t, 3, len(r.Segments)) + assert.Len(t, r.Segments, 3) if text, ok := r.Segments[0].(*TextSegment); ok { assert.Equal(t, "Head1", text.Text) assert.Equal(t, RichTextStyleHeading, text.Style) @@ -100,7 +100,7 @@ func TestRichTextMarkdown_Heading(t *testing.T) { if text, ok := r.Segments[2].(*TextSegment); ok { assert.Equal(t, "Head3", text.Text) - assert.Equal(t, true, text.Style.TextStyle.Bold) // we don't have 6 levels of heading so just bold others + assert.True(t, text.Style.TextStyle.Bold) // we don't have 6 levels of heading so just bold others } else { t.Error("Segment should be Strong") } @@ -109,7 +109,7 @@ func TestRichTextMarkdown_Heading(t *testing.T) { func TestRichTextMarkdown_Heading_Blank(t *testing.T) { r := NewRichTextFromMarkdown("#") - assert.Equal(t, 1, len(r.Segments)) + assert.Len(t, r.Segments, 1) if text, ok := r.Segments[0].(*TextSegment); ok { assert.Equal(t, "", text.Text) assert.Equal(t, RichTextStyleHeading, text.Style) @@ -119,7 +119,7 @@ func TestRichTextMarkdown_Heading_Blank(t *testing.T) { r = NewRichTextFromMarkdown("# ") - assert.Equal(t, 1, len(r.Segments)) + assert.Len(t, r.Segments, 1) if text, ok := r.Segments[0].(*TextSegment); ok { assert.Equal(t, "", text.Text) assert.Equal(t, RichTextStyleHeading, text.Style) @@ -131,7 +131,7 @@ func TestRichTextMarkdown_Heading_Blank(t *testing.T) { func TestRichTextMarkdown_Hyperlink(t *testing.T) { r := NewRichTextFromMarkdown("[title](https://fyne.io/)") - assert.Equal(t, 2, len(r.Segments)) + assert.Len(t, r.Segments, 2) if link, ok := r.Segments[0].(*HyperlinkSegment); ok { assert.Equal(t, "title", link.Text) assert.Equal(t, "fyne.io", link.URL.Host) @@ -143,7 +143,7 @@ func TestRichTextMarkdown_Hyperlink(t *testing.T) { func TestRichTextMarkdown_Image(t *testing.T) { r := NewRichTextFromMarkdown("![title](../../theme/icons/fyne.png)") - assert.Equal(t, 2, len(r.Segments)) + assert.Len(t, r.Segments, 2) if img, ok := r.Segments[0].(*ImageSegment); ok { assert.Equal(t, storage.NewFileURI("../../theme/icons/fyne.png"), img.Source) } else { @@ -152,7 +152,7 @@ func TestRichTextMarkdown_Image(t *testing.T) { r = NewRichTextFromMarkdown("![](../../theme/icons/fyne.png)") - assert.Equal(t, 2, len(r.Segments)) + assert.Len(t, r.Segments, 2) if img, ok := r.Segments[0].(*ImageSegment); ok { assert.Equal(t, storage.NewFileURI("../../theme/icons/fyne.png"), img.Source) } else { @@ -163,7 +163,7 @@ func TestRichTextMarkdown_Image(t *testing.T) { func TestRichTextMarkdown_Lines(t *testing.T) { r := NewRichTextFromMarkdown("line1\nline2\n") // a single newline is not a new paragraph - assert.Equal(t, 3, len(r.Segments)) + assert.Len(t, r.Segments, 3) if text, ok := r.Segments[0].(*TextSegment); ok { assert.Equal(t, "line1 ", text.Text) assert.True(t, text.Inline()) @@ -178,7 +178,7 @@ func TestRichTextMarkdown_Lines(t *testing.T) { r.ParseMarkdown("line1\n\nline2\n") - assert.Equal(t, 4, len(r.Segments)) + assert.Len(t, r.Segments, 4) if text, ok := r.Segments[0].(*TextSegment); ok { assert.Equal(t, "line1", text.Text) assert.True(t, text.Inline()) @@ -195,10 +195,10 @@ func TestRichTextMarkdown_Lines(t *testing.T) { func TestRichTextMarkdown_List(t *testing.T) { r := NewRichTextFromMarkdown("* line1 in _three_ segments\n* line2") - assert.Equal(t, 1, len(r.Segments)) + assert.Len(t, r.Segments, 1) if list, ok := r.Segments[0].(*ListSegment); ok { - assert.Equal(t, 2, len(list.Items)) - assert.Equal(t, 3, len(list.Items[0].(*ParagraphSegment).Texts)) + assert.Len(t, list.Items, 2) + assert.Len(t, list.Items[0].(*ParagraphSegment).Texts, 3) assert.Equal(t, "line1 in ", list.Items[0].(*ParagraphSegment).Texts[0].(*TextSegment).Text) } else { t.Error("Segment should be a List") @@ -206,11 +206,11 @@ func TestRichTextMarkdown_List(t *testing.T) { r.ParseMarkdown("1. line1\n2. line2") - assert.Equal(t, 1, len(r.Segments)) + assert.Len(t, r.Segments, 1) if list, ok := r.Segments[0].(*ListSegment); ok { assert.True(t, list.Ordered) - assert.Equal(t, 2, len(list.Items)) - assert.Equal(t, 1, len(list.Items[1].(*ParagraphSegment).Texts)) + assert.Len(t, list.Items, 2) + assert.Len(t, list.Items[1].(*ParagraphSegment).Texts, 1) assert.Equal(t, "line2", list.Items[1].(*ParagraphSegment).Texts[0].(*TextSegment).Text) } else { t.Error("Segment should be a List") @@ -220,7 +220,7 @@ func TestRichTextMarkdown_List(t *testing.T) { func TestRichTextMarkdown_Separator(t *testing.T) { r := NewRichTextFromMarkdown("---\n") - assert.Equal(t, 1, len(r.Segments)) + assert.Len(t, r.Segments, 1) if _, ok := r.Segments[0].(*SeparatorSegment); !ok { t.Error("Segment should be a separator") } @@ -229,7 +229,7 @@ func TestRichTextMarkdown_Separator(t *testing.T) { func TestRichTextMarkdown_Paragraph(t *testing.T) { r := NewRichTextFromMarkdown("foo") - assert.Equal(t, 2, len(r.Segments)) + assert.Len(t, r.Segments, 2) if text, ok := r.Segments[1].(*TextSegment); ok { assert.Equal(t, "", text.Text) assert.Equal(t, RichTextStyleParagraph, text.Style) diff --git a/widget/popup_test.go b/widget/popup_test.go index 6540c43059..0978d12a88 100644 --- a/widget/popup_test.go +++ b/widget/popup_test.go @@ -21,11 +21,11 @@ func TestNewPopUp(t *testing.T) { pop := NewPopUp(label, test.Canvas()) defer test.Canvas().Overlays().Remove(pop) - assert.Equal(t, 0, len(test.Canvas().Overlays().List())) + assert.Empty(t, test.Canvas().Overlays().List()) pop.Show() assert.True(t, pop.Visible()) - assert.Equal(t, 1, len(test.Canvas().Overlays().List())) + assert.Len(t, test.Canvas().Overlays().List(), 1) assert.Equal(t, pop, test.Canvas().Overlays().List()[0]) } @@ -43,7 +43,7 @@ func TestShowPopUp(t *testing.T) { defer w.Canvas().Overlays().Remove(pop) assert.True(t, pop.Visible()) - assert.Equal(t, 1, len(w.Canvas().Overlays().List())) + assert.Len(t, w.Canvas().Overlays().List(), 1) } test.AssertRendersToMarkup(t, "popup/normal.xml", w.Canvas()) @@ -58,7 +58,7 @@ func TestShowPopUpAtPosition(t *testing.T) { pop := c.Overlays().Top() if assert.NotNil(t, pop) { assert.True(t, pop.Visible()) - assert.Equal(t, 1, len(c.Overlays().List())) + assert.Len(t, c.Overlays().List(), 1) assert.Equal(t, pos.Add(fyne.NewPos(theme.Padding(), theme.Padding())), pop.(*PopUp).Content.Position()) } } @@ -76,7 +76,7 @@ func TestShowPopUpAtRelativePosition(t *testing.T) { pop := w.Canvas().Overlays().Top() if assert.NotNil(t, pop) { assert.True(t, pop.Visible()) - assert.Equal(t, 1, len(w.Canvas().Overlays().List())) + assert.Len(t, w.Canvas().Overlays().List(), 1) areaPos, _ := w.Canvas().InteractiveArea() assert.Equal(t, pos.Add(parent2.Position()).Add(fyne.NewPos(theme.Padding()*2, theme.Padding()*2)).Subtract(areaPos), pop.(*PopUp).Content.Position()) } @@ -96,7 +96,7 @@ func TestShowModalPopUp(t *testing.T) { defer w.Canvas().Overlays().Remove(pop) assert.True(t, pop.Visible()) - assert.Equal(t, 1, len(w.Canvas().Overlays().List())) + assert.Len(t, w.Canvas().Overlays().List(), 1) } test.AssertRendersToMarkup(t, "popup/modal.xml", w.Canvas()) @@ -112,7 +112,7 @@ func TestPopUp_Show(t *testing.T) { pop.Show() assert.Equal(t, pop, c.Overlays().Top()) - assert.Equal(t, 1, len(c.Overlays().List())) + assert.Len(t, c.Overlays().List(), 1) assert.Equal(t, cSize, pop.Size()) assert.Equal(t, label.MinSize(), pop.Content.Size()) } @@ -128,7 +128,7 @@ func TestPopUp_ShowAtPosition(t *testing.T) { pop.ShowAtPosition(pos) assert.Equal(t, pop, c.Overlays().Top()) - assert.Equal(t, 1, len(c.Overlays().List())) + assert.Len(t, c.Overlays().List(), 1) assert.Equal(t, cSize, pop.Size()) assert.Equal(t, label.MinSize(), pop.Content.Size()) assert.Equal(t, pos.Add(fyne.NewPos(theme.Padding(), theme.Padding())), pop.Content.Position()) @@ -142,7 +142,7 @@ func TestPopUp_Hide(t *testing.T) { assert.True(t, pop.Visible()) pop.Hide() assert.False(t, pop.Visible()) - assert.Equal(t, 0, len(test.Canvas().Overlays().List())) + assert.Empty(t, test.Canvas().Overlays().List()) } func TestPopUp_MinSize(t *testing.T) { @@ -243,7 +243,7 @@ func TestPopUp_Tapped(t *testing.T) { assert.True(t, pop.Visible()) test.Tap(pop) assert.False(t, pop.Visible()) - assert.Equal(t, 0, len(test.Canvas().Overlays().List())) + assert.Empty(t, test.Canvas().Overlays().List()) } func TestPopUp_TappedSecondary(t *testing.T) { @@ -254,7 +254,7 @@ func TestPopUp_TappedSecondary(t *testing.T) { assert.True(t, pop.Visible()) test.TapSecondary(pop) assert.False(t, pop.Visible()) - assert.Equal(t, 0, len(test.Canvas().Overlays().List())) + assert.Empty(t, test.Canvas().Overlays().List()) } func TestPopUp_Stacked(t *testing.T) { @@ -401,7 +401,7 @@ func TestModalPopUp_Tapped(t *testing.T) { assert.True(t, pop.Visible()) test.Tap(pop) assert.True(t, pop.Visible()) - assert.Equal(t, 1, len(test.Canvas().Overlays().List())) + assert.Len(t, test.Canvas().Overlays().List(), 1) assert.Equal(t, pop, test.Canvas().Overlays().List()[0]) } @@ -414,7 +414,7 @@ func TestModalPopUp_TappedSecondary(t *testing.T) { assert.True(t, pop.Visible()) test.TapSecondary(pop) assert.True(t, pop.Visible()) - assert.Equal(t, 1, len(test.Canvas().Overlays().List())) + assert.Len(t, test.Canvas().Overlays().List(), 1) assert.Equal(t, pop, test.Canvas().Overlays().List()[0]) } diff --git a/widget/progressbar_test.go b/widget/progressbar_test.go index ab0ee39e47..38abce1958 100644 --- a/widget/progressbar_test.go +++ b/widget/progressbar_test.go @@ -83,7 +83,7 @@ func TestProgressBar_TextFormatter(t *testing.T) { formatted := false bar.SetValue(0.2) - assert.Equal(t, false, formatted) + assert.False(t, formatted) formatter := func() string { formatted = true @@ -93,7 +93,7 @@ func TestProgressBar_TextFormatter(t *testing.T) { bar.SetValue(0.4) - assert.Equal(t, true, formatted) + assert.True(t, formatted) } func TestProgressRenderer_Layout(t *testing.T) { diff --git a/widget/radio_group_extended_test.go b/widget/radio_group_extended_test.go index edd13ea2fb..78fdadd5fd 100644 --- a/widget/radio_group_extended_test.go +++ b/widget/radio_group_extended_test.go @@ -50,27 +50,27 @@ func TestRadioGroup_Extended_Unselected(t *testing.T) { func TestRadioGroup_Extended_Append(t *testing.T) { radio := newextendedRadioGroup([]string{"Hi"}, nil) - assert.Equal(t, 1, len(radio.Options)) - assert.Equal(t, 1, len(cache.Renderer(radio).(*radioGroupRenderer).items)) + assert.Len(t, radio.Options, 1) + assert.Len(t, cache.Renderer(radio).(*radioGroupRenderer).items, 1) radio.Options = append(radio.Options, "Another") radio.Refresh() - assert.Equal(t, 2, len(radio.Options)) - assert.Equal(t, 2, len(cache.Renderer(radio).(*radioGroupRenderer).items)) + assert.Len(t, radio.Options, 2) + assert.Len(t, cache.Renderer(radio).(*radioGroupRenderer).items, 2) } func TestRadioGroup_Extended_Remove(t *testing.T) { radio := newextendedRadioGroup([]string{"Hi", "Another"}, nil) - assert.Equal(t, 2, len(radio.Options)) - assert.Equal(t, 2, len(cache.Renderer(radio).(*radioGroupRenderer).items)) + assert.Len(t, radio.Options, 2) + assert.Len(t, cache.Renderer(radio).(*radioGroupRenderer).items, 2) radio.Options = radio.Options[:1] radio.Refresh() - assert.Equal(t, 1, len(radio.Options)) - assert.Equal(t, 1, len(cache.Renderer(radio).(*radioGroupRenderer).items)) + assert.Len(t, radio.Options, 1) + assert.Len(t, cache.Renderer(radio).(*radioGroupRenderer).items, 1) } func TestRadioGroup_Extended_SetSelected(t *testing.T) { diff --git a/widget/radio_group_internal_test.go b/widget/radio_group_internal_test.go index 392c19f63b..ecf7cf584d 100644 --- a/widget/radio_group_internal_test.go +++ b/widget/radio_group_internal_test.go @@ -19,8 +19,8 @@ func TestRadioGroup_MinSize(t *testing.T) { radio := NewRadioGroup([]string{"Hi"}, nil) min := radio.MinSize() - assert.True(t, min.Width > theme.InnerPadding()) - assert.True(t, min.Height > theme.InnerPadding()) + assert.Greater(t, min.Width, theme.InnerPadding()) + assert.Greater(t, min.Height, theme.InnerPadding()) radio2 := NewRadioGroup([]string{"Hi", "H"}, nil) min2 := radio2.MinSize() @@ -37,7 +37,7 @@ func TestRadioGroup_MinSize_Horizontal(t *testing.T) { radio2.Horizontal = true min2 := radio2.MinSize() - assert.True(t, min2.Width > min.Width) + assert.Greater(t, min2.Width, min.Width) assert.Equal(t, min.Height, min2.Height) } @@ -94,27 +94,27 @@ func TestRadioGroup_SelectedOther(t *testing.T) { func TestRadioGroup_Append(t *testing.T) { radio := NewRadioGroup([]string{"Hi"}, nil) - assert.Equal(t, 1, len(radio.Options)) - assert.Equal(t, 1, len(test.TempWidgetRenderer(t, radio).(*radioGroupRenderer).items)) + assert.Len(t, radio.Options, 1) + assert.Len(t, test.TempWidgetRenderer(t, radio).(*radioGroupRenderer).items, 1) radio.Options = append(radio.Options, "Another") radio.Refresh() - assert.Equal(t, 2, len(radio.Options)) - assert.Equal(t, 2, len(test.TempWidgetRenderer(t, radio).(*radioGroupRenderer).items)) + assert.Len(t, radio.Options, 2) + assert.Len(t, test.TempWidgetRenderer(t, radio).(*radioGroupRenderer).items, 2) } func TestRadioGroup_Remove(t *testing.T) { radio := NewRadioGroup([]string{"Hi", "Another"}, nil) - assert.Equal(t, 2, len(radio.Options)) - assert.Equal(t, 2, len(test.TempWidgetRenderer(t, radio).(*radioGroupRenderer).items)) + assert.Len(t, radio.Options, 2) + assert.Len(t, test.TempWidgetRenderer(t, radio).(*radioGroupRenderer).items, 2) radio.Options = radio.Options[:1] radio.Refresh() - assert.Equal(t, 1, len(radio.Options)) - assert.Equal(t, 1, len(test.TempWidgetRenderer(t, radio).(*radioGroupRenderer).items)) + assert.Len(t, radio.Options, 1) + assert.Len(t, test.TempWidgetRenderer(t, radio).(*radioGroupRenderer).items, 1) } func TestRadioGroup_SetSelected(t *testing.T) { @@ -127,7 +127,7 @@ func TestRadioGroup_SetSelected(t *testing.T) { radio.SetSelected("Another") assert.Equal(t, "Another", radio.Selected) - assert.Equal(t, true, changed) + assert.True(t, changed) } func TestRadioGroup_SetSelectedWithSameOption(t *testing.T) { @@ -155,16 +155,16 @@ func TestRadioGroup_SetSelectedEmpty(t *testing.T) { func TestRadioGroup_DuplicatedOptions(t *testing.T) { radio := NewRadioGroup([]string{"Hi", "Hi", "Hi", "Another", "Another"}, nil) - assert.Equal(t, 5, len(radio.Options)) - assert.Equal(t, 5, len(test.TempWidgetRenderer(t, radio).(*radioGroupRenderer).items)) + assert.Len(t, radio.Options, 5) + assert.Len(t, test.TempWidgetRenderer(t, radio).(*radioGroupRenderer).items, 5) radioGroupTestTapItem(t, radio, 1) assert.Equal(t, "Hi", radio.Selected) assert.Equal(t, 1, radio.selectedIndex()) item0 := test.TempWidgetRenderer(t, radio).Objects()[0].(*radioItem) - assert.Equal(t, false, item0.focused) + assert.False(t, item0.focused) item1 := test.TempWidgetRenderer(t, radio).Objects()[0].(*radioItem) - assert.Equal(t, false, item1.focused) + assert.False(t, item1.focused) } func TestRadioGroup_AppendDuplicate(t *testing.T) { @@ -172,8 +172,8 @@ func TestRadioGroup_AppendDuplicate(t *testing.T) { radio.Append("Hi") - assert.Equal(t, 2, len(radio.Options)) - assert.Equal(t, 2, len(test.TempWidgetRenderer(t, radio).(*radioGroupRenderer).items)) + assert.Len(t, radio.Options, 2) + assert.Len(t, test.TempWidgetRenderer(t, radio).(*radioGroupRenderer).items, 2) } func TestRadioGroup_Disable(t *testing.T) { diff --git a/widget/richtext_test.go b/widget/richtext_test.go index f207c31dc5..9e50044a0c 100644 --- a/widget/richtext_test.go +++ b/widget/richtext_test.go @@ -40,7 +40,7 @@ func TestRichText_Hyperlink_Endline(t *testing.T) { r.Resize(r.MinSize()) view := cache.Renderer(r) - assert.Equal(t, 2, len(view.Objects())) + assert.Len(t, view.Objects(), 2) assert.Equal(t, view.Objects()[0].Position().Y, view.Objects()[1].Position().Y) // same baseline assert.Greater(t, view.Objects()[1].Position().X, view.Objects()[0].Position().X) // to the right } diff --git a/widget/select_internal_test.go b/widget/select_internal_test.go index afa753d4f5..22963eb80c 100644 --- a/widget/select_internal_test.go +++ b/widget/select_internal_test.go @@ -14,7 +14,7 @@ func TestSelect_SetOptions(t *testing.T) { test.Tap(sel) assert.NotNil(t, sel.popUp) - assert.Equal(t, 3, len(sel.popUp.Items)) + assert.Len(t, sel.popUp.Items, 3) assert.Equal(t, "10", sel.popUp.Items[0].(*menuItem).Item.Label) sel.popUp.Hide() @@ -22,7 +22,7 @@ func TestSelect_SetOptions(t *testing.T) { test.Tap(sel) assert.NotNil(t, sel.popUp) - assert.Equal(t, 3, len(sel.popUp.Items)) + assert.Len(t, sel.popUp.Items, 3) assert.Equal(t, "16", sel.popUp.Items[1].(*menuItem).Item.Label) sel.popUp.Hide() @@ -31,7 +31,7 @@ func TestSelect_SetOptions(t *testing.T) { test.Tap(sel) assert.NotNil(t, sel.popUp) - assert.Equal(t, 2, len(sel.popUp.Items)) + assert.Len(t, sel.popUp.Items, 2) assert.Equal(t, "20", sel.popUp.Items[0].(*menuItem).Item.Label) } diff --git a/widget/select_test.go b/widget/select_test.go index aeb525ca37..f4cbb96db8 100644 --- a/widget/select_test.go +++ b/widget/select_test.go @@ -22,7 +22,7 @@ import ( func TestNewSelect(t *testing.T) { combo := widget.NewSelect([]string{"1", "2"}, func(string) {}) - assert.Equal(t, 2, len(combo.Options)) + assert.Len(t, combo.Options, 2) assert.Equal(t, "", combo.Selected) } @@ -30,11 +30,11 @@ func TestNewSelectWithData(t *testing.T) { data := binding.NewString() combo := widget.NewSelectWithData([]string{"1", "2", "3"}, data) - assert.Equal(t, 3, len(combo.Options)) + assert.Len(t, combo.Options, 3) assert.Equal(t, "", combo.Selected) err := data.Set("2") - assert.Nil(t, err) + assert.NoError(t, err) waitForBinding() assert.Equal(t, "2", combo.Selected) } @@ -78,27 +78,27 @@ func TestSelect_Binding(t *testing.T) { s.Bind(str) waitForBinding() value, err := str.Get() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "", value) assert.Equal(t, "2", s.Selected) // no match to options, so keep previous value err = str.Set("3") - assert.Nil(t, err) + assert.NoError(t, err) waitForBinding() assert.Equal(t, "3", s.Selected) s.Unbind() assert.Nil(t, s.OnChanged) err = str.Set("1") - assert.Nil(t, err) + assert.NoError(t, err) val1, err := str.Get() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "1", val1) assert.Equal(t, "3", s.Selected) s.SetSelected("2") val1, err = str.Get() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, "1", val1) assert.Equal(t, "2", s.Selected) } @@ -155,11 +155,11 @@ func TestSelect_ClipValue(t *testing.T) { r := cache.Renderer(combo) text := r.Objects()[2].(*widget.RichText) - assert.Equal(t, 1, len(text.Segments)) + assert.Len(t, text.Segments, 1) assert.Equal(t, "some text", text.Segments[0].(*widget.TextSegment).Text) r2 := cache.Renderer(text) - assert.Equal(t, 1, len(r2.Objects())) + assert.Len(t, r2.Objects(), 1) assert.Equal(t, "some …", r2.Objects()[0].(*canvas.Text).Text) } @@ -481,7 +481,7 @@ func TestSelect_Tapped(t *testing.T) { test.Tap(combo) canvas := fyne.CurrentApp().Driver().CanvasForObject(combo) - assert.Equal(t, 1, len(canvas.Overlays().List())) + assert.Len(t, canvas.Overlays().List(), 1) assertRendersToPlatformMarkup(t, "select/%s/tapped.xml", w.Canvas()) } @@ -497,7 +497,7 @@ func TestSelect_Tapped_Constrained(t *testing.T) { canvas := w.Canvas() combo.Move(fyne.NewPos(canvas.Size().Width-10, canvas.Size().Height-10)) test.Tap(combo) - assert.Equal(t, 1, len(canvas.Overlays().List())) + assert.Len(t, canvas.Overlays().List(), 1) assertRendersToPlatformMarkup(t, "select/%s/tapped_constrained.xml", w.Canvas()) } diff --git a/widget/slider_extend_test.go b/widget/slider_extend_test.go index d403cacc4f..472648df80 100644 --- a/widget/slider_extend_test.go +++ b/widget/slider_extend_test.go @@ -25,7 +25,7 @@ func TestSlider_Extended_Value(t *testing.T) { slider := newExtendedSlider() slider.Resize(slider.MinSize().Add(fyne.NewSize(20, 0))) objs := cache.Renderer(slider).Objects() - assert.Equal(t, 4, len(objs)) + assert.Len(t, objs, 4) thumb := objs[2] thumbPos := thumb.Position() @@ -38,7 +38,7 @@ func TestSlider_Extended_Value(t *testing.T) { func TestSlider_Extended_Drag(t *testing.T) { slider := newExtendedSlider() objs := cache.Renderer(slider).Objects() - assert.Equal(t, 4, len(objs)) + assert.Len(t, objs, 4) thumb := objs[2] thumbPos := thumb.Position() diff --git a/widget/slider_test.go b/widget/slider_test.go index a15e14d688..48c92ee263 100644 --- a/widget/slider_test.go +++ b/widget/slider_test.go @@ -14,7 +14,7 @@ import ( func TestNewSliderWithData(t *testing.T) { val := binding.NewFloat() err := val.Set(4) - assert.Nil(t, err) + assert.NoError(t, err) s := NewSliderWithData(0, 10, val) waitForBinding() @@ -22,7 +22,7 @@ func TestNewSliderWithData(t *testing.T) { s.SetValue(2.0) f, err := val.Get() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, 2.0, f) } @@ -37,13 +37,13 @@ func TestSlider_Binding(t *testing.T) { assert.Equal(t, 0.0, s.Value) err := val.Set(3) - assert.Nil(t, err) + assert.NoError(t, err) waitForBinding() assert.Equal(t, 3.0, s.Value) s.SetValue(5) f, err := val.Get() - assert.Nil(t, err) + assert.NoError(t, err) assert.Equal(t, 5.0, f) s.Unbind() diff --git a/widget/table_internal_test.go b/widget/table_internal_test.go index 9de625d14d..a9d09405ee 100644 --- a/widget/table_internal_test.go +++ b/widget/table_internal_test.go @@ -40,14 +40,14 @@ func TestTable_Cache(t *testing.T) { cellRenderer := test.TempWidgetRenderer(t, table.content.Content.(*tableCells)) cellRenderer.Refresh() - assert.Equal(t, 6, len(cellRenderer.(*tableCellsRenderer).visible)) + assert.Len(t, cellRenderer.(*tableCellsRenderer).visible, 6) assert.Equal(t, "Cell 0, 0", cellRenderer.Objects()[0].(*Label).Text) objRef := cellRenderer.Objects()[0].(*Label) test.Scroll(c, fyne.NewPos(10, 10), -150, -150) assert.Equal(t, float32(0), table.content.Offset.Y) // we didn't scroll as data shorter assert.Equal(t, float32(150), table.content.Offset.X) - assert.Equal(t, 6, len(cellRenderer.(*tableCellsRenderer).visible)) + assert.Len(t, cellRenderer.(*tableCellsRenderer).visible, 6) assert.Equal(t, "Cell 0, 1", cellRenderer.Objects()[0].(*Label).Text) assert.NotEqual(t, objRef, cellRenderer.Objects()[0].(*Label)) // we want to re-use visible cells without rewriting them } @@ -727,7 +727,7 @@ func TestTable_SetColumnWidth(t *testing.T) { cellRenderer := test.TempWidgetRenderer(t, table.content.Content.(*tableCells)) cellRenderer.Refresh() - assert.Equal(t, 8, len(cellRenderer.(*tableCellsRenderer).visible)) + assert.Len(t, cellRenderer.(*tableCellsRenderer).visible, 8) assert.Equal(t, float32(32), cellRenderer.(*tableCellsRenderer).Objects()[0].Size().Width) cell1Offset := theme.Padding() assert.Equal(t, float32(32)+cell1Offset, cellRenderer.(*tableCellsRenderer).Objects()[1].Position().X) @@ -806,7 +806,7 @@ func TestTable_SetRowHeight(t *testing.T) { cellRenderer := test.TempWidgetRenderer(t, table.content.Content.(*tableCells)) cellRenderer.Refresh() - assert.Equal(t, 6, len(cellRenderer.(*tableCellsRenderer).visible)) + assert.Len(t, cellRenderer.(*tableCellsRenderer).visible, 6) assert.Equal(t, float32(48), cellRenderer.(*tableCellsRenderer).Objects()[0].Size().Height) cell1Offset := theme.Padding() assert.Equal(t, float32(48)+cell1Offset, cellRenderer.(*tableCellsRenderer).Objects()[3].Position().Y) @@ -873,7 +873,7 @@ func TestTable_ShowVisible(t *testing.T) { cellRenderer := test.TempWidgetRenderer(t, table.content.Content.(*tableCells)) cellRenderer.Refresh() - assert.Equal(t, 8, len(cellRenderer.(*tableCellsRenderer).visible)) + assert.Len(t, cellRenderer.(*tableCellsRenderer).visible, 8) } func TestTable_SeparatorThicknessZero_NotPanics(t *testing.T) { diff --git a/widget/textgrid_test.go b/widget/textgrid_test.go index 98331e3b02..a71422725f 100644 --- a/widget/textgrid_test.go +++ b/widget/textgrid_test.go @@ -17,8 +17,8 @@ func TestNewTextGrid(t *testing.T) { grid := NewTextGridFromString("A") test.TempWidgetRenderer(t, grid).Refresh() - assert.Equal(t, 1, len(grid.Rows)) - assert.Equal(t, 1, len(grid.Rows[0].Cells)) + assert.Len(t, grid.Rows, 1) + assert.Len(t, grid.Rows[0].Cells, 1) } func TestTextGrid_CreateRendererRows(t *testing.T) { @@ -27,7 +27,7 @@ func TestTextGrid_CreateRendererRows(t *testing.T) { rend := test.TempWidgetRenderer(t, grid).(*textGridRenderer) rend.Refresh() - assert.Equal(t, 18, len(rend.objects)) + assert.Len(t, rend.objects, 18) } func TestTextGrid_Row(t *testing.T) { @@ -35,7 +35,7 @@ func TestTextGrid_Row(t *testing.T) { test.TempWidgetRenderer(t, grid).Refresh() assert.NotNil(t, grid.Row(0)) - assert.Equal(t, 2, len(grid.Row(0).Cells)) + assert.Len(t, grid.Row(0).Cells, 2) assert.Equal(t, 'b', grid.Row(0).Cells[1].Rune) } @@ -43,8 +43,8 @@ func TestTextGrid_Rows(t *testing.T) { grid := NewTextGridFromString("Ab\nC") test.TempWidgetRenderer(t, grid).Refresh() - assert.Equal(t, 2, len(grid.Rows)) - assert.Equal(t, 2, len(grid.Rows[0].Cells)) + assert.Len(t, grid.Rows, 2) + assert.Len(t, grid.Rows[0].Cells, 2) } func TestTextGrid_RowText(t *testing.T) { @@ -61,16 +61,16 @@ func TestTextGrid_SetText(t *testing.T) { text := "\n\n\n\n\n\n\n\n\n\n\n\n" grid.SetText(text) // goes beyond the current view size - don't crash - assert.Equal(t, 13, len(grid.Rows)) - assert.Equal(t, 0, len(grid.Rows[1].Cells)) + assert.Len(t, grid.Rows, 13) + assert.Empty(t, grid.Rows[1].Cells) } func TestTextGrid_SetText_Overflow(t *testing.T) { grid := NewTextGrid() grid.SetText("Hello\nthere") - assert.Equal(t, 2, len(grid.Rows)) - assert.Equal(t, 5, len(grid.Rows[1].Cells)) + assert.Len(t, grid.Rows, 2) + assert.Len(t, grid.Rows[1].Cells, 5) } func TestTextGrid_SetRowStyle(t *testing.T) { diff --git a/widget/toolbar_test.go b/widget/toolbar_test.go index 5b33c60b71..94de43f48e 100644 --- a/widget/toolbar_test.go +++ b/widget/toolbar_test.go @@ -12,7 +12,7 @@ import ( func TestToolbarSize(t *testing.T) { toolbar := NewToolbar(NewToolbarSpacer(), NewToolbarAction(theme.HomeIcon(), func() {})) - assert.Equal(t, 2, len(toolbar.Items)) + assert.Len(t, toolbar.Items, 2) size := toolbar.MinSize() toolbar.Items = append(toolbar.Items, &toolbarLabel{NewLabel("Hi")}) @@ -23,28 +23,28 @@ func TestToolbarSize(t *testing.T) { func TestToolbar_Apppend(t *testing.T) { toolbar := NewToolbar(NewToolbarSpacer()) - assert.Equal(t, 1, len(toolbar.Items)) + assert.Len(t, toolbar.Items, 1) added := NewToolbarAction(theme.ContentCutIcon(), func() {}) toolbar.Append(added) - assert.Equal(t, 2, len(toolbar.Items)) + assert.Len(t, toolbar.Items, 2) assert.Equal(t, added, toolbar.Items[1]) } func TestToolbar_Prepend(t *testing.T) { toolbar := NewToolbar(NewToolbarSpacer()) - assert.Equal(t, 1, len(toolbar.Items)) + assert.Len(t, toolbar.Items, 1) prepend := NewToolbarAction(theme.ContentCutIcon(), func() {}) toolbar.Prepend(prepend) - assert.Equal(t, 2, len(toolbar.Items)) + assert.Len(t, toolbar.Items, 2) assert.Equal(t, prepend, toolbar.Items[0]) } func TestToolbar_Replace(t *testing.T) { icon := theme.ContentCutIcon() toolbar := NewToolbar(NewToolbarAction(icon, func() {})) - assert.Equal(t, 1, len(toolbar.Items)) + assert.Len(t, toolbar.Items, 1) render := test.TempWidgetRenderer(t, toolbar) assert.Equal(t, icon.Name(), render.Objects()[0].(*Button).Icon.Name()) @@ -68,7 +68,7 @@ func TestToolbar_ItemPositioning(t *testing.T) { items = append(items, b) } } - if assert.Equal(t, 2, len(items)) { + if assert.Len(t, items, 2) { assert.Equal(t, fyne.NewPos(0, 0), items[0].Position()) assert.Equal(t, fyne.NewPos(40, 0), items[1].Position()) } @@ -95,8 +95,8 @@ func TestToolbarAction_Disable(t *testing.T) { testIcon := theme.InfoIcon() toolbarAction := NewToolbarAction(testIcon, nil) toolbarAction.Disable() - assert.NotEqual(t, false, toolbarAction.Disabled()) - assert.Equal(t, true, toolbarAction.Disabled()) + assert.True(t, toolbarAction.Disabled()) + assert.True(t, toolbarAction.Disabled()) } func TestToolbarAction_Enable(t *testing.T) { @@ -104,8 +104,8 @@ func TestToolbarAction_Enable(t *testing.T) { toolbarAction := NewToolbarAction(testIcon, nil) toolbarAction.Disable() toolbarAction.Enable() - assert.NotEqual(t, true, toolbarAction.Disabled()) - assert.Equal(t, false, toolbarAction.Disabled()) + assert.False(t, toolbarAction.Disabled()) + assert.False(t, toolbarAction.Disabled()) } func TestToolbarAction_UpdateOnActivated(t *testing.T) { diff --git a/widget/tree_internal_test.go b/widget/tree_internal_test.go index 0302438a13..c99cc4fa8e 100644 --- a/widget/tree_internal_test.go +++ b/widget/tree_internal_test.go @@ -57,7 +57,7 @@ func TestTree(t *testing.T) { tree.walkAll(func(uid, _ string, branch bool, depth int) { nodes = append(nodes, uid) }) - assert.Equal(t, 0, len(nodes)) + assert.Empty(t, nodes) }) t.Run("Initializer_Populated", func(t *testing.T) { tree := &Tree{ @@ -89,10 +89,10 @@ func TestTree(t *testing.T) { leaves = append(leaves, uid) } }) - assert.Equal(t, 2, len(branches)) + assert.Len(t, branches, 2) assert.Equal(t, "", branches[0]) assert.Equal(t, "c", branches[1]) - assert.Equal(t, 5, len(leaves)) + assert.Len(t, leaves, 5) assert.Equal(t, "a", leaves[0]) assert.Equal(t, "b", leaves[1]) assert.Equal(t, "d", leaves[2]) @@ -129,10 +129,10 @@ func TestTree(t *testing.T) { leaves = append(leaves, uid) } }) - assert.Equal(t, 2, len(branches)) + assert.Len(t, branches, 2) assert.Equal(t, "", branches[0]) assert.Equal(t, "c", branches[1]) - assert.Equal(t, 5, len(leaves)) + assert.Len(t, leaves, 5) assert.Equal(t, "a", leaves[0]) assert.Equal(t, "b", leaves[1]) assert.Equal(t, "d", leaves[2]) @@ -153,10 +153,10 @@ func TestTree(t *testing.T) { leaves = append(leaves, uid) } }) - assert.Equal(t, 2, len(branches)) + assert.Len(t, branches, 2) assert.Equal(t, "", branches[0]) // Root assert.Equal(t, "foo", branches[1]) - assert.Equal(t, 1, len(leaves)) + assert.Len(t, leaves, 1) assert.Equal(t, "foobar", leaves[0]) }) } @@ -229,90 +229,90 @@ func TestTree_Keyboard(t *testing.T) { // Validate the state assert.NotNil(t, canvas.Focused()) assert.Equal(t, "item_1", canvas.Focused().(*Tree).currentFocus) - assert.Equal(t, tree.IsBranchOpen("item_1"), false) - assert.Equal(t, tree.IsBranchOpen("item_2"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_1"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_2"), false) + assert.False(t, tree.IsBranchOpen("item_1")) + assert.False(t, tree.IsBranchOpen("item_2")) + assert.False(t, tree.IsBranchOpen("item_1_1")) + assert.False(t, tree.IsBranchOpen("item_1_2")) // Open the node "item_1" tree.TypedKey(&fyne.KeyEvent{Name: fyne.KeyRight}) // Validate the state assert.NotNil(t, canvas.Focused()) assert.Equal(t, "item_1_1", canvas.Focused().(*Tree).currentFocus) - assert.Equal(t, tree.IsBranchOpen("item_1"), true) - assert.Equal(t, tree.IsBranchOpen("item_2"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_1"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_2"), false) + assert.True(t, tree.IsBranchOpen("item_1")) + assert.False(t, tree.IsBranchOpen("item_2")) + assert.False(t, tree.IsBranchOpen("item_1_1")) + assert.False(t, tree.IsBranchOpen("item_1_2")) // Go to next node "item1_2" tree.TypedKey(&fyne.KeyEvent{Name: fyne.KeyDown}) // Validate the state assert.NotNil(t, canvas.Focused()) assert.Equal(t, "item_1_2", canvas.Focused().(*Tree).currentFocus) - assert.Equal(t, tree.IsBranchOpen("item_1"), true) - assert.Equal(t, tree.IsBranchOpen("item_2"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_1"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_2"), false) + assert.True(t, tree.IsBranchOpen("item_1")) + assert.False(t, tree.IsBranchOpen("item_2")) + assert.False(t, tree.IsBranchOpen("item_1_1")) + assert.False(t, tree.IsBranchOpen("item_1_2")) // Open the node "item_1_2" tree.TypedKey(&fyne.KeyEvent{Name: fyne.KeyRight}) // Validate the state assert.NotNil(t, canvas.Focused()) assert.Equal(t, "item_1_2_1", canvas.Focused().(*Tree).currentFocus) - assert.Equal(t, tree.IsBranchOpen("item_1"), true) - assert.Equal(t, tree.IsBranchOpen("item_2"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_1"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_2"), true) + assert.True(t, tree.IsBranchOpen("item_1")) + assert.False(t, tree.IsBranchOpen("item_2")) + assert.False(t, tree.IsBranchOpen("item_1_1")) + assert.True(t, tree.IsBranchOpen("item_1_2")) // Go to next node "item_1_2_2" tree.TypedKey(&fyne.KeyEvent{Name: fyne.KeyDown}) // Validate the state assert.NotNil(t, canvas.Focused()) assert.Equal(t, "item_1_2_2", canvas.Focused().(*Tree).currentFocus) - assert.Equal(t, tree.IsBranchOpen("item_1"), true) - assert.Equal(t, tree.IsBranchOpen("item_2"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_1"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_2"), true) + assert.True(t, tree.IsBranchOpen("item_1")) + assert.False(t, tree.IsBranchOpen("item_2")) + assert.False(t, tree.IsBranchOpen("item_1_1")) + assert.True(t, tree.IsBranchOpen("item_1_2")) // Press left on the non-branch node "item_1_2_2" tree.TypedKey(&fyne.KeyEvent{Name: fyne.KeyLeft}) // Validate the state assert.NotNil(t, canvas.Focused()) assert.Equal(t, "item_1_2", canvas.Focused().(*Tree).currentFocus) - assert.Equal(t, tree.IsBranchOpen("item_1"), true) - assert.Equal(t, tree.IsBranchOpen("item_2"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_1"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_2"), true) + assert.True(t, tree.IsBranchOpen("item_1")) + assert.False(t, tree.IsBranchOpen("item_2")) + assert.False(t, tree.IsBranchOpen("item_1_1")) + assert.True(t, tree.IsBranchOpen("item_1_2")) // Press left on the open branch node "item_1_2" tree.TypedKey(&fyne.KeyEvent{Name: fyne.KeyLeft}) // Validate the state assert.NotNil(t, canvas.Focused()) assert.Equal(t, "item_1_2", canvas.Focused().(*Tree).currentFocus) - assert.Equal(t, tree.IsBranchOpen("item_1"), true) - assert.Equal(t, tree.IsBranchOpen("item_2"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_1"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_2"), false) + assert.True(t, tree.IsBranchOpen("item_1")) + assert.False(t, tree.IsBranchOpen("item_2")) + assert.False(t, tree.IsBranchOpen("item_1_1")) + assert.False(t, tree.IsBranchOpen("item_1_2")) // Press left on the closed branch node "item_1_2" tree.TypedKey(&fyne.KeyEvent{Name: fyne.KeyLeft}) // Validate the state assert.NotNil(t, canvas.Focused()) assert.Equal(t, "item_1", canvas.Focused().(*Tree).currentFocus) - assert.Equal(t, tree.IsBranchOpen("item_1"), true) - assert.Equal(t, tree.IsBranchOpen("item_2"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_1"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_2"), false) + assert.True(t, tree.IsBranchOpen("item_1")) + assert.False(t, tree.IsBranchOpen("item_2")) + assert.False(t, tree.IsBranchOpen("item_1_1")) + assert.False(t, tree.IsBranchOpen("item_1_2")) // Press left on the open branch node "item_1" tree.TypedKey(&fyne.KeyEvent{Name: fyne.KeyLeft}) // Validate the state assert.NotNil(t, canvas.Focused()) assert.Equal(t, "item_1", canvas.Focused().(*Tree).currentFocus) - assert.Equal(t, tree.IsBranchOpen("item_1"), false) - assert.Equal(t, tree.IsBranchOpen("item_2"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_1"), false) - assert.Equal(t, tree.IsBranchOpen("item_1_2"), false) + assert.False(t, tree.IsBranchOpen("item_1")) + assert.False(t, tree.IsBranchOpen("item_2")) + assert.False(t, tree.IsBranchOpen("item_1_1")) + assert.False(t, tree.IsBranchOpen("item_1_2")) } func TestTree_Indentation(t *testing.T) { @@ -512,7 +512,7 @@ func TestTree_Select(t *testing.T) { } tree.Select("A") - assert.Equal(t, 1, len(tree.selected)) + assert.Len(t, tree.selected, 1) assert.Equal(t, "A", tree.selected[0]) select { case s := <-selection: @@ -536,7 +536,7 @@ func TestTree_Select_Unselects(t *testing.T) { } tree.Select("B") - assert.Equal(t, 1, len(tree.selected)) + assert.Len(t, tree.selected, 1) select { case s := <-unselection: assert.Equal(t, "A", s) @@ -545,10 +545,10 @@ func TestTree_Select_Unselects(t *testing.T) { } tree.Unselect("C") - assert.Equal(t, 1, len(tree.selected)) + assert.Len(t, tree.selected, 1) tree.UnselectAll() - assert.Equal(t, 0, len(tree.selected)) + assert.Empty(t, tree.selected) select { case s := <-unselection: assert.Equal(t, "B", s) @@ -754,7 +754,7 @@ func TestTree_Unselect(t *testing.T) { } tree.Unselect("A") - assert.Equal(t, 0, len(tree.selected)) + assert.Empty(t, tree.selected) select { case s := <-unselection: assert.Equal(t, "A", s) @@ -783,8 +783,8 @@ func TestTree_Walk(t *testing.T) { } }) - assert.Equal(t, 5, len(branches)) - assert.Equal(t, 2, len(leaves)) + assert.Len(t, branches, 5) + assert.Len(t, leaves, 2) assert.Equal(t, "", branches[0]) assert.Equal(t, "A", branches[1]) @@ -810,8 +810,8 @@ func TestTree_Walk(t *testing.T) { } }) - assert.Equal(t, 3, len(branches)) - assert.Equal(t, 0, len(leaves)) + assert.Len(t, branches, 3) + assert.Empty(t, leaves) assert.Equal(t, "", branches[0]) assert.Equal(t, "A", branches[1]) diff --git a/widget/tree_test.go b/widget/tree_test.go index d38a9dd408..826f38ccd7 100644 --- a/widget/tree_test.go +++ b/widget/tree_test.go @@ -43,8 +43,8 @@ func TestNewTreeWithData(t *testing.T) { template := widget.NewLabel("Template Object") - assert.Equal(t, 1000, len(tree.ChildUIDs(""))) - assert.Equal(t, 10, len(tree.ChildUIDs("1"))) + assert.Len(t, tree.ChildUIDs(""), 1000) + assert.Len(t, tree.ChildUIDs("1"), 10) assert.GreaterOrEqual(t, tree.MinSize().Width, template.MinSize().Width) }