forked from minetest/minetest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MetaData: restore undocumented set_string behaviour
- Loading branch information
1 parent
e3cc26c
commit 52ba4d8
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
do | ||
-- MetaData test | ||
local stack = ItemStack("air 20") | ||
local meta = stack:get_meta() | ||
|
||
-- key/value removal using set_string (undocumented, deprecated way) | ||
meta:set_string("key", "value") | ||
assert(meta:get_string("key") == "value") | ||
meta:set_string("key", nil) -- ignore warning | ||
assert(meta:to_table().fields["key"] == nil) | ||
|
||
-- undocumented consequence of Lua's automatic string <--> number cast | ||
meta:set_string("key", 2) | ||
assert(meta:get_string("key") == "2") | ||
|
||
-- Getters for inexistent keys | ||
assert(meta:get_string("notfound") == "") | ||
assert(meta:get_int("notfound") == 0) | ||
assert(meta:get("notfound") == nil) | ||
|
||
-- key/value removal using set_string (correct way) | ||
meta:set_string("key", "value2") | ||
assert(meta:get_string("key") == "value2") | ||
meta:set_string("key", "") | ||
assert(meta:to_table().fields["key"] == nil) | ||
|
||
-- from_table | ||
local values = meta:to_table() | ||
values.fields["new"] = 420 | ||
meta:from_table(values) | ||
assert(meta:get_int("new") == 420) | ||
values.fields["new"] = nil | ||
meta:from_table(values) | ||
assert(meta:get("new") == nil) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name = testmetadata | ||
description = Tests for MetaDataRef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters