Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal struct don't work #63

Open
lougxing opened this issue Apr 19, 2024 · 0 comments
Open

internal struct don't work #63

lougxing opened this issue Apr 19, 2024 · 0 comments

Comments

@lougxing
Copy link

lougxing commented Apr 19, 2024

`import (
"fmt"
"testing"

"github.com/go-test/deep"

. "github.com/smartystreets/goconvey/convey"

)

func TestStructCompare(t *testing.T) {

type BB struct {
    i_BB int
    I_BB int
    S_BB string
    M_BB map[string]string
    A_BB []int
}

type AA struct {
    i_AA int
    I_AA int
    S_AA string
    M_AA map[string]string
    A_AA []int
    P_AA *BB
    B_AA BB
}

Convey("test struct compare", t, func() {
    a1 := AA{}
    a2 := AA{}

    a1.I_AA = 1
    a1.S_AA = "cc"
    a1.M_AA = map[string]string{"1": "2"}
    a1.A_AA = []int{3, 4}
    a1.P_AA = &BB{I_BB: 21, M_BB: map[string]string{"15": "6"}}
    a1.B_AA = BB{I_BB: 21, M_BB: map[string]string{"15": "6"}, A_BB: []int{1, 2}}

    a2.I_AA = 2
    a2.S_AA = "dd"
    a2.M_AA = map[string]string{"5": "6"}
    a2.A_AA = []int{7, 8}
    a2.P_AA = &BB{I_BB: 21, M_BB: map[string]string{"25": "6"}}

    a2.B_AA = BB{I_BB: 21, M_BB: map[string]string{"25": "6"}, A_BB: []int{3, 4}}

    fmt.Println()
    fmt.Printf("%+v \n", a1)
    fmt.Printf("%+v \n", a2)

    if diff := deep.Equal(a1, a2); diff != nil {
        for i, s := range diff {
            fmt.Println(i, s)

        }
        t.Error(diff)
    }
})

}`
output:

{i_AA:0 I_AA:1 S_AA:cc M_AA:map[1:2] A_AA:[3 4] P_AA:0x140009aaf00 B_AA:{i_BB:0 I_BB:21 S_BB: M_BB:map[15:6] A_BB:[1 2]}}
{i_AA:0 I_AA:2 S_AA:dd M_AA:map[5:6] A_AA:[7 8] P_AA:0x140009aaf40 B_AA:{i_BB:0 I_BB:21 S_BB: M_BB:map[25:6] A_BB:[3 4]}}
0 I_AA: 1 != 2
1 S_AA: cc != dd
2 M_AA.map[1]: 2 !=
3 M_AA.map[5]: != 6
4 A_AA.slice[0]: 3 != 7
5 A_AA.slice[1]: 4 != 8
6 P_AA.M_BB.map[15]: 6 !=
7 P_AA.M_BB.map[25]: != 6
8 B_AA.M_BB.map[15]: 6 !=
9 B_AA.M_BB.map[25]: != 6

BB.A_BB is diff,but no.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant