(t *testing.T)
| 323 | } |
| 324 | |
| 325 | func TestErrorf(t *testing.T) { |
| 326 | l := NewState() |
| 327 | BaseOpen(l) |
| 328 | program := "-- script that is bigger than the max ID size\nhelper()\n" + strings.Repeat("--", idSize) |
| 329 | expectedErrorMessage := chunkID(program) + ":2: error" |
| 330 | l.PushGoFunction(func(l *State) int { |
| 331 | Errorf(l, "error") |
| 332 | return 0 |
| 333 | }) |
| 334 | l.SetGlobal("helper") |
| 335 | errorHandled := false |
| 336 | l.PushGoFunction(func(l *State) int { |
| 337 | if l.Top() == 0 { |
| 338 | t.Error("error handler received no arguments") |
| 339 | } else if errorMessage, ok := l.ToString(-1); !ok { |
| 340 | t.Errorf("error handler received %s instead of string", TypeNameOf(l, -1)) |
| 341 | } else if errorMessage != expectedErrorMessage { |
| 342 | t.Errorf("error handler received '%s' instead of '%s'", errorMessage, expectedErrorMessage) |
| 343 | } |
| 344 | errorHandled = true |
| 345 | return 1 |
| 346 | }) |
| 347 | LoadString(l, program) |
| 348 | l.ProtectedCall(0, 0, -2) |
| 349 | if !errorHandled { |
| 350 | t.Error("error not handled") |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | func TestPairsSplit(t *testing.T) { |
| 355 | testString(t, ` |
nothing calls this directly
no test coverage detected