Skip to content
Prev Previous commit
Next Next commit
feat: add pointer tests
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
  • Loading branch information
sagikazarmark committed May 31, 2025
commit 659da110d64284ed1a4a0d7b82bb0f194f22de75
128 changes: 99 additions & 29 deletions cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,107 @@ func runTests[T cast.Basic](t *testing.T, testCases []testCase, to func(i any) T
testCase := testCase

t.Run("", func(t *testing.T) {
c := qt.New(t)

{
v := to(testCase.input)
c.Assert(v, qt.Equals, testCase.expected)
}

{
v := cast.To[T](testCase.input)
c.Assert(v, qt.Equals, testCase.expected)
}

{
v, err := toErr(testCase.input)
if testCase.expectError {
c.Assert(err, qt.IsNotNil)
} else {
c.Assert(err, qt.IsNil)
t.Parallel()

t.Run("Value", func(t *testing.T) {
t.Run("ToType", func(t *testing.T) {
t.Parallel()

c := qt.New(t)

v := to(testCase.input)
c.Assert(v, qt.Equals, testCase.expected)
}
}

{
v, err := cast.ToE[T](testCase.input)
if testCase.expectError {
c.Assert(err, qt.IsNotNil)
} else {
c.Assert(err, qt.IsNil)
})

t.Run("To", func(t *testing.T) {
t.Parallel()

c := qt.New(t)

v := cast.To[T](testCase.input)
c.Assert(v, qt.Equals, testCase.expected)
}
}
})

t.Run("ToTypeE", func(t *testing.T) {
t.Parallel()

c := qt.New(t)

v, err := toErr(testCase.input)
if testCase.expectError {
c.Assert(err, qt.IsNotNil)
} else {
c.Assert(err, qt.IsNil)
c.Assert(v, qt.Equals, testCase.expected)
}
})

t.Run("ToE", func(t *testing.T) {
t.Parallel()

c := qt.New(t)

v, err := cast.ToE[T](testCase.input)
if testCase.expectError {
c.Assert(err, qt.IsNotNil)
} else {
c.Assert(err, qt.IsNil)
c.Assert(v, qt.Equals, testCase.expected)
}
})
})

t.Run("", func(t *testing.T) {
t.Parallel()

t.Run("Value", func(t *testing.T) {
t.Run("ToType", func(t *testing.T) {
t.Parallel()

c := qt.New(t)

v := to(&testCase.input)
c.Assert(v, qt.Equals, testCase.expected)
})

t.Run("To", func(t *testing.T) {
t.Parallel()

c := qt.New(t)

v := cast.To[T](&testCase.input)
c.Assert(v, qt.Equals, testCase.expected)
})

t.Run("ToTypeE", func(t *testing.T) {
t.Parallel()

c := qt.New(t)

v, err := toErr(&testCase.input)
if testCase.expectError {
c.Assert(err, qt.IsNotNil)
} else {
c.Assert(err, qt.IsNil)
c.Assert(v, qt.Equals, testCase.expected)
}
})

t.Run("ToE", func(t *testing.T) {
t.Parallel()

c := qt.New(t)

v, err := cast.ToE[T](&testCase.input)
if testCase.expectError {
c.Assert(err, qt.IsNotNil)
} else {
c.Assert(err, qt.IsNil)
c.Assert(v, qt.Equals, testCase.expected)
}
})
})
})
})
}
}