add gs
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# Generated by Rotriever. Format subject to change in future releases.
|
||||
name = "roblox/lua-symbol"
|
||||
version = "0.1.0"
|
||||
commit = "139fdfe6e4d4eca690887d3beb80e1514af501bf"
|
||||
source = "git+https://github.rbx.com/roblox/lua-symbol#master"
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
--[[
|
||||
A 'Symbol' is an opaque marker type that can be used to signify unique
|
||||
statuses. Symbols have the type 'userdata', but when printed to the console,
|
||||
the name of the symbol is shown.
|
||||
]]
|
||||
|
||||
local Symbol = {}
|
||||
|
||||
--[[
|
||||
Creates a Symbol with the given name.
|
||||
|
||||
When printed or coerced to a string, the symbol will turn into the string
|
||||
given as its name.
|
||||
]]
|
||||
function Symbol.named(name)
|
||||
assert(type(name) == "string", "Symbols must be created using a string name!")
|
||||
|
||||
local self = newproxy(true)
|
||||
|
||||
local wrappedName = ("Symbol(%s)"):format(name)
|
||||
|
||||
getmetatable(self).__tostring = function()
|
||||
return wrappedName
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--[[
|
||||
Create an unnamed Symbol. Usually, you should create a named Symbol using
|
||||
Symbol.named(name)
|
||||
]]
|
||||
function Symbol.unnamed()
|
||||
local self = newproxy(true)
|
||||
|
||||
getmetatable(self).__tostring = function()
|
||||
return "Unnamed Symbol"
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return Symbol
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
return function()
|
||||
local Symbol = require(script.Parent.Symbol)
|
||||
|
||||
describe("named", function()
|
||||
it("should give an opaque object", function()
|
||||
local symbol = Symbol.named("foo")
|
||||
|
||||
expect(symbol).to.be.a("userdata")
|
||||
end)
|
||||
|
||||
it("should coerce to the given name", function()
|
||||
local symbol = Symbol.named("foo")
|
||||
|
||||
expect(tostring(symbol):find("foo")).to.be.ok()
|
||||
end)
|
||||
|
||||
it("should be unique when constructed", function()
|
||||
local symbolA = Symbol.named("abc")
|
||||
local symbolB = Symbol.named("abc")
|
||||
|
||||
expect(symbolA).never.to.equal(symbolB)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("unnamed", function()
|
||||
it("should give an opaque object", function()
|
||||
local symbol = Symbol.unnamed()
|
||||
|
||||
expect(symbol).to.be.a("userdata")
|
||||
end)
|
||||
|
||||
it("should coerce to some string", function()
|
||||
local symbol = Symbol.unnamed()
|
||||
|
||||
expect(tostring(symbol)).to.be.a("string")
|
||||
end)
|
||||
|
||||
it("should be unique when constructed", function()
|
||||
local symbolA = Symbol.unnamed()
|
||||
local symbolB = Symbol.unnamed()
|
||||
|
||||
expect(symbolA).never.to.equal(symbolB)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
+1
@@ -0,0 +1 @@
|
||||
return require(script.Symbol)
|
||||
Reference in New Issue
Block a user