@@ -169,3 +169,44 @@ func TestStringer(t *testing.T) {
169
169
EqString (t , "BlockType" , "ClassBlock" , ClassBlock .String ())
170
170
EqString (t , "BlockType" , "BlockType(100)" , BlockType (100 ).String ())
171
171
}
172
+
173
+ func TestSymTableFind (t * testing.T ) {
174
+ st := & SymTable {
175
+ Symbols : Symbols {
176
+ "x" : Symbol {
177
+ Flags : DefLocal | DefNonlocal ,
178
+ Scope : ScopeFree ,
179
+ },
180
+ "a" : Symbol {
181
+ Flags : DefLocal | DefNonlocal ,
182
+ Scope : ScopeFree ,
183
+ },
184
+ "b" : Symbol {
185
+ Flags : DefLocal | DefNonlocal ,
186
+ Scope : ScopeFree ,
187
+ },
188
+ "c" : Symbol {
189
+ Flags : DefNonlocal ,
190
+ Scope : ScopeCell ,
191
+ },
192
+ "d" : Symbol {
193
+ Flags : DefLocal ,
194
+ Scope : ScopeCell ,
195
+ },
196
+ },
197
+ }
198
+
199
+ for _ , test := range []struct {
200
+ scope Scope
201
+ flag DefUseFlags
202
+ want []string
203
+ }{
204
+ {scope : ScopeGlobalExplicit , flag : 0 , want : []string {}},
205
+ {scope : ScopeFree , flag : 0 , want : []string {"a" , "b" , "x" }},
206
+ {scope : ScopeFree , flag : DefLocal , want : []string {"a" , "b" , "d" , "x" }},
207
+ {scope : 0 , flag : DefNonlocal , want : []string {"a" , "b" , "c" , "x" }},
208
+ } {
209
+ got := st .Find (test .scope , test .flag )
210
+ EqStrings (t , fmt .Sprintf ("Scope %v, Flag %v" , test .scope , test .flag ), test .want , got )
211
+ }
212
+ }
0 commit comments