Unified Naming Convention
Key RequiredUniversal

Unified Naming Convention

Universal Scriptskypinealtskypinealt 3.7K views 10 executesUpdated Apr 4, 2025
5.0/ 5(1 votes)
10100% Positive
Lua Script•959 lines (42705 chars)
local passes, fails, aliasIssues = 0, 0, 0
local runningTests = 0

local function getGlobal(path)
    local env = (getgenv and getgenv()) or getfenv(2)
    for segment in string.gmatch(path, "([^.]+)") do
        if env then
            env = env[segment]
        else
            break
        end
    end
    return env
end

local function test(globalName, aliases, callback)
    runningTests = runningTests + 1
    task.spawn(function()
        if not callback then
            print("⏺️ " .. globalName)
        elseif not getGlobal(globalName) then
            fails = fails + 1
            warn("⛔ Global `" .. globalName .. "` does not exist.")
        else
            local success, message = pcall(callback)
            if success then
                passes = passes + 1
                print("✅ " .. globalName .. (message and " • " .. tostring(message) or ""))
            else
                fails = fails + 1
                warn("⛔ " .. globalName .. " test failed: " .. tostring(message))
            end
        end

        local missingAliases = {}
        if aliases and type(aliases) == "table" then
            for _, alias in ipairs(aliases) do
                if getGlobal(alias) == nil then
                    table.insert(missingAliases, alias)
                end
            end
        end
        if #missingAliases > 0 then
            aliasIssues = aliasIssues + 1
            warn("⚠️ Missing aliases for test \"" .. globalName .. "\": " .. table.concat(missingAliases, ", "))
        end
        runningTests = runningTests - 1
    end)
end

print("UNC Environment Check")
print("✅ - Pass, ⛔ - Fail, ⏺️ - No test, ⚠️ - Missing aliases\n")

-- Cache
test("cache.invalidate", {}, function()
    local container = Instance.new("Folder")
    local part = Instance.new("Part", container)
    local original = container:FindFirstChild("Part")
    cache.invalidate(original)
    local invalidated = container:FindFirstChild("Part")
    assert(original ~= invalidated, "cache.invalidate: The cached reference was not updated as expected.")
end)

test("cache.iscached", {}, function()
    local part = Instance.new("Part")
    assert(cache.iscached(part), "cache.iscached: Instance should be cached initially.")
    cache.invalidate(part)
    assert(not cache.iscached(part), "cache.iscached: Instance should not be cached after invalidation.")
end)

test("cache.replace", {}, function()
    local part = Instance.new("Part")
    local fire = Instance.new("Fire")
    cache.replace(part, fire)
    assert(not cache.iscached(part), 
       "cache.replace: Original instance should not be cached after replacement.")
    assert(cache.iscached(fire), 
       "cache.replace: Replacement instance should be cached after replacement.")
end)

test("cloneref", {}, function()
    local part = Instance.new("Part")
    local clone = cloneref(part)
    assert(part ~= clone, "cloneref: Clone should be a distinct instance from the original.")
    clone.Name = "Test"
    assert(part.Name == "Test", "cloneref: Changes in the clone did not propagate to the original instance.")
end)

test("compareinstances", {}, function()
    local part = Instance.new("Part")
    local clone = cloneref(part)
    assert(part ~= clone, "compareinstances: Clone should be a distinct instance from the original.")
    assert(compareinstances(part, clone), "compareinstances: The clone is not considered equivalent to the original.")
end)

-- Closures
test("clonefunction", {}, function()
    local function originalFunction()
        return "success"
    end
    local clonedFunction = clonefunction(originalFunction)
    assert(originalFunction() == clonedFunction(), "clonefunction: Cloned function did not return the same value as the original.")
    assert(originalFunction ~= clonedFunction, "clonefunction: Cloned function should be a distinct instance from the original.")
end)

test("getfunctionhash", {}, function()
    local function sampleFunction()
        return "sample"
    end
    local hash1 = getfunctionhash(sampleFunction)
    local hash2 = getfunctionhash(sampleFunction)
    assert(type(hash1) == "string", "getfunctionhash: The function hash should be a string.")
    assert(hash1 == hash2, "getfunctionhash: The hash for the same function must be consistent.")
    local clonedFunction = clonefunction(sampleFunction)
    local hashCloned = getfunctionhash(clonedFunction)
    assert(hash1 == hashCloned, "getfunctionhash: The hash of a cloned function should match the original function hash.")
    local function anotherFunction()
        return "another"
    end
    local hash3 = getfunctionhash(anotherFunction)
    assert(hash1 ~= hash3, "getfunctionhash: Different functions should have different hashes.")
end)

test("hookfunction", {"replaceclosure"}, function()
    local function originalFunction()
        return true
    end
    local originalHook = hookfunction(originalFunction, function()
        return false 
    end)
    assert(originalFunction() == false, "hookfunction: After hooking, the function should return false.")
    assert(originalHook() == true, "hookfunction: The returned original function should return true.")
    assert(originalFunction ~= originalHook, "hookfunction: Hooked function reference should differ from the original function reference.")
end)

test("hookmetamethod", {}, function()
    local metaFunction = newcclosure(function() return false end)
    local object = setmetatable({}, { __index = metaFunction, __metatable = "Locked!" })
    local originalMetaMethod = hookmetamethod(object, "__index", function() return true end)
    assert(object.anyKey == true, "hookmetamethod: Metamethod hook did not change the behavior as expected.")
    assert(originalMetaMethod() == false, "hookmetamethod: Original metamethod should return false.")
end)

test("iscclosure", {}, function()
    assert(iscclosure(print) == true, "iscclosure: 'print' should be detected as a C closure.")
    assert(iscclosure(function() end) == false, "iscclosure: A Lua function should not be a C closure.")
end)

test("islclosure", {}, function()
    assert(islclosure(print) == false, "islclosure: 'print' should not be detected as a Lua closure.")
    assert(islclosure(function() end) == true, "islclosure: A Lua executor function should be detected as a Lua closure.")
end)

test("isexecutorclosure", {"checkclosure", "isourclosure"}, function()
    assert(isexecutorclosure(isexecutorclosure) == true, "isexecutorclosure: Executor global function should be detected as an executor closure.")
    assert(isexecutorclosure(newcclosure(function() end)) == true, "isexecutorclosure: New C closure should be detected as an executor closure.")
    assert(isexecutorclosure(function() end) == true, "isexecutorclosure: Lua closure should be detected as an executor closure.")
    assert(isexecutorclosure(print) == false, "isexecutorclosure: Roblox global function 'print' should not be detected as an executor closure.")
end)

test("newcclosure", {}, function()
    local function originalFunction()
        return true
    end
    local cClosure = newcclosure(originalFunction)
    assert(originalFunction() == cClosure(), "newcclosure: The new C closure did not return the expected result.")
    assert(originalFunction ~= cClosure, "newcclosure: The new C closure should be distinct from the original.")
    assert(iscclosure(cClosure), "newcclosure: The new closure should be detected as a C closure.")
end)

-- Crypt
test("crypt.base64decode", {"crypt.base64.decode", "crypt.base64_decode", "base64.decode", "base64_decode"}, function()
    local base64Input = "dGVzdA=="
    local expectedOutput = "test"
    local decodedValue = crypt.base64decode(base64Input)
    assert(decodedValue == expectedOutput, "crypt.base64decode: Expected '" .. expectedOutput .. "', got '" .. tostring(decodedValue) .. "'")
end)

test("crypt.base64encode", {"crypt.base64.encode", "crypt.base64_encode", "base64.encode", "base64_encode"}, function()
    local inputString = "test"
    local expectedEncoded = "dGVzdA=="
    local encodedValue = crypt.base64encode(inputString)
    assert(encodedValue == expectedEncoded, "crypt.base64encode: Expected '" .. expectedEncoded .. "', got '" .. tostring(encodedValue) .. "'")
end)

test("crypt.decrypt", {}, function()
    local key = crypt.generatekey()
    local iv = crypt.generatekey()
    local originalMessage = "test"
    local encryptedData = crypt.encrypt(originalMessage, key, iv, "CBC")
    local decryptedMessage = crypt.decrypt(encryptedData, key, iv, "CBC")
    assert(decryptedMessage == originalMessage, "crypt.decrypt: Expected decrypted message '" .. originalMessage .. "', but got '" .. tostring(decryptedMessage) .. "'")
end)

test("crypt.encrypt", {}, function()
    local key = crypt.generatekey()
    local originalMessage = "test"
    local encryptedData, generatedIV = crypt.encrypt(originalMessage, key, nil, "CBC")
    assert(generatedIV, "crypt.encrypt: Expected an IV to be generated when none is provided.")
    local decryptedMessage = crypt.decrypt(encryptedData, key, generatedIV, "CBC")
    assert(decryptedMessage == originalMessage, "crypt.encrypt: Decrypted message mismatch. Expected '" .. originalMessage .. "', got '" .. tostring(decryptedMessage) .. "'")
end)

test("crypt.generatebytes", {}, function()
    local byteCount = math.random(10, 100)
    local base64Bytes = crypt.generatebytes(byteCount)
    local decodedBytes = crypt.base64decode(base64Bytes)
    assert(#decodedBytes == byteCount, "crypt.generatebytes: Expected decoded byte length of " .. byteCount .. " but got " .. #decodedBytes)
end)

test("crypt.generatekey", {}, function()
    local key = crypt.generatekey()
    local decodedKey = crypt.base64decode(key)
    assert(#decodedKey == 32, "crypt.generatekey: Expected a 32-byte key when decoded, but got " .. #decodedKey .. " bytes.")
end)

test("crypt.hash", {}, function()
    local message = "test"
    local algorithms = {'sha1', 'sha384', 'sha512', 'md5', 'sha256', 'sha3-224', 'sha3-256', 'sha3-512'}
    for _, algorithm in ipairs(algorithms) do
        local hashResult = crypt.hash(message, algorithm)
        assert(hashResult and type(hashResult) == "string" and #hashResult > 0,
            "crypt.hash: Expected a non-empty hash string for algorithm '" .. algorithm .. "'.")
    end
end)

-- Debug
test("debug.getconstants", {}, function()
    local function sampleFunction()
        local num = 5000 .. 50000
        print("Hello, world!", num, warn)
    end
    local constants = debug.getconstants(sampleFunction)
    assert(constants[1] == 50000, "debug.getconstants: Expected first constant to be 50000, got " .. tostring(constants[1]))
    assert(constants[2] == "print", "debug.getconstants: Expected second constant to be 'print', got " .. tostring(constants[2]))
    assert(constants[3] == nil, "debug.getconstants: Expected third constant to be nil, got " .. tostring(constants[3]))
    assert(constants[4] == "Hello, world!", "debug.getconstants: Expected fourth constant to be 'Hello, world!', got " .. tostring(constants[4]))
    assert(constants[5] == "warn", "debug.getconstants: Expected fifth constant to be 'warn', got " .. tostring(constants[5]))
end)

test("debug.getconstant", {}, function()
    local function sampleFunction()
        print("Hello, world!")
    end
    local const1 = debug.getconstant(sampleFunction, 1)
    local const2 = debug.getconstant(sampleFunction, 2)
    local const3 = debug.getconstant(sampleFunction, 3)
    assert(const1 == "print", "debug.getconstant: Expected first constant to be 'print', got " .. tostring(const1))
    assert(const2 == nil, "debug.getconstant: Expected second constant to be nil, got " .. tostring(const2))
    assert(const3 == "Hello, world!", "debug.getconstant: Expected third constant to be 'Hello, world!', got " .. tostring(const3))
end)

test("debug.getinfo", {}, function()
    local expectedTypes = {
        source = "string",
        short_src = "string",
        func = "function",
        what = "string",
        currentline = "number",
        name = "string",
        nups = "number",
        numparams = "number",
        is_vararg = "number",
    }
    local function sampleFunction(...)
        print(...)
    end
    local info = debug.getinfo(sampleFunction)
    for key, expectedType in pairs(expectedTypes) do
        assert(info[key] ~= nil, "debug.getinfo: Expected info to include field '" .. key .. "', but it is nil.")
        local actualType = type(info[key])
        assert(actualType == expectedType, "debug.getinfo: Field '" .. key .. "' expected to be '" .. expectedType .. "', but got '" .. actualType .. "'.")
    end
end)

test("debug.getproto", {}, function()
    local function sampleFunction()
        local function innerProto()
            return true
        end
    end
    local protos = debug.getproto(sampleFunction, 1, true)
    local protoFunc = protos and protos[1]
    local realProtoFunc = debug.getproto(sampleFunction, 1)
    assert(protoFunc, "debug.getproto: Failed to retrieve the inner function.")
    assert(protoFunc() == true, "debug.getproto: The retrieved inner function did not return true.")
    local realResult = realProtoFunc and realProtoFunc()
    assert(realResult == true, "debug.getproto: The real proto function did not return true. (Proto return values may be disabled on this executor)")
end)

test("debug.getprotos", {}, function()
    local function sampleFunction()
        local function inner1()
            return true
        end
        local function inner2()
            return true
        end
        local function inner3()
            return true
        end
    end
    local protosList = debug.getprotos(sampleFunction)
    for i, _ in ipairs(protosList) do
        local protoEntry = debug.getproto(sampleFunction, i, true)
        local protoFunc = protoEntry and protoEntry[1]
        local realProtoFunc = debug.getproto(sampleFunction, i)
        assert(protoFunc and protoFunc() == true, "debug.getprotos: Failed retrieving or validating inner function at index " .. i)
        local realResult = realProtoFunc and realProtoFunc()
        assert(realResult == true, "debug.getprotos: Real proto function at index " .. i .. " did not return true. (Proto return values may be disabled)")
    end
end)

test("debug.getstack", {}, function()
    local concatenated = "a" .. "b"
    local singleStack = debug.getstack(1, 1)
    local stackTable = debug.getstack(1)
    assert(singleStack == concatenated, "debug.getstack: Expected first stack item to be '" .. concatenated .. "', got '" .. tostring(singleStack) .. "'.")
    assert(stackTable[1] == concatenated, "debug.getstack: Expected first item in stack table to be '" .. concatenated .. "', got '" .. tostring(stackTable[1]) .. "'.")
end)

test("debug.getupvalue", {}, function()
    local capturedUpvalue = function() end
    local function sampleFunction()
        print(capturedUpvalue)
    end
    local retrievedUpvalue = debug.getupvalue(sampleFunction, 1)
    assert(retrievedUpvalue == capturedUpvalue, "debug.getupvalue: Expected upvalue to match; got " .. tostring(retrievedUpvalue))
end)

test("debug.getupvalues", {}, function()
    local capturedUpvalue = function() end
    local function sampleFunction()
        print(capturedUpvalue)
    end
    local upvalues = debug.getupvalues(sampleFunction)
    assert(upvalues[1] == capturedUpvalue, "debug.getupvalues: Expected first upvalue to match the captured value; got " .. tostring(upvalues[1]))
end)

test("debug.setconstant", {}, function()
    local function sampleFunction()
        return "fail"
    end
    debug.setconstant(sampleFunction, 1, "success")
    local result = sampleFunction()
    assert(result == "success", "debug.setconstant: Expected sampleFunction() to return 'success', got '" .. tostring(result) .. "'.")
end)

test("debug.setstack", {}, function()
    local function sampleFunction()
        return "fail", debug.setstack(1, 1, "success")
    end
    local result = sampleFunction()
    assert(result == "success", "debug.setstack: Expected sampleFunction() to return 'success', got '" .. tostring(result) .. "'.")
end)

test("debug.setupvalue", {}, function()
    local function innerUpvalue()
        return "fail"
    end
    local function sampleFunction()
        return innerUpvalue()
    end
    debug.setupvalue(sampleFunction, 1, function() return "success" end)
    local result = sampleFunction()
    assert(result == "success", "debug.setupvalue: Expected sampleFunction() to return 'success', got '" .. tostring(result) .. "'.")
end)

-- Drawing
test("cleardrawcache", {}, function()
    local dummyDrawing = Drawing.new("Circle")
    dummyDrawing.Visible = true
    local success = pcall(function()
        cleardrawcache()
    end)
    assert(success, "cleardrawcache: Clearing the drawing cache produced an error.")
end)

test("Drawing.Fonts", {}, function()
    assert(Drawing.Fonts.UI == 0, "Drawing.Fonts.UI expected value 0, got " .. tostring(Drawing.Fonts.UI))
    assert(Drawing.Fonts.System == 1, "Drawing.Fonts.System expected value 1, got " .. tostring(Drawing.Fonts.System))
    assert(Drawing.Fonts.Plex == 2, "Drawing.Fonts.Plex expected value 2, got " .. tostring(Drawing.Fonts.Plex))
    assert(Drawing.Fonts.Monospace == 3, "Drawing.Fonts.Monospace expected value 3, got " .. tostring(Drawing.Fonts.Monospace))
end)

test("Drawing.new", {}, function()
    local drawing = Drawing.new("Square")
    drawing.Visible = false
    local destroySuccess, err = pcall(function()
        drawing:Destroy()
    end)
    assert(destroySuccess, "Drawing.new: Calling Destroy() threw an error: " .. tostring(err))
end)

test("getrenderproperty", {}, function()
    local drawing = Drawing.new("Image")
    drawing.Visible = true
    local visibleValue = getrenderproperty(drawing, "Visible")
    assert(type(visibleValue) == "boolean", "getrenderproperty: Expected 'Visible' to be a boolean, got " .. type(visibleValue))
    local success, colorValue = pcall(function()
        return getrenderproperty(drawing, "Color")
    end)
    if not success or colorValue == nil then
        return "getrenderproperty: 'Color' property is not supported by this drawing object."
    else
        assert(type(colorValue) == "string" or type(colorValue) == "table",
            "getrenderproperty: 'Color' exists but has an unexpected type: " .. type(colorValue))
    end
end)

test("isrenderobj", {}, function()
    local drawing = Drawing.new("Image")
    drawing.Visible = true
    assert(isrenderobj(drawing) == true, "isrenderobj: Expected true for a valid Drawing instance but got false.")
    local nonRenderObject = newproxy and newproxy() or {}
    assert(isrenderobj(nonRenderObject) == false, "isrenderobj: Expected false for a non-render object, but got true.")
end)

test("setrenderproperty", {}, function()
    local drawing = Drawing.new("Square")
    drawing.Visible = true
    setrenderproperty(drawing, "Visible", false)
    assert(drawing.Visible == false, "setrenderproperty: Expected 'Visible' to be false after setting, but got " .. tostring(drawing.Visible))
end)

-- Environment
test("getgc", {}, function()
    local gcTable = getgc()
    assert(type(gcTable) == "table", "getgc: Expected a table, got " .. type(gcTable))
    assert(#gcTable > 0, "getgc: Expected a non-empty table, but got 0 items.")
end)

test("getgenv", {}, function()
    local env = getgenv()
    env.__TEST_GLOBAL = true
    assert(__TEST_GLOBAL == true, "getgenv: Failed to set the global variable '__TEST_GLOBAL'.")
    env.__TEST_GLOBAL = nil
end)

test("getrenv", {}, function()
    local executorEnv = getrenv()
    assert(_G ~= executorEnv._G, "getrenv: Expected executor _G to differ from the game's _G.")
end)

-- Filesystem
if isfolder and makefolder and delfolder then
    if isfolder(".tests") then
        delfolder(".tests")
    end
    makefolder(".tests")
end

test("appendfile", {}, function()
    writefile(".tests/appendfile.txt", "su")
    appendfile(".tests/appendfile.txt", "cce")
    appendfile(".tests/appendfile.txt", "ss")
    local content = readfile(".tests/appendfile.txt")
    assert(content == "success", "appendfile: Expected file content 'success'; got '" .. tostring(content) .. "'.")
end)

test("delfile", {}, function()
    writefile(".tests/delfile.txt", "Hello, world!")
    delfile(".tests/delfile.txt")
    local exists = isfile(".tests/delfile.txt")
    assert(exists == false, "delfile: Expected file to be deleted; isfile returned " .. tostring(exists) .. ".")
end)

test("delfolder", {}, function()
    makefolder(".tests/delfolder")
    delfolder(".tests/delfolder")
    local exists = isfolder(".tests/delfolder")
    assert(exists == false, "delfolder: Expected folder to be deleted; isfolder returned " .. tostring(exists) .. ".")
end)

test("getcustomasset", {}, function()
    writefile(".tests/getcustomasset.txt", "success")
    local assetUrl = getcustomasset(".tests/getcustomasset.txt")
    assert(type(assetUrl) == "string", "getcustomasset: Expected a string; got " .. type(assetUrl) .. ".")
    assert(#assetUrl > 0, "getcustomasset: Returned an empty string.")
    local matched = string.match(assetUrl, "rbxasset://")
    assert(matched == "rbxasset://", "getcustomasset: Expected URL starting with 'rbxasset://'; got '" .. tostring(assetUrl) .. "'.")
end)

test("isfile", {}, function()
    writefile(".tests/isfile.txt", "success")
    assert(isfile(".tests/isfile.txt") == true, "isfile: Expected true for an existing file.")
    assert(isfile(".tests") == false, "isfile: Expected false when checking a folder.")
    assert(isfile(".tests/doesnotexist.exe") == false, "isfile: Expected false for a non-existent path; got " .. tostring(isfile(".tests/doesnotexist.exe")) .. ".")
end)

test("isfolder", {}, function()
    assert(isfolder(".tests") == true, "isfolder: Expected true for an existing folder.")
    assert(isfolder(".tests/doesnotexist.exe") == false, "isfolder: Expected false for a non-existent folder; got " .. tostring(isfolder(".tests/doesnotexist.exe")) .. ".")
end)

test("listfiles", {}, function()
    makefolder(".tests/listfiles")
    writefile(".tests/listfiles/test_1.txt", "success")
    writefile(".tests/listfiles/test_2.txt", "success")
    local files = listfiles(".tests/listfiles")
    assert(#files == 2, "listfiles: Expected 2 files; got " .. #files .. ".")
    for _, file in ipairs(files) do
        assert(isfile(file), "listfiles: Expected a file path; got " .. tostring(file) .. ".")
        assert(readfile(file) == "success", "listfiles: File content does not match expectations.")
    end
    makefolder(".tests/listfiles_2")
    makefolder(".tests/listfiles_2/test_1")
    makefolder(".tests/listfiles_2/test_2")
    local folders = listfiles(".tests/listfiles_2")
    assert(#folders == 2, "listfiles: Expected 2 folders; got " .. #folders .. ".")
    for _, folder in ipairs(folders) do
        assert(isfolder(folder), "listfiles: Expected a folder path; got " .. tostring(folder) .. ".")
    end
end)

test("loadfile", {}, function()
    writefile(".tests/loadfile.txt", "return ... + 1")
    local fileFunc = assert(loadfile(".tests/loadfile.txt"))
    local result = fileFunc(1)
    assert(result == 2, "loadfile: Expected result 2 when calling function with argument 1; got " .. tostring(result) .. ".")
    writefile(".tests/loadfile.txt", "f")
    local callback, err = loadfile(".tests/loadfile.txt")
    assert(not callback and err, "loadfile: Expected a compiler error message for invalid file content.")
end)

test("makefolder", {}, function()
    makefolder(".tests/makefolder")
    assert(isfolder(".tests/makefolder") == true, "makefolder: Expected folder '.tests/makefolder' to be created.")
end)

test("readfile", {}, function()
    writefile(".tests/readfile.txt", "success")
    local content = readfile(".tests/readfile.txt")
    assert(content == "success", "readfile: Expected content 'success'; got '" .. tostring(content) .. "'.")
end)

test("writefile", {}, function()
    writefile(".tests/writefile.txt", "success")
    local content = readfile(".tests/writefile.txt")
    assert(content == "success", "writefile: Expected content 'success'; got '" .. tostring(content) .. "'.")
    local requiresFileExt = pcall(function()
        writefile(".tests/writefile", "success")
        assert(isfile(".tests/writefile.txt"), "writefile: Expected file with missing extension to be saved as '.txt'.")
    end)
    if not requiresFileExt then
        return "writefile: This executor requires a file extension in writefile."
    end
end)

-- Input
test("isrbxactive", {"isgameactive"}, function()
    local activeStatus = isrbxactive()
    assert(type(activeStatus) == "boolean", "isrbxactive: Expected a boolean value but received " .. type(activeStatus))
end)

-- Instances
test("fireclickdetector", {}, function()
    local detector = Instance.new("ClickDetector")
    fireclickdetector(detector, 50, "MouseHoverEnter")
end)

test("fireproximityprompt", {}, function()
    local part = Instance.new("Part")
    local prompt = Instance.new("ProximityPrompt")
    prompt.Parent = part
    fireproximityprompt(prompt)
end)

test("firetouchinterest", {}, function()
    local partA = Instance.new("Part")
    local partB = Instance.new("Part")
    local successBegin, errBegin = pcall(function()
        firetouchinterest(partA, partB, 0)
    end)
    assert(successBegin, "firetouchinterest: Failed to fire touch begin event: " .. tostring(errBegin))
    local successEnd, errEnd = pcall(function()
        firetouchinterest(partA, partB, 1)
    end)
    assert(successEnd, "firetouchinterest: Failed to fire touch end event: " .. tostring(errEnd))
end)

test("getcallbackvalue", {}, function()
    local bindable = Instance.new("BindableFunction")
    local function callbackFunction() end
    bindable.OnInvoke = callbackFunction
    local retrievedCallback = getcallbackvalue(bindable, "OnInvoke")
    assert(retrievedCallback == callbackFunction, "getcallbackvalue: Retrieved callback does not match the expected function.")
end)

test("gethui", {}, function()
    local huiInstance = gethui()
    assert(typeof(huiInstance) == "Instance", "gethui: Expected an Instance, got " .. typeof(huiInstance))
end)

test("getinstances", {}, function()
    local instancesList = getinstances()
    assert(instancesList[1]:IsA("Instance"), "getinstances: The first element is not an Instance.")
end)

test("getnilinstances", {}, function()
    local nilInstances = getnilinstances()
    assert(nilInstances[1]:IsA("Instance"), "getnilinstances: The first element is not an Instance.")
    assert(nilInstances[1].Parent == nil, "getnilinstances: The first instance is not parented to nil.")
end)

test("isscriptable", {}, function()
    local fireInstance = Instance.new("Fire")
    assert(isscriptable(fireInstance, "size_xml") == false, "isscriptable: Expected false for non-scriptable property 'size_xml'.")
    assert(isscriptable(fireInstance, "Size") == true, "isscriptable: Expected true for scriptable property 'Size'.")
end)

-- Metatable
test("getrawmetatable", {}, function()
    local expectedMT = { __metatable = "Locked!" }
    local obj = setmetatable({}, expectedMT)
    local rawMT = getrawmetatable(obj)
    assert(rawMT == expectedMT, "getrawmetatable: Expected metatable does not match the actual metatable.")
end)

test("isreadonly", {}, function()
    local obj = {}
    table.freeze(obj)
    local readonlyStatus = isreadonly(obj)
    assert(readonlyStatus, "isreadonly: Expected a frozen table to be read-only, but got false.")
end)

test("setrawmetatable", {}, function()
    local obj = setmetatable({}, { __index = function() return false end, __metatable = "Locked!" })
    local newMT = { __index = function() return true end }
    local returnedObj = setrawmetatable(obj, newMT)
    assert(returnedObj == obj, "setrawmetatable: Expected to return the original object, but did not.")
    assert(obj.test == true, "setrawmetatable: Expected obj.test to be true from the new metatable; got " .. tostring(obj.test))
end)

test("setreadonly", {}, function()
    local obj = { success = false }
    table.freeze(obj)
    setreadonly(obj, false)
    obj.success = true
    assert(obj.success, "setreadonly: Table modification failed; expected obj.success to be true, but got " .. tostring(obj.success))
end)

-- Miscellaneous
test("identifyexecutor", {"getexecutorname"}, function()
    local executorName, executorVersion = identifyexecutor()
    assert(type(executorName) == "string", "identifyexecutor: Expected executor name to be a string, got " .. type(executorName))
    if type(executorVersion) == "string" then
        return "Returns version as a string: " .. executorVersion
    else
        return "Does not return a version string"
    end
end)

test("lz4compress", {}, function()
    local rawData = "Hello, world!"
    local compressedData = lz4compress(rawData)
    assert(type(compressedData) == "string", "lz4compress: Expected compressed data to be a string, got " .. type(compressedData))
    local decompressedData = lz4decompress(compressedData, #rawData)
    assert(decompressedData == rawData, "lz4compress/lz4decompress: Decompressed data did not match original")
end)

test("lz4decompress", {}, function()
    local rawData = "Hello, world!"
    local compressedData = lz4compress(rawData)
    assert(type(compressedData) == "string", "lz4decompress: Expected compressed data to be a string, got " .. type(compressedData))
    local decompressedData = lz4decompress(compressedData, #rawData)
    assert(decompressedData == rawData, "lz4decompress: Decompressed data did not match original")
end)

test("request", {"http.request", "http_request"}, function()
    local response = request({
        Url = "https://httpbin.org/user-agent",
        Method = "GET",
    })
    assert(type(response) == "table", "request: Expected response to be a table, got " .. type(response))
    assert(response.StatusCode == 200, "request: Expected status code 200, got " .. tostring(response.StatusCode))
    local jsonData = game:GetService("HttpService"):JSONDecode(response.Body)
    assert(type(jsonData) == "table" and type(jsonData["user-agent"]) == "string", "request: Response body is not as expected")
    return "User-Agent: " .. jsonData["user-agent"]
end)

test("setclipboard", {}, function()
    local clipboardText = "Hello, clipboard!"
    local success, err = pcall(function()
        setclipboard(clipboardText)
    end)
    assert(success, "setclipboard: Expected to set clipboard text without error, but got: " .. tostring(err))
    return "Clipboard set to: " .. clipboardText
end)

test("setfpscap", {}, function()
    local RunService = game:GetService("RunService")
    local function measureFPS()
        local totalFPS, count = 0, 5
        for i = 1, count do
            local dt = RunService.RenderStepped:Wait()
            totalFPS = totalFPS + (1 / dt)
        end
        return math.round(totalFPS / count)
    end
    setfpscap(60)
    local fpsAt60 = measureFPS()
    setfpscap(0)
    local fpsAt0 = measureFPS()
    return fpsAt60 .. "fps @60 cap • " .. fpsAt0 .. "fps @0 cap"
end)

test("queue_on_teleport", {}, function()
    local success, err = pcall(function() 
        queue_on_teleport("print('Teleport script queued')")
    end)
    assert(success, "queue_on_teleport: Expected no error when queuing a teleport script, but got: " .. tostring(err))
end)

-- Reflection
test("checkcaller", {}, function()
    local isMainCaller = checkcaller()
    assert(isMainCaller, "checkcaller: Expected main scope to return true, but got false.")
end)

test("gethiddenproperty", {}, function()
    local fireInstance = Instance.new("Fire")
    local propertyValue, isHidden = gethiddenproperty(fireInstance, "size_xml")
    assert(propertyValue == 5, "gethiddenproperty: Expected 'size_xml' to be 5; got " .. tostring(propertyValue))
    assert(isHidden == true, "gethiddenproperty: Expected 'size_xml' to be hidden; got " .. tostring(isHidden))
end)

test("getthreadidentity", {"getidentity", "getthreadcontext"}, function()
    local threadIdentity = getthreadidentity()
    assert(type(threadIdentity) == "number", "getthreadidentity: Expected a number; got " .. type(threadIdentity))
end)

test("sethiddenproperty", {}, function()
    local fireInstance = Instance.new("Fire")
    local success = sethiddenproperty(fireInstance, "size_xml", 10)
    assert(success, "sethiddenproperty: Expected sethiddenproperty to return true for setting 'size_xml' to 10, but got false.")
    local newValue = gethiddenproperty(fireInstance, "size_xml")
    assert(newValue == 10, "sethiddenproperty: Expected 'size_xml' to be updated to 10; got " .. tostring(newValue))
end)

test("setscriptable", {}, function()
    local fireInstance = Instance.new("Fire")
    local wasScriptable = setscriptable(fireInstance, "size_xml", true)
    assert(wasScriptable == false, "setscriptable: Expected initial state for 'size_xml' to be non-scriptable, but got " .. tostring(wasScriptable))
    assert(isscriptable(fireInstance, "size_xml") == true, "setscriptable: 'size_xml' should be scriptable after setting, but it is not.")
    local anotherFire = Instance.new("Fire")
    assert(isscriptable(anotherFire, "size_xml") == false, "setscriptable: Scriptable state should not persist between instances; new instance returned true.")
end)

test("setthreadidentity", {"setidentity", "setthreadcontext"}, function()
    setthreadidentity(3)
    local threadIdentity = getthreadidentity()
    assert(threadIdentity == 3, "setthreadidentity: Expected thread identity to be 3 after setting, but got " .. tostring(threadIdentity))
end)

-- Scripts
local function shallowEqual(t1, t2)
    if t1 == t2 then
        return true
    end
    local UNIQUE_TYPES = {
        ["function"] = true,
        ["table"] = true,
        ["userdata"] = true,
        ["thread"] = true,
    }
    for k, v in pairs(t1) do
        if UNIQUE_TYPES[type(v)] then
            if type(t2[k]) ~= type(v) then
                return false
            end
        elseif t2[k] ~= v then
            return false
        end
    end
    for k, v in pairs(t2) do
        if UNIQUE_TYPES[type(v)] then
            if type(t1[k]) ~= type(v) then
                return false
            end
        elseif t1[k] ~= v then
            return false
        end
    end
    return true
end

test("getcallingscript", {}, function()
    local function retrieveCallingScript()
        return getcallingscript()
    end
    local callingScript = retrieveCallingScript()
    assert(typeof(callingScript) == "Instance", "getcallingscript: Expected an Instance, got " .. typeof(callingScript))
    local scriptClass = callingScript.ClassName
    local validScriptType = (scriptClass == "LocalScript" or scriptClass == "Script" or scriptClass == "ModuleScript")
    assert(validScriptType, "getcallingscript: Expected caller to be a Script/LocalScript/ModuleScript, got " .. scriptClass)
    return "Caller script: " .. callingScript:GetFullName()
end)

test("getloadedmodules", {}, function()
    local modules = getloadedmodules()
    assert(type(modules) == "table", "getloadedmodules: Expected a table, got " .. type(modules))
    assert(#modules > 0, "getloadedmodules: Table is empty")
    assert(typeof(modules[1]) == "Instance", "getloadedmodules: First value is not an Instance")
    assert(modules[1]:IsA("ModuleScript"), "getloadedmodules: First value is not a ModuleScript")
end)

test("getscriptbytecode", {"dumpstring"}, function()
    local animate = game:GetService("Players").LocalPlayer.Character.Animate
    local bytecode = getscriptbytecode(animate)
    assert(type(bytecode) == "string", "getscriptbytecode: Expected a string for Character.Animate (a " .. animate.ClassName .. "), got " .. type(bytecode))
end)

test("getscriptclosure", {"getscriptfunction"}, function()
    local module = game:GetService("CoreGui").RobloxGui.Modules.Common.Constants
    local expectedConstants = getrenv().require(module)
    local generatedConstants = getscriptclosure(module)()
    assert(expectedConstants ~= generatedConstants, "getscriptclosure: Generated module should not match the original reference")
    assert(shallowEqual(expectedConstants, generatedConstants), "getscriptclosure: Generated constant table is not shallow equal to the expected constants")
end)

test("getscripthash", {}, function()
    local animate = game:GetService("Players").LocalPlayer.Character.Animate:Clone()
    local originalHash = getscripthash(animate)
    local originalSource = animate.Source
    animate.Source = "print('Hello, world!')"
    task.defer(function()
        animate.Source = originalSource
    end)
    local modifiedHash = getscripthash(animate)
    assert(originalHash ~= modifiedHash, "getscripthash: Expected different hash after modifying the script")
    assert(modifiedHash == getscripthash(animate), "getscripthash: Expected same hash when source remains unchanged")
end)

test("getrunningscripts", {}, function()
    local runningScripts = getrunningscripts()
    assert(type(runningScripts) == "table", "getrunningscripts: Expected a table, got " .. type(runningScripts))
    assert(#runningScripts > 0, "getrunningscripts: No running scripts returned")
    assert(typeof(runningScripts[1]) == "Instance", "getrunningscripts: First value is not an Instance")
    local className = runningScripts[1].ClassName
    assert(className == "ModuleScript" or className == "LocalScript", "getrunningscripts: First value is not a ModuleScript or LocalScript")
end)

test("getscripts", {}, function()
    local scripts = getscripts()
    assert(type(scripts) == "table", "getscripts: Expected a table, got " .. type(scripts))
    assert(#scripts > 0, "getscripts: No scripts returned")
    assert(typeof(scripts[1]) == "Instance", "getscripts: First value is not an Instance")
    local className = scripts[1].ClassName
    assert(className == "ModuleScript" or className == "LocalScript", "getscripts: First value is not a ModuleScript or LocalScript")
end)

test("getsenv", {}, function()
    local animate = game:GetService("Players").LocalPlayer.Character.Animate
    local env = getsenv(animate)
    assert(type(env) == "table", "getsenv: Expected a table for " .. animate.ClassName .. ", got " .. type(env))
    assert(env.script == animate, "getsenv: The 'script' global does not match " .. animate:GetFullName())
end)

test("loadstring", {}, function()
    local animate = game:GetService("Players").LocalPlayer.Character.Animate
    local bytecode = getscriptbytecode(animate)
    local func = loadstring(bytecode)
    assert(type(func) ~= "function", "loadstring: Luau bytecode should not be loadable!")
    local simpleFunc = assert(loadstring("return ... + 1"))
    assert(simpleFunc(1) == 2, "loadstring: Expected simple function to return 2 when called with 1")
    local _, errMsg = loadstring("f")
    assert(type(errMsg) == "string", "loadstring: Expected an error message for invalid code")
end)

-- Signals
test("firesignal", {}, function()
    local bindable = Instance.new("BindableEvent")
    local receivedValue = nil
    local function onFired(val)
        receivedValue = val
    end
    bindable.Event:Connect(onFired)
    firesignal(bindable.Event, 42)
    assert(receivedValue == 42, 
        "firesignal: Expected callback to receive 42; got " .. tostring(receivedValue))
end)

test("getconnections", {}, function()
    local expectedTypes = {
        Enabled = "boolean",
        ForeignState = "boolean",
        LuaConnection = "boolean",
        Function = "function",
        Thread = "thread",
        Fire = "function",
        Defer = "function",
        Disconnect = "function",
        Disable = "function",
        Enable = "function",
    }
    local bindable = Instance.new("BindableEvent")
    bindable.Event:Connect(function() end)
    local connections = getconnections(bindable.Event)
    assert(type(connections) == "table" and #connections >= 1, 
        "getconnections: Expected a non-empty table of connections.")
    local connection = connections[1]
    for key, expectedType in pairs(expectedTypes) do
        assert(connection[key] ~= nil, 
            "getconnections: Missing '" .. key .. "' field in connection table.")
        assert(type(connection[key]) == expectedType, 
            "getconnections: Field '" .. key .. "' expected to be a " .. expectedType .. 
            ", got " .. type(connection[key]) .. ".")
    end
end)

test("replicatesignal", {}, function()
    local sourceEvent = Instance.new("BindableEvent")
    local targetEvent = Instance.new("BindableEvent")
    local triggeredValue = nil
    local function callback(val)
        triggeredValue = val
    end
    sourceEvent.Event:Connect(callback)
    replicatesignal(sourceEvent.Event, targetEvent)
    firesignal(targetEvent.Event, "TestValue")
    assert(triggeredValue == "TestValue", 
        "replicatesignal: Expected replicated callback to receive 'TestValue'; got " .. tostring(triggeredValue))
end)

-- WebSocket
test("WebSocket.connect", {}, function()
    local expectedProperties = {
        Send = "function",
        Close = "function",
        OnMessage = {"table", "userdata"},
        OnClose = {"table", "userdata"},
    }
    local ws = WebSocket.connect("ws://echo.websocket.events")
    assert(type(ws) == "table" or type(ws) == "userdata", 
        "WebSocket.connect: Expected WebSocket object to be a table or userdata, got " .. type(ws))
    for propertyName, expectedType in pairs(expectedProperties) do
        if type(expectedType) == "table" then
            assert(table.find(expectedType, type(ws[propertyName])), 
                "WebSocket.connect: Expected '" .. propertyName .. "' to be one of " .. table.concat(expectedType, ", ") .. 
                ", got " .. type(ws[propertyName]))
        else
            assert(type(ws[propertyName]) == expectedType, 
                "WebSocket.connect: Expected '" .. propertyName .. "' to be a " .. expectedType .. 
                ", got " .. type(ws[propertyName]))
        end
    end
    ws:Close()
end)

task.defer(function()
    repeat task.wait() until runningTests == 0
    local totalTests = passes + fails
    local successRate = totalTests > 0 and math.floor((passes / totalTests) * 100 + 0.5) or 100
    print("\nUNC Environment Check Result")
    print("✅ Tested with a " .. successRate .. "% success rate (" .. passes .. " out of " .. totalTests .. " tests).")
    print("⛔ " .. fails .. " tests failed.")
    print("⚠️ " .. aliasIssues .. " tests have missing aliases.")
end)

Features & Information

This is an improved version of the original UNC. Change Logs: 1.0.0 - Improved all the existing test functions. - Added getfunctionhash, fireproximityprompt, firetouchinterest, getcallingscript, setclipboard, queue_on_teleport, firesignal, and replicatesignal. Note: All the improved and added test functions are based on UNC and sUNC documentation.
#UNC#Unified Naming Convention#Universal Script#Executor

Community Comments (0)

No comments yet for this script.

More Scripts for Universal Scripts