1package x
2
3import (
4	bar "switch/y"
5	barpkg "switch/y"
6)
7
8type Direction int
9
10var (
11	N                Direction = 1
12	E                Direction = 2
13	S                Direction = 3
14	W                Direction = 4
15	directionInvalid Direction = 5
16)
17
18func _a() {
19	// Basic test of same package enum.
20	//
21	// Additionally: unexported members should be included in exhaustiveness
22	// check since enum is in same package.
23
24	var d Direction
25	switch d { // want "missing cases in switch of type Direction: E, directionInvalid"
26	case N:
27	case S:
28	case W:
29	default:
30	}
31}
32
33func _b() {
34	// Basic test of external package enum.
35	//
36	// Additionally: unexported members should not be included in exhaustiveness
37	// check since enum is in external package.
38
39	var p bar.Phylum
40	switch p { // want "missing cases in switch of type bar.Phylum: Mollusca"
41	case bar.Chordata:
42	case bar.Echinodermata:
43	}
44}
45
46func _j() {
47	// Named imports still report real package name.
48
49	var p bar.Phylum
50	switch p { // want "missing cases in switch of type bar.Phylum: Mollusca"
51	case barpkg.Chordata:
52	case barpkg.Echinodermata:
53	}
54}
55
56func _k(d Direction) {
57	// Parenthesized values in case statements.
58
59	switch d { // want "missing cases in switch of type Direction: S, directionInvalid"
60	case (N):
61	case (E):
62	case (W):
63	}
64}
65
66func _f() {
67	// Multiple values in single case.
68
69	var d Direction
70	switch d { // want "missing cases in switch of type Direction: W"
71	case E, directionInvalid, S:
72	default:
73	case N:
74	}
75}
76
77func _g() {
78	// Switch isn't at top-level of function -- should still be checked.
79
80	var d Direction
81	if true {
82		switch d { // want "missing cases in switch of type Direction: S, directionInvalid"
83		case (N):
84		case (E):
85		case (W):
86		}
87	}
88
89	switch d { // want "missing cases in switch of type Direction: E, S, W, directionInvalid"
90	case N:
91		switch d { // want "missing cases in switch of type Direction: N, S, W"
92		case E, directionInvalid:
93		}
94	}
95}
96
97type SortDirection int
98
99const (
100	_ SortDirection = iota
101	Asc
102	Desc
103)
104
105func _n() {
106	var d SortDirection
107	switch d {
108	case Asc:
109	case Desc:
110	}
111}
112
113func _o() {
114	// Selector isn't of the form "enumPkg.enumMember"
115
116	type holdsMollusca struct {
117		Mollusca bar.Phylum // can hold any Phylum value
118	}
119
120	var p bar.Phylum
121	var h holdsMollusca
122
123	switch p { // want "missing cases in switch of type bar.Phylum: Mollusca"
124	case bar.Chordata:
125	case bar.Echinodermata:
126	case h.Mollusca:
127	}
128}
129