local H=game:GetService("\067\111\108\108\101\099\116\105\111\110\083\101\114\118\105\099\101")local g=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local K=(require(g:WaitForChild("\098\097\115\101"))).CollectionServiceHelper local function d()local g="\077\121\084\097\103"local d=Instance.new("\080\097\114\116")d.Name="\080\097\114\116\049"d.Parent=game.Workspace K:BindToTag(g,function(H)print("\073\110\115\116\097\110\099\101 \097\100\100\101\100\058",H.Name)end)K:BindToTag(g,function(H)print("\073\110\115\116\097\110\099\101 \097\100\100\101\100 \097\103\097\105\110\058",H.Name)end)K:BindToTag(g,function(H)print("\073\110\115\116\097\110\099\101 \097\100\100\101\100 \111\110\099\101 \109\111\114\101\058",H.Name)end)H:AddTag(d,g)task.wait(1)H:RemoveTag(d,g)task.wait(1)d:Destroy()end local function J()local g="\077\121\084\097\103"local d=Instance.new("\080\097\114\116")d.Name="\080\097\114\116\049"d.Parent=game.Workspace K:BindToTagWithFilter(g,function(H)return H:IsA("\080\097\114\116")end,function(H)print("\080\097\114\116 \097\100\100\101\100\058",H.Name)end)K:BindToTagWithFilter(g,function(H)return H:IsA("\080\097\114\116")end,function(H) end)K:BindToTagWithFilter(g,function(H)return H:IsA("\080\097\114\116")end,function(H)print("\080\097\114\116 \097\100\100\101\100 \111\110\099\101 \109\111\114\101\058",H.Name)end)H:AddTag(d,g)task.wait(1)H:RemoveTag(d,g)task.wait(1)d:Destroy()end local function x()local g="\077\121\084\097\103"local d=Instance.new("\080\097\114\116")d.Name="\080\097\114\116\049"d.Parent=game.Workspace H:AddTag(d,g)K:BindToTagRemoved(g,function(H)print("\073\110\115\116\097\110\099\101 \114\101\109\111\118\101\100\058",H.Name)end)K:BindToTagRemoved(g,function(H)print("\073\110\115\116\097\110\099\101 \114\101\109\111\118\101\100 \097\103\097\105\110\058",H.Name)end)K:BindToTagRemoved(g,function(H)print("\073\110\115\116\097\110\099\101 \114\101\109\111\118\101\100 \111\110\099\101 \109\111\114\101\058",H.Name)end)H:RemoveTag(d,g)task.wait(1)d:Destroy()end d()J()x()
--!strict

--@class test_CollectionServiceHelper
--@author Midnightific

--// Initialization

local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local CollectionServiceHelper = require(ReplicatedStorage:WaitForChild("base")).CollectionServiceHelper

--// Functions

local function testBindToTag()
	local tag = "MyTag"
	local instance1 = Instance.new("Part")

	instance1.Name = "Part1"
	instance1.Parent = game.Workspace
	CollectionServiceHelper:BindToTag(tag, function(instance) print("Instance added:", instance.Name) end)

	CollectionServiceHelper:BindToTag(tag, function(instance) print("Instance added again:", instance.Name) end)

	CollectionServiceHelper:BindToTag(tag, function(instance) print("Instance added once more:", instance.Name) end)

	CollectionService:AddTag(instance1, tag)
	task.wait(1)
	CollectionService:RemoveTag(instance1, tag)
	task.wait(1)
	instance1:Destroy()
end

local function testBindToTagWithFilter()
	local tag = "MyTag"
	local instance1 = Instance.new("Part")
	instance1.Name = "Part1"
	instance1.Parent = game.Workspace

	CollectionServiceHelper:BindToTagWithFilter(
		tag,
		function(instance) return instance:IsA("Part") end,
		function(instance) print("Part added:", instance.Name) end
	)

	CollectionServiceHelper:BindToTagWithFilter(
		tag,
		function(instance) return instance:IsA("Part") end,
		function(instance) end
	)

	CollectionServiceHelper:BindToTagWithFilter(
		tag,
		function(instance) return instance:IsA("Part") end,
		function(instance) print("Part added once more:", instance.Name) end
	)

	CollectionService:AddTag(instance1, tag)
	task.wait(1)
	CollectionService:RemoveTag(instance1, tag)
	task.wait(1)
	instance1:Destroy()
end

local function testBindToTagRemoved()
	local tag = "MyTag"
	local instance1 = Instance.new("Part")

	instance1.Name = "Part1"
	instance1.Parent = game.Workspace
	CollectionService:AddTag(instance1, tag)
	CollectionServiceHelper:BindToTagRemoved(tag, function(instance) print("Instance removed:", instance.Name) end)

	CollectionServiceHelper:BindToTagRemoved(
		tag,
		function(instance) print("Instance removed again:", instance.Name) end
	)

	CollectionServiceHelper:BindToTagRemoved(
		tag,
		function(instance) print("Instance removed once more:", instance.Name) end
	)

	CollectionService:RemoveTag(instance1, tag)
	task.wait(1)
	instance1:Destroy()
end

--// Triggers

testBindToTag()
testBindToTagWithFilter()
testBindToTagRemoved()
