From 8c12473e7a1073f8edfb737f6837a9a5f7b39e1e Mon Sep 17 00:00:00 2001 From: Moderocky Date: Thu, 23 May 2024 17:33:48 +0100 Subject: [PATCH] Tests for all node syntax. --- .../tests/syntaxes/expressions/ExprConfig.sk | 41 +++++++++++++++++++ .../tests/syntaxes/expressions/ExprName.sk | 27 ++++++++++++ .../tests/syntaxes/expressions/ExprNode.sk | 24 +++++++++++ .../syntaxes/expressions/ExprNodeValue.sk | 30 ++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprConfig.sk create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprNode.sk create mode 100644 src/test/skript/tests/syntaxes/expressions/ExprNodeValue.sk diff --git a/src/test/skript/tests/syntaxes/expressions/ExprConfig.sk b/src/test/skript/tests/syntaxes/expressions/ExprConfig.sk new file mode 100644 index 00000000000..ed0fb693fa2 --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprConfig.sk @@ -0,0 +1,41 @@ +using script reflection + +test "skript config": + set {_config} to the skript config + assert {_config} exists with "config doesn't exist" + + set {_value} to the boolean value at "color codes reset formatting" in {_config} + assert {_value} exists with "navigation failed" + assert {_value} is true with "colour codes do not reset formatting (direct)" + delete {_value} + + set {_node} to the node "number accuracy" of {_config} + set {_value} to the number value of {_node} + assert {_value} is 2 with "number accuracy wasn't 2 (indirect)" + delete {_value} + + set {_node} to the node "effect command token" of {_config} + set {_value} to the text value of {_node} + assert {_value} is "!" with "effect command token (indirect)" + delete {_value} + + set {_node} to the node "language" of {_config} + set {_value} to the text value of {_node} + assert {_value} is "english" with "language (indirect)" + delete {_value} + + set {_count} to 0 + loop the nodes of {_config}: + add 1 to {_count} + assert {_count} is greater than 10 with "too few nodes in config!" + +test "script config": + set {_config} to the current script + set {_node} to node "test ""script config""" of {_config} + set {_line} to the first element of nodes of {_node} + assert name of {_line} is "set {_config} to the current script" with "our first line was wrong" + + set {_count} to 0 + loop the nodes of {_node}: + add 1 to {_count} + assert {_count} is 7 with "wrong number of lines in this section" diff --git a/src/test/skript/tests/syntaxes/expressions/ExprName.sk b/src/test/skript/tests/syntaxes/expressions/ExprName.sk index 17c15b79bb6..03e156ebad9 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprName.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprName.sk @@ -1,5 +1,32 @@ using script reflection +test "config name (new)": + set {_node} to the skript config + set {_node} to node "language" of {_node} + assert name of {_node} is "language" with "config node name was wrong" + + # node in node + set {_node} to the skript config + set {_node} to node "disable hooks.vault" of {_node} + assert name of {_node} is "vault" with "config node name was wrong" + assert "%{_node}%" is "disable hooks.vault" with "config node path was wrong" + +test "node name (new)": + set {_node} to the current script + set {_node} to the first element of nodes of {_node} + assert name of {_node} is "using script reflection" with "first node name was wrong" + + # root node + set {_node} to the skript config + set {_node} to node "language" of {_node} + assert name of {_node} is "language" with "config node name was wrong" + + # node in node + set {_node} to the skript config + set {_node} to node "disable hooks.vault" of {_node} + assert name of {_node} is "vault" with "config node name was wrong" + assert "%{_node}%" is "disable hooks.vault" with "config node path was wrong" + test "script name (new)": set {_name} to the script's name assert the script's name is "ExprName" with "script name is wrong" diff --git a/src/test/skript/tests/syntaxes/expressions/ExprNode.sk b/src/test/skript/tests/syntaxes/expressions/ExprNode.sk new file mode 100644 index 00000000000..09416d0eb90 --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprNode.sk @@ -0,0 +1,24 @@ +using script reflection + +test "node of": + set {_node} to the current script + set {_node} to the first element of nodes of {_node} + assert name of {_node} is "using script reflection" with "first node name was wrong" + assert "%{_node}%" is "using script reflection" with "first node name was wrong" + assert size of (nodes of {_node}) is 0 with "simple node wasn't empty: %nodes of {_node}%" + + set {_node} to the current script + set {_node} to node "test ""node of""" of {_node} # this :) + assert size of (nodes of {_node}) is greater than 0 with "section node was empty" + + # root node + set {_node} to the skript config + set {_node} to node "language" in {_node} + assert name of {_node} is "language" with "config node name was wrong" + assert text value of {_node} is "english" with "config is in wrong language" + + # node in node + set {_node} to the skript config + set {_node} to node "disable hooks.vault" in {_node} + assert text value of {_node} is "false" with "wrong node text value" + assert boolean value of {_node} is false with "wrong node boolean value" diff --git a/src/test/skript/tests/syntaxes/expressions/ExprNodeValue.sk b/src/test/skript/tests/syntaxes/expressions/ExprNodeValue.sk new file mode 100644 index 00000000000..17bd960b0e9 --- /dev/null +++ b/src/test/skript/tests/syntaxes/expressions/ExprNodeValue.sk @@ -0,0 +1,30 @@ +using script reflection + +test "node of": + set {_node} to the current script + set {_node} to the first element of nodes of {_node} + assert text value of {_node} does not exist with "simple node had value?" + + set {_node} to the current script + set {_node} to node "test ""node of""" of {_node} # this :) + assert size of (nodes of {_node}) is greater than 0 with "section node was empty" + + # root node + set {_node} to the skript config + set {_node} to node "language" in {_node} + assert name of {_node} is "language" with "config node name was wrong" + assert text value of {_node} is "english" with "config is in wrong language" + + # node in node + set {_node} to the skript config + set {_node} to node "disable hooks.vault" in {_node} + assert text value of {_node} is "false" with "wrong node text value" + assert boolean value of {_node} is false with "wrong node boolean value" + + # weird type node + set {_node} to node "update check interval" in the skript config + assert text value of {_node} is "12 hours" with "wrong node text value" + set {_time} to {_node}'s timespan value + assert {_time} is 12 hours with "wrong node timespan value" + assert {_time} is greater than 11 hours with "wrong node timespan value" + assert {_time} is less than 13 hours with "wrong node timespan value"