MCPcopy Index your code
hub / github.com/yuin/gopher-lua / TestTableForEach

Function TestTableForEach

table_test.go:181–233  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

179}
180
181func TestTableForEach(t *testing.T) {
182 tbl := newLTable(0, 0)
183 tbl.Append(LNumber(1))
184 tbl.Append(LNumber(2))
185 tbl.Append(LNumber(3))
186 tbl.Append(LNil)
187 tbl.Append(LNumber(5))
188
189 tbl.RawSetH(LString("a"), LString("a"))
190 tbl.RawSetH(LString("b"), LString("b"))
191 tbl.RawSetH(LString("c"), LString("c"))
192
193 tbl.RawSetH(LTrue, LString("true"))
194 tbl.RawSetH(LFalse, LString("false"))
195
196 tbl.ForEach(func(key, value LValue) {
197 switch k := key.(type) {
198 case LBool:
199 switch bool(k) {
200 case true:
201 errorIfNotEqual(t, LString("true"), value)
202 case false:
203 errorIfNotEqual(t, LString("false"), value)
204 default:
205 t.Fail()
206 }
207 case LNumber:
208 switch int(k) {
209 case 1:
210 errorIfNotEqual(t, LNumber(1), value)
211 case 2:
212 errorIfNotEqual(t, LNumber(2), value)
213 case 3:
214 errorIfNotEqual(t, LNumber(3), value)
215 case 4:
216 errorIfNotEqual(t, LNumber(5), value)
217 default:
218 t.Fail()
219 }
220 case LString:
221 switch string(k) {
222 case "a":
223 errorIfNotEqual(t, LString("a"), value)
224 case "b":
225 errorIfNotEqual(t, LString("b"), value)
226 case "c":
227 errorIfNotEqual(t, LString("c"), value)
228 default:
229 t.Fail()
230 }
231 }
232 })
233}

Callers

nothing calls this directly

Calls 7

newLTableFunction · 0.85
LNumberTypeAlias · 0.85
LStringTypeAlias · 0.85
errorIfNotEqualFunction · 0.85
AppendMethod · 0.80
RawSetHMethod · 0.80
ForEachMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…