variables_test.go 691 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package variables_test
  2. import (
  3. "fmt"
  4. "testing"
  5. "cdop.pt/go/free/platepipe/variables"
  6. . "cdop.pt/go/open/assertive"
  7. )
  8. type m = map[string]any
  9. func TestCoalesce(t *testing.T) {
  10. cases := []struct {
  11. args []m
  12. ret m
  13. }{
  14. {
  15. []m{},
  16. m{},
  17. },
  18. {
  19. []m{{"k": "v"}},
  20. m{"k": "v"},
  21. },
  22. {
  23. []m{{"k": 1}, {"k": 2}},
  24. m{"k": 1},
  25. },
  26. {
  27. []m{{"k1": 1}, {"k2": 2}},
  28. m{"k1": 1, "k2": 2},
  29. },
  30. {
  31. []m{
  32. {"k1": 1, "k2": 2},
  33. {"k2": "ignored", "k3": 3},
  34. {"k3": "ignored", "k4": 4},
  35. },
  36. m{"k1": 1, "k2": 2, "k3": 3, "k4": 4},
  37. },
  38. }
  39. for _, c := range cases {
  40. ret := variables.Coalesce(c.args...)
  41. Want(t, fmt.Sprint(ret) == fmt.Sprint(c.ret))
  42. }
  43. }