(t *testing.T)
| 431 | } |
| 432 | |
| 433 | func TestMap_Callback(t *testing.T) { |
| 434 | called := map[string]int{} |
| 435 | |
| 436 | cfg := Node{ |
| 437 | Children: []Node{ |
| 438 | { |
| 439 | Name: "test2", |
| 440 | Args: []string{"a"}, |
| 441 | }, |
| 442 | { |
| 443 | Name: "test3", |
| 444 | Args: []string{"b"}, |
| 445 | }, |
| 446 | { |
| 447 | Name: "test3", |
| 448 | Args: []string{"b"}, |
| 449 | }, |
| 450 | { |
| 451 | Name: "unrelated", |
| 452 | Args: []string{"b"}, |
| 453 | }, |
| 454 | }, |
| 455 | } |
| 456 | m := NewMap(nil, cfg) |
| 457 | m.Callback("test1", func(*Map, Node) error { |
| 458 | called["test1"]++ |
| 459 | return nil |
| 460 | }) |
| 461 | m.Callback("test2", func(_ *Map, n Node) error { |
| 462 | called["test2"]++ |
| 463 | if n.Args[0] != "a" { |
| 464 | t.Fatal("Wrong n.Args[0] for test2:", n.Args[0]) |
| 465 | } |
| 466 | return nil |
| 467 | }) |
| 468 | m.Callback("test3", func(_ *Map, n Node) error { |
| 469 | called["test3"]++ |
| 470 | if n.Args[0] != "b" { |
| 471 | t.Fatal("Wrong n.Args[0] for test2:", n.Args[0]) |
| 472 | } |
| 473 | return nil |
| 474 | }) |
| 475 | m.AllowUnknown() |
| 476 | others, err := m.Process() |
| 477 | if err != nil { |
| 478 | t.Fatal("Unexpected error:", err) |
| 479 | } |
| 480 | if called["test1"] != 0 { |
| 481 | t.Error("test1 CB was called when it should not") |
| 482 | } |
| 483 | if called["test2"] != 1 { |
| 484 | t.Error("test2 CB was not called when it should") |
| 485 | } |
| 486 | if called["test3"] != 2 { |
| 487 | t.Error("test3 CB was not called when it should") |
| 488 | } |
| 489 | if len(others) != 1 { |
| 490 | t.Error("Wrong amount of unmatched directives") |
nothing calls this directly
no test coverage detected