smap_test.go 810 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package utl
  2. import (
  3. "testing"
  4. )
  5. func TestSMap(t *testing.T) {
  6. m := NewSMap()
  7. AssertFalse(m.Exists(20), "smap should empty", t)
  8. err := m.Insert("h", "good")
  9. AssertNil(err, "h not exists in smap", t)
  10. val, ok := m.Get("h")
  11. AssertTrue(ok && val == "good", "h==good:"+val.(string), t)
  12. err = m.Insert("h", "ggd")
  13. AssertErr(err, "h exists", t)
  14. m.Set("h", "hh")
  15. _, ok = m.Get("dd")
  16. AssertFalse(ok, "dd should not exists in smap", t)
  17. val, ok = m.Get("h")
  18. AssertTrue(ok, "h exists", t)
  19. AssertTrue(val == "hh", "Set is force", t)
  20. err = m.Update("t", "jj")
  21. AssertErr(err, "t not exists", t)
  22. err = m.Update("h", "jj")
  23. AssertNil(err, "update h", t)
  24. val, ok = m.Get("h")
  25. AssertTrue(ok && val == "jj", "updated h:"+val.(string), t)
  26. m.Del("z")
  27. m.Del("h")
  28. t.Log(m.Keys())
  29. t.Log(m.Values())
  30. }