From 191bbf15bb8d32230ec9d17bd62a8d2d92afaeea Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sat, 25 Mar 2023 17:26:16 +0100 Subject: [PATCH] Implement more tests for instance methods --- tests/roblox/instance/methods/Destroy.luau | 35 +++++++++++++++++++ tests/roblox/instance/methods/IsA.luau | 27 ++++++++++++++ .../roblox/instance/methods/IsAncestorOf.luau | 21 +++++++++++ .../instance/methods/IsDescendantOf.luau | 21 +++++++++++ 4 files changed, 104 insertions(+) create mode 100644 tests/roblox/instance/methods/Destroy.luau create mode 100644 tests/roblox/instance/methods/IsA.luau create mode 100644 tests/roblox/instance/methods/IsAncestorOf.luau create mode 100644 tests/roblox/instance/methods/IsDescendantOf.luau diff --git a/tests/roblox/instance/methods/Destroy.luau b/tests/roblox/instance/methods/Destroy.luau new file mode 100644 index 0000000..113fead --- /dev/null +++ b/tests/roblox/instance/methods/Destroy.luau @@ -0,0 +1,35 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local root = Instance.new("Folder") +local child = Instance.new("Model") +local descendant = Instance.new("Part") + +child.Parent = root +descendant.Parent = child + +root:Destroy() + +assert(not pcall(function() + return root.Name +end)) + +assert(not pcall(function() + return root.Parent +end)) + +assert(not pcall(function() + return child.Name +end)) + +assert(not pcall(function() + return child.Parent +end)) + +assert(not pcall(function() + return descendant.Name +end)) + +assert(not pcall(function() + return descendant.Parent +end)) diff --git a/tests/roblox/instance/methods/IsA.luau b/tests/roblox/instance/methods/IsA.luau new file mode 100644 index 0000000..1732af4 --- /dev/null +++ b/tests/roblox/instance/methods/IsA.luau @@ -0,0 +1,27 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local part = Instance.new("Part") +local workspace = Instance.new("Workspace") + +-- Valid + +assert(part:IsA("Part") == true) +assert(part:IsA("BasePart") == true) +assert(part:IsA("PVInstance") == true) +assert(part:IsA("Instance") == true) + +assert(workspace:IsA("Workspace") == true) +assert(workspace:IsA("Model") == true) +assert(workspace:IsA("Instance") == true) + +-- Invalid + +assert(part:IsA("part") == false) +assert(part:IsA("Base-Part") == false) +assert(part:IsA("Model") == false) +assert(part:IsA("Paart") == false) + +assert(workspace:IsA("Service") == false) +assert(workspace:IsA(".") == false) +assert(workspace:IsA("") == false) diff --git a/tests/roblox/instance/methods/IsAncestorOf.luau b/tests/roblox/instance/methods/IsAncestorOf.luau new file mode 100644 index 0000000..a482c97 --- /dev/null +++ b/tests/roblox/instance/methods/IsAncestorOf.luau @@ -0,0 +1,21 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local root = Instance.new("Folder") +local child = Instance.new("Model") +local descendant = Instance.new("Part") + +child.Parent = root +descendant.Parent = child + +assert(not root:IsAncestorOf(root)) +assert(not child:IsAncestorOf(root)) +assert(not descendant:IsAncestorOf(root)) + +assert(root:IsAncestorOf(child)) +assert(not child:IsAncestorOf(child)) +assert(not descendant:IsAncestorOf(child)) + +assert(root:IsAncestorOf(descendant)) +assert(child:IsAncestorOf(descendant)) +assert(not descendant:IsAncestorOf(descendant)) diff --git a/tests/roblox/instance/methods/IsDescendantOf.luau b/tests/roblox/instance/methods/IsDescendantOf.luau new file mode 100644 index 0000000..8a65c64 --- /dev/null +++ b/tests/roblox/instance/methods/IsDescendantOf.luau @@ -0,0 +1,21 @@ +local roblox = require("@lune/roblox") :: any +local Instance = roblox.Instance + +local root = Instance.new("Folder") +local child = Instance.new("Model") +local descendant = Instance.new("Part") + +child.Parent = root +descendant.Parent = child + +assert(not root:IsDescendantOf(root)) +assert(child:IsDescendantOf(root)) +assert(descendant:IsDescendantOf(root)) + +assert(not root:IsDescendantOf(child)) +assert(not child:IsDescendantOf(child)) +assert(descendant:IsDescendantOf(child)) + +assert(not root:IsDescendantOf(descendant)) +assert(not child:IsDescendantOf(descendant)) +assert(not descendant:IsDescendantOf(descendant))