Skip to content

Commit

Permalink
整理reflection章节
Browse files Browse the repository at this point in the history
  • Loading branch information
william's mac committed Nov 24, 2019
1 parent 0242318 commit 64f8430
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 318 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
10. [Mocking](mocking.md) - 学习使用mock测试,覆盖那些使用常规测试无法覆盖的代码。
11. [并发](concurrency.md) - 学习如何写并发程序,让软件运行更快。
12. [选择Select](select.md) - 学习如何优雅地在进程间进行同步。
13. [Reflection](reflection.md) - Learn about reflection
13. [反射](reflection.md) - 学习反射。
14. [Sync](sync.md) - Learn some functionality from the sync package including `WaitGroup` and `Mutex`
15. [Context](context.md) - Use the context package to manage and cancel long-running processes
16. [Intro to property based tests](roman-numerals.md) - Practice some TDD with the Roman Numerals kata and get a brief intro to property based tests
Expand Down
392 changes: 167 additions & 225 deletions reflection.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions reflection/v1/reflection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func TestWalk(t *testing.T) {
"Struct with one string field",
struct {
Name string
}{"Chris"},
[]string{"Chris"},
}{"Bobo"},
[]string{"Bobo"},
},
}

Expand All @@ -29,7 +29,7 @@ func TestWalk(t *testing.T) {
})

if !reflect.DeepEqual(got, test.ExpectedCalls) {
t.Errorf("got %v, want %v", got, test.ExpectedCalls)
t.Errorf("got %v, expect %v", got, test.ExpectedCalls)
}
})
}
Expand Down
10 changes: 5 additions & 5 deletions reflection/v2/reflection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ func TestWalk(t *testing.T) {
"Struct with one string field",
struct {
Name string
}{"Chris"},
[]string{"Chris"},
}{"Bobo"},
[]string{"Bobo"},
},
{
"Struct with two string fields",
struct {
Name string
City string
}{"Chris", "London"},
[]string{"Chris", "London"},
}{"Bobo", "Shanghai"},
[]string{"Bobo", "Shanghai"},
},
}

Expand All @@ -37,7 +37,7 @@ func TestWalk(t *testing.T) {
})

if !reflect.DeepEqual(got, test.ExpectedCalls) {
t.Errorf("got %v, want %v", got, test.ExpectedCalls)
t.Errorf("got %v, expect %v", got, test.ExpectedCalls)
}
})
}
Expand Down
14 changes: 7 additions & 7 deletions reflection/v3/reflection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ func TestWalk(t *testing.T) {
}{
{
"Struct with one string field",
struct{ Name string }{"Chris"},
[]string{"Chris"},
struct{ Name string }{"Bobo"},
[]string{"Bobo"},
},
{
"Struct with two string fields",
struct {
Name string
City string
}{"Chris", "London"},
[]string{"Chris", "London"},
}{"Bobo", "Shanghai"},
[]string{"Bobo", "Shanghai"},
},
{
"Struct with non string field",
struct {
Name string
Age int
}{"Chris", 33},
[]string{"Chris"},
}{"Bobo", 33},
[]string{"Bobo"},
},
}

Expand All @@ -43,7 +43,7 @@ func TestWalk(t *testing.T) {
})

if !reflect.DeepEqual(got, test.ExpectedCalls) {
t.Errorf("got %v, want %v", got, test.ExpectedCalls)
t.Errorf("got %v, expect %v", got, test.ExpectedCalls)
}
})
}
Expand Down
20 changes: 10 additions & 10 deletions reflection/v4/reflection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@ func TestWalk(t *testing.T) {
}{
{
"Struct with one string field",
struct{ Name string }{"Chris"},
[]string{"Chris"},
struct{ Name string }{"Bobo"},
[]string{"Bobo"},
},
{
"Struct with two string fields",
struct {
Name string
City string
}{"Chris", "London"},
[]string{"Chris", "London"},
}{"Bobo", "Shanghai"},
[]string{"Bobo", "Shanghai"},
},
{
"Struct with non string field",
struct {
Name string
Age int
}{"Chris", 33},
[]string{"Chris"},
}{"Bobo", 33},
[]string{"Bobo"},
},
{
"Nested fields",
Person{
"Chris",
Profile{33, "London"},
"Bobo",
Profile{33, "Shanghai"},
},
[]string{"Chris", "London"},
[]string{"Bobo", "Shanghai"},
},
}

Expand All @@ -51,7 +51,7 @@ func TestWalk(t *testing.T) {
})

if !reflect.DeepEqual(got, test.ExpectedCalls) {
t.Errorf("got %v, want %v", got, test.ExpectedCalls)
t.Errorf("got %v, expect %v", got, test.ExpectedCalls)
}
})
}
Expand Down
26 changes: 13 additions & 13 deletions reflection/v5/reflection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@ func TestWalk(t *testing.T) {
}{
{
"Struct with one string field",
struct{ Name string }{"Chris"},
[]string{"Chris"},
struct{ Name string }{"Bobo"},
[]string{"Bobo"},
},
{
"Struct with two string fields",
struct {
Name string
City string
}{"Chris", "London"},
[]string{"Chris", "London"},
}{"Bobo", "Shanghai"},
[]string{"Bobo", "Shanghai"},
},
{
"Struct with non string field",
struct {
Name string
Age int
}{"Chris", 33},
[]string{"Chris"},
}{"Bobo", 33},
[]string{"Bobo"},
},
{
"Nested fields",
Person{
"Chris",
Profile{33, "London"},
"Bobo",
Profile{33, "Shanghai"},
},
[]string{"Chris", "London"},
[]string{"Bobo", "Shanghai"},
},
{
"Pointers to things",
&Person{
"Chris",
Profile{33, "London"},
"Bobo",
Profile{33, "Shanghai"},
},
[]string{"Chris", "London"},
[]string{"Bobo", "Shanghai"},
},
}

Expand All @@ -59,7 +59,7 @@ func TestWalk(t *testing.T) {
})

if !reflect.DeepEqual(got, test.ExpectedCalls) {
t.Errorf("got %v, want %v", got, test.ExpectedCalls)
t.Errorf("got %v, expect %v", got, test.ExpectedCalls)
}
})
}
Expand Down
32 changes: 16 additions & 16 deletions reflection/v6/reflection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,48 @@ func TestWalk(t *testing.T) {
}{
{
"Struct with one string field",
struct{ Name string }{"Chris"},
[]string{"Chris"},
struct{ Name string }{"Bobo"},
[]string{"Bobo"},
},
{
"Struct with two string fields",
struct {
Name string
City string
}{"Chris", "London"},
[]string{"Chris", "London"},
}{"Bobo", "Shanghai"},
[]string{"Bobo", "Shanghai"},
},
{
"Struct with non string field",
struct {
Name string
Age int
}{"Chris", 33},
[]string{"Chris"},
}{"Bobo", 33},
[]string{"Bobo"},
},
{
"Nested fields",
Person{
"Chris",
Profile{33, "London"},
"Bobo",
Profile{33, "Shanghai"},
},
[]string{"Chris", "London"},
[]string{"Bobo", "Shanghai"},
},
{
"Pointers to things",
&Person{
"Chris",
Profile{33, "London"},
"Bobo",
Profile{33, "Shanghai"},
},
[]string{"Chris", "London"},
[]string{"Bobo", "Shanghai"},
},
{
"Slices",
[]Profile{
{33, "London"},
{34, "Reykjavík"},
{33, "Shanghai"},
{34, "Beijing"},
},
[]string{"London", "Reykjavík"},
[]string{"Shanghai", "Beijing"},
},
}

Expand All @@ -67,7 +67,7 @@ func TestWalk(t *testing.T) {
})

if !reflect.DeepEqual(got, test.ExpectedCalls) {
t.Errorf("got %v, want %v", got, test.ExpectedCalls)
t.Errorf("got %v, expect %v", got, test.ExpectedCalls)
}
})
}
Expand Down
38 changes: 19 additions & 19 deletions reflection/v7/reflection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,56 @@ func TestWalk(t *testing.T) {
}{
{
"Struct with one string field",
struct{ Name string }{"Chris"},
[]string{"Chris"},
struct{ Name string }{"Bobo"},
[]string{"Bobo"},
},
{
"Struct with two string fields",
struct {
Name string
City string
}{"Chris", "London"},
[]string{"Chris", "London"},
}{"Bobo", "Shanghai"},
[]string{"Bobo", "Shanghai"},
},
{
"Struct with non string field",
struct {
Name string
Age int
}{"Chris", 33},
[]string{"Chris"},
}{"Bobo", 33},
[]string{"Bobo"},
},
{
"Nested fields",
Person{
"Chris",
Profile{33, "London"},
"Bobo",
Profile{33, "Shanghai"},
},
[]string{"Chris", "London"},
[]string{"Bobo", "Shanghai"},
},
{
"Pointers to things",
&Person{
"Chris",
Profile{33, "London"},
"Bobo",
Profile{33, "Shanghai"},
},
[]string{"Chris", "London"},
[]string{"Bobo", "Shanghai"},
},
{
"Slices",
[]Profile{
{33, "London"},
{34, "Reykjavík"},
{33, "Shanghai"},
{34, "Beijing"},
},
[]string{"London", "Reykjavík"},
[]string{"Shanghai", "Beijing"},
},
{
"Arrays",
[2]Profile{
{33, "London"},
{34, "Reykjavík"},
{33, "Shanghai"},
{34, "Beijing"},
},
[]string{"London", "Reykjavík"},
[]string{"Shanghai", "Beijing"},
},
}

Expand All @@ -75,7 +75,7 @@ func TestWalk(t *testing.T) {
})

if !reflect.DeepEqual(got, test.ExpectedCalls) {
t.Errorf("got %v, want %v", got, test.ExpectedCalls)
t.Errorf("got %v, expect %v", got, test.ExpectedCalls)
}
})
}
Expand Down
Loading

0 comments on commit 64f8430

Please sign in to comment.