Skip to content

Commit

Permalink
Add tests for datamodel & collectionservice
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Mar 26, 2023
1 parent 4b793bf commit 8799c26
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/lib/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,18 @@ create_tests! {
roblox_datatype_vector2int16: "roblox/datatypes/Vector2int16",
roblox_datatype_vector3: "roblox/datatypes/Vector3",
roblox_datatype_vector3int16: "roblox/datatypes/Vector3int16",

roblox_files_read_model: "roblox/files/readModelFile",
roblox_files_read_place: "roblox/files/readPlaceFile",
roblox_files_write_model: "roblox/files/writeModelFile",
roblox_files_write_place: "roblox/files/writePlaceFile",

roblox_instance_attributes: "roblox/instance/attributes",
roblox_instance_datamodel: "roblox/instance/datamodel",
roblox_instance_new: "roblox/instance/new",
roblox_instance_properties: "roblox/instance/properties",
roblox_instance_tags: "roblox/instance/tags",

roblox_instance_methods_clear_all_children: "roblox/instance/methods/ClearAllChildren",
roblox_instance_methods_clone: "roblox/instance/methods/Clone",
roblox_instance_methods_destroy: "roblox/instance/methods/Destroy",
Expand Down
24 changes: 24 additions & 0 deletions tests/roblox/instance/datamodel.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
local roblox = require("@lune/roblox") :: any
local Instance = roblox.Instance

local game = Instance.new("DataModel")

assert(game:FindService("Workspace") == nil)
assert(game:GetService("Workspace") ~= nil)
assert(game:FindService("Workspace") ~= nil)

assert(game:FindService("CSGDictionaryService") == nil)
assert(game:GetService("CSGDictionaryService") ~= nil)
assert(game:FindService("CSGDictionaryService") ~= nil)

assert(not pcall(function()
game:GetService("wrorokspacey")
end))

assert(not pcall(function()
game:GetService("work-space")
end))

assert(not pcall(function()
game:GetService("workspac")
end))
35 changes: 35 additions & 0 deletions tests/roblox/instance/tags.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
local roblox = require("@lune/roblox") :: any
local Instance = roblox.Instance

local game = Instance.new("DataModel")
local cs = game:GetService("CollectionService")

local model = Instance.new("Model")
local part = Instance.new("Part")
part.Parent = model

local TAG_NAME = "InstanceTagName"

assert(cs:HasTag(model, TAG_NAME) == false)
assert(cs:HasTag(part, TAG_NAME) == false)

cs:AddTag(part, TAG_NAME)

assert(cs:HasTag(model, TAG_NAME) == false)
assert(cs:HasTag(part, TAG_NAME) == true)

cs:RemoveTag(part, TAG_NAME)

assert(cs:HasTag(model, TAG_NAME) == false)
assert(cs:HasTag(part, TAG_NAME) == false)

assert(#cs:GetTags(model) == 0)
assert(#cs:GetTags(part) == 0)

cs:AddTag(model, TAG_NAME)
cs:AddTag(part, TAG_NAME)

assert(#cs:GetTags(model) == 1)
assert(#cs:GetTags(part) == 1)
assert(cs:GetTags(model)[1] == TAG_NAME)
assert(cs:GetTags(part)[1] == TAG_NAME)

0 comments on commit 8799c26

Please sign in to comment.