Skip to content

Commit

Permalink
Test type switch statement with struct and interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Jan 7, 2023
1 parent 713cd5c commit 6883791
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
10 changes: 4 additions & 6 deletions testdata/instrumenter/TypeSwitchStmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,14 @@ func typeSwitchStmt(tag interface{}, value interface{}) string {
case []int:
return "slice of int"

// FIXME: Currently leads to a stack overflow error
// case struct{}:
// return "struct with field"
case struct{ field int }:
return "struct with field"

case func(int) int:
return "function taking int and returning int"

// FIXME: Currently leads to a stack overflow error
// case interface{ ReadByte() (byte, error) }:
// return "interface with ReadByte"
case interface{ ReadByte() (byte, error) }:
return "interface with ReadByte"

case map[int]int:
return "map from int to int"
Expand Down
66 changes: 37 additions & 29 deletions testdata/instrumenter/TypeSwitchStmt.gobco
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func typeSwitchStmt(tag interface{}, value interface{}) string {

// TODO: Test type parameters and generic types.

switch _ = GobcoCover(20, 123 > 0); {
switch _ = GobcoCover(22, 123 > 0); {
default:
gobco11 := value
_, gobco12 := gobco11.(int)
Expand All @@ -115,10 +115,12 @@ func typeSwitchStmt(tag interface{}, value interface{}) string {
gobco17 := gobco11 == nil
_, gobco18 := gobco11.([3]int)
_, gobco19 := gobco11.([]int)
_, gobco20 := gobco11.(func(int) int)
_, gobco21 := gobco11.(map[int]int)
_, gobco22 := gobco11.(chan int)
_, gobco23 := gobco11.(*int)
_, gobco20 := gobco11.(struct{ field int })
_, gobco21 := gobco11.(func(int) int)
_, gobco22 := gobco11.(interface{ ReadByte() (byte, error) })
_, gobco23 := gobco11.(map[int]int)
_, gobco24 := gobco11.(chan int)
_, gobco25 := gobco11.(*int)
switch {

case GobcoCover(6, gobco12), GobcoCover(7, gobco13):
Expand Down Expand Up @@ -168,33 +170,37 @@ func typeSwitchStmt(tag interface{}, value interface{}) string {

return "slice of int"

// FIXME: Currently leads to a stack overflow error
// case struct{}:
// return "struct with field"

case GobcoCover(14, gobco20):
v := gobco11.(struct{ field int })
_ = v

return "struct with field"

case GobcoCover(15, gobco21):
v := gobco11.(func(int) int)
_ = v

return "function taking int and returning int"

// FIXME: Currently leads to a stack overflow error
// case interface{ ReadByte() (byte, error) }:
// return "interface with ReadByte"
case GobcoCover(16, gobco22):
v := gobco11.(interface{ ReadByte() (byte, error) })
_ = v

return "interface with ReadByte"

case GobcoCover(15, gobco21):
case GobcoCover(17, gobco23):
v := gobco11.(map[int]int)
_ = v

return "map from int to int"

case GobcoCover(16, gobco22):
case GobcoCover(18, gobco24):
v := gobco11.(chan int)
_ = v

return "chan of int"

case GobcoCover(17, gobco23):
case GobcoCover(19, gobco25):
v := gobco11.(*int)
_ = v

Expand All @@ -221,10 +227,10 @@ func typeSwitchStmtMixed(value interface{}) {
_, gobco1 := gobco0.(int)
_, gobco2 := gobco0.(uint)
switch {
case GobcoCover(18, gobco1):
_ = GobcoCover(21, true) && GobcoCover(22, false)
case GobcoCover(19, gobco2):
_ = GobcoCover(23, false) || GobcoCover(24, true)
case GobcoCover(20, gobco1):
_ = GobcoCover(23, true) && GobcoCover(24, false)
case GobcoCover(21, gobco2):
_ = GobcoCover(25, false) || GobcoCover(26, true)
}
}

Expand All @@ -244,14 +250,16 @@ func typeSwitchStmtMixed(value interface{}) {
// :89:7: "value.(type) == nil"
// :92:7: "value.(type) == [3]int"
// :95:7: "value.(type) == []int"
// :102:7: "value.(type) == func(int) int"
// :109:7: "value.(type) == map[int]int"
// :112:7: "value.(type) == chan int"
// :115:7: "value.(type) == *int"
// :130:7: "value.(type) == int"
// :132:7: "value.(type) == uint"
// :98:7: "value.(type) == struct{ field int }"
// :101:7: "value.(type) == func(int) int"
// :104:7: "value.(type) == (interface{ ReadByte() (byte, error) })"
// :107:7: "value.(type) == map[int]int"
// :110:7: "value.(type) == chan int"
// :113:7: "value.(type) == *int"
// :128:7: "value.(type) == int"
// :130:7: "value.(type) == uint"
// :70:13: "123 > 0"
// :131:7: "true"
// :131:15: "false"
// :133:7: "false"
// :133:16: "true"
// :129:7: "true"
// :129:15: "false"
// :131:7: "false"
// :131:16: "true"

0 comments on commit 6883791

Please sign in to comment.