itemstack_equals.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. local function test_itemstack_equals_non_stack()
  2. local i1 = ItemStack("basenodes:stone")
  3. local i2 = { foo = "bar" }
  4. assert(not i1:equals(i2))
  5. assert(i1 ~= i2)
  6. assert(i2 ~= i1)
  7. end
  8. unittests.register("test_itemstack_equals_non_stack", test_itemstack_equals_non_stack)
  9. local function test_itemstack_equals_name()
  10. local i1 = ItemStack("basenodes:stone")
  11. local i2 = ItemStack("basenodes:desert_stone")
  12. assert(not i1:equals(i2))
  13. assert(i1 ~= i2)
  14. end
  15. unittests.register("test_itemstack_equals_name", test_itemstack_equals_name)
  16. local function test_itemstack_equals_count()
  17. local i1 = ItemStack("basenodes:stone")
  18. local i2 = ItemStack("basenodes:stone 2")
  19. assert(not i1:equals(i2))
  20. assert(i1 ~= i2)
  21. end
  22. unittests.register("test_itemstack_equals_count", test_itemstack_equals_count)
  23. local function test_itemstack_equals_wear()
  24. local i1 = ItemStack("basetools:axe_stone")
  25. local i2 = ItemStack("basetools:axe_stone")
  26. i2:add_wear(1)
  27. assert(not i1:equals(i2))
  28. assert(i1 ~= i2)
  29. end
  30. unittests.register("test_itemstack_equals_wear", test_itemstack_equals_wear)
  31. local function test_itemstack_equals_metadata()
  32. local i1 = ItemStack("basenodes:stone")
  33. local i2 = ItemStack("basenodes:stone")
  34. local i3 = ItemStack("basenodes:stone")
  35. local m1 = i1:get_meta()
  36. local m2 = i2:get_meta()
  37. local m3 = i3:get_meta()
  38. local keys = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"}
  39. local values = {}
  40. for i, key in pairs(keys) do
  41. m1:set_int(key, i)
  42. m3:set_int(key, i)
  43. values[key] = i
  44. end
  45. m3:set_int("a", 999)
  46. for key, i in pairs(values) do
  47. m2:set_int(key, i)
  48. end
  49. assert(i1:equals(i2))
  50. assert(i1 == i2)
  51. assert(not i1:equals(i3))
  52. assert(i1 ~= i3)
  53. end
  54. unittests.register("test_itemstack_equals_metadata", test_itemstack_equals_metadata)