Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for item syntaxes. #6164

Merged
merged 9 commits into from
Jul 1, 2024
14 changes: 14 additions & 0 deletions src/test/skript/tests/syntaxes/expressions/ExprAmountOfItems.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
test "amount of items":
set {_inventory} to a hopper inventory named "test"
assert the amount of stone in {_inventory} is 0 with "default amount failed"
add stone to {_inventory}
assert the amount of stone in {_inventory} is 1 with "single amount failed"
add stone named "bread" to {_inventory}
assert the amount of stone in {_inventory} is 2 with "different named items amount failed"
add 100 of iron ingot to {_inventory}
assert the amount of stone in {_inventory} is 2 with "add different item amount failed"
assert the amount of iron ingot in {_inventory} is 100 with "add 100 item amount failed"
remove stone from {_inventory}
assert the amount of stone in {_inventory} is 1 with "removed one amount failed"
remove stone from {_inventory}
assert the amount of stone in {_inventory} is 0 with "removed all amount failed"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test "item with custom model data" when minecraft version is not "1.13.2":
set {_i} to stone
assert the custom model data of {_i} is 0 with "default model data failed"
set {_i} to stone with custom model data 5
assert the custom model data of {_i} is 5 with "simple model data set failed"
set {_i} to stone with custom model data -1
assert the custom model data of {_i} is -1 with "negative model data set failed"
set {_i} to {_i} with custom model data 2
assert the custom model data of {_i} is 2 with "existing item model data set failed"
set {_i} to {_i} with custom model data 3.3
assert the custom model data of {_i} is 3 with "decimal item model data set failed"
set {_i} to {_i} with custom model data 3.999
assert the custom model data of {_i} is 3 with "close decimal item model data set failed"
27 changes: 27 additions & 0 deletions src/test/skript/tests/syntaxes/expressions/ExprItemsIn.sk
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

test "items in (inventory)":
set {_inventory} to a hopper inventory named "test"
add stone to {_inventory}
add stone named "bread" to {_inventory}
add 100 of iron ingot to {_inventory}
loop items in {_inventory}:
if loop-value is stone:
continue
else if loop-value is iron ingot:
continue
else:
assert true is false with "unexpected item in the inventory area: %loop-value%"
set {_list::*} to items in {_inventory}
assert size of {_list::*} is 4 with "size of items in failed: %size of {_list::*}%"
assert {_list::1} is stone with "first item failed: %{_list::1}%"
assert {_list::2} is stone named "bread" with "second item failed: %{_list::2}%"
assert {_list::3} is 64 of iron ingot with "third item failed: %{_list::3}%"
assert {_list::4} is 36 of iron ingot with "split fourth item failed: %{_list::4}%"
remove stone from {_inventory}
set {_list::*} to items in {_inventory}
assert size of {_list::*} is 3 with "size of second items in failed: %size of {_list::*}%"
assert {_list::1} is stone named "bread" with "new first item failed: %{_list::1}%"
assert {_list::2} is 64 of iron ingot with "new second item failed: %{_list::2}%"
assert {_list::3} is 36 of iron ingot with "new third item failed: %{_list::3}%"
Moderocky marked this conversation as resolved.
Show resolved Hide resolved

test "filtering ExprItemsIn":
set {_world} to random world out of all worlds
set block at spawn of {_world} to chest
Expand All @@ -19,3 +45,4 @@ test "unfiltered ExprItemsIn":
set slot 3 of {_inv} to bucket
assert all items in inventory {_inv} are dirt, stone or bucket with "found correct items with ExprItemsIn##get"
assert (all items in inventory {_inv} where [true is true]) are dirt, stone or bucket with "found correct items with ExprItemsIn##iterator"

Loading