Skip to content

Commit

Permalink
Merge pull request #1 from LPGhatguy/master
Browse files Browse the repository at this point in the history
Update to master
  • Loading branch information
Validark committed Aug 21, 2019
2 parents 6346da9 + cba91fb commit 69111ac
Show file tree
Hide file tree
Showing 18 changed files with 329 additions and 9 deletions.
8 changes: 7 additions & 1 deletion FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ This document should remain up-to-date with current API coverage and status.
* Vector2
* Vector2.new()
* Vector2.new(x, y)
* Operators: `==`, `+`
* Operators: `==`, `+`, `*`, `/`

## Implemented Instance Members
* AnalyticsService
Expand All @@ -85,6 +85,8 @@ This document should remain up-to-date with current API coverage and status.
* InputBegan
* InputEnded
* LayoutOrder
* MouseEnter
* MouseLeave
* Position
* Selectable
* Size
Expand All @@ -97,11 +99,15 @@ This document should remain up-to-date with current API coverage and status.
* ImageButton
* Image
* ImageColor3
* ImageRectOffset
* ImageRectSize
* ScaleType
* SliceCenter
* ImageLabel
* Image
* ImageColor3
* ImageRectOffset
* ImageRectSize
* ScaleType
* SliceCenter
* Instance
Expand Down
2 changes: 1 addition & 1 deletion lib/functions/warn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local function warn(...)
local count = select("#", ...)
for i = 1, count do
local piece = select(i, ...)
io.stderr:write(piece)
io.stderr:write(tostring(piece))

if i < count then
io.stderr:write("\t")
Expand Down
14 changes: 14 additions & 0 deletions lib/functions/warn_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ describe("functions.warn", function()
assert.spy(writeSpy).was.called(4) -- IT'S DOGE, \t, AAH!, \n
io.stderr = oldErr -- luacheck: ignore
end)

it("should warn with a non-string argument", function()
local oldErr, writeSpy = setupWarnDetour()
warn(1)
assert.spy(writeSpy).was_called_with(io.stderr, "1")
io.stderr = oldErr -- luacheck: ignore
end)

it("should warn with non-string arguments", function()
local oldErr, writeSpy = setupWarnDetour()
warn(2, 3)
assert.spy(writeSpy).was.called(4) -- 2, \t, 3, \n
io.stderr = oldErr -- luacheck: ignore
end)
end)
12 changes: 12 additions & 0 deletions lib/instances/GuiObject.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ GuiObject.properties.LayoutOrder = InstanceProperty.typed("number", {
end,
})

GuiObject.properties.MouseEnter = InstanceProperty.readOnly({
getDefault = function()
return Signal.new()
end,
})

GuiObject.properties.MouseLeave = InstanceProperty.readOnly({
getDefault = function()
return Signal.new()
end,
})

GuiObject.properties.Position = InstanceProperty.typed("UDim2", {
getDefault = function()
return UDim2.new()
Expand Down
2 changes: 2 additions & 0 deletions lib/instances/GuiObject_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe("instances.GuiObject", function()
assert.equal(typeof(instance.InputBegan), "RBXScriptSignal")
assert.equal(typeof(instance.InputEnded), "RBXScriptSignal")
assert.equal(typeof(instance.LayoutOrder), "number")
assert.equal(typeof(instance.MouseEnter), "RBXScriptSignal")
assert.equal(typeof(instance.MouseLeave), "RBXScriptSignal")
assert.equal(typeof(instance.Position), "UDim2")
assert.equal(typeof(instance.Selectable), "boolean")
assert.equal(typeof(instance.Size), "UDim2")
Expand Down
13 changes: 13 additions & 0 deletions lib/instances/ImageButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local GuiButton = import("./GuiButton")
local InstanceProperty = import("../InstanceProperty")
local Rect = import("../types/Rect")
local ScaleType = import("../Enum/ScaleType")
local Vector2 = import("../types/Vector2")

local ImageButton = GuiButton:extend("ImageButton", {
creatable = true,
Expand All @@ -20,6 +21,18 @@ ImageButton.properties.ImageColor3 = InstanceProperty.typed("Color3", {
end,
})

ImageButton.properties.ImageRectOffset = InstanceProperty.typed("Vector2", {
getDefault = function()
return Vector2.new(0, 0)
end,
})

ImageButton.properties.ImageRectSize = InstanceProperty.typed("Vector2", {
getDefault = function()
return Vector2.new(0, 0)
end,
})

ImageButton.properties.ScaleType = InstanceProperty.enum(ScaleType, {
getDefault = function()
return ScaleType.Stretch
Expand Down
2 changes: 2 additions & 0 deletions lib/instances/ImageButton_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe("instances.ImageButton", function()
local instance = Instance.new("ImageButton")
assert.equals(typeof(instance.Image), "string")
assert.equals(typeof(instance.ImageColor3), "Color3")
assert.equals(typeof(instance.ImageRectOffset), "Vector2")
assert.equals(typeof(instance.ImageRectSize), "Vector2")
assert.equals(typeof(instance.ScaleType), "EnumItem")
assert.equal(instance.ScaleType.EnumType, ScaleType)
assert.equals(typeof(instance.SliceCenter), "Rect")
Expand Down
13 changes: 13 additions & 0 deletions lib/instances/ImageLabel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local GuiObject = import("./GuiObject")
local InstanceProperty = import("../InstanceProperty")
local Rect = import("../types/Rect")
local ScaleType = import("../Enum/ScaleType")
local Vector2 = import("../types/Vector2")

local ImageLabel = GuiObject:extend("ImageLabel", {
creatable = true,
Expand All @@ -20,6 +21,18 @@ ImageLabel.properties.ImageColor3 = InstanceProperty.typed("Color3", {
end,
})

ImageLabel.properties.ImageRectOffset = InstanceProperty.typed("Vector2", {
getDefault = function()
return Vector2.new(0, 0)
end,
})

ImageLabel.properties.ImageRectSize = InstanceProperty.typed("Vector2", {
getDefault = function()
return Vector2.new(0, 0)
end,
})

ImageLabel.properties.ScaleType = InstanceProperty.enum(ScaleType, {
getDefault = function()
return ScaleType.Stretch
Expand Down
2 changes: 2 additions & 0 deletions lib/instances/ImageLabel_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe("instances.ImageLabel", function()
local instance = Instance.new("ImageLabel")
assert.equals(typeof(instance.Image), "string")
assert.equals(typeof(instance.ImageColor3), "Color3")
assert.equals(typeof(instance.ImageRectOffset), "Vector2")
assert.equals(typeof(instance.ImageRectSize), "Vector2")
assert.equals(typeof(instance.ScaleType), "EnumItem")
assert.equals(instance.ScaleType.EnumType, ScaleType)
assert.equals(typeof(instance.SliceCenter), "Rect")
Expand Down
14 changes: 13 additions & 1 deletion lib/instances/ScreenGui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,16 @@ ScreenGui.properties.ZIndexBehavior = InstanceProperty.enum(ZIndexBehavior, {
end,
})

return ScreenGui
ScreenGui.properties.Enabled = InstanceProperty.typed("boolean", {
getDefault = function()
return true
end,
})

ScreenGui.properties.OnTopOfCoreBlur = InstanceProperty.typed("boolean", {
getDefault = function()
return false
end,
})

return ScreenGui
4 changes: 3 additions & 1 deletion lib/instances/ScreenGui_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ describe("instances.ScreenGui", function()
assert.equals(typeof(instance.AutoLocalize), "boolean")
assert.equals(typeof(instance.IgnoreGuiInset), "boolean")
assert.equals(typeof(instance.ZIndexBehavior), "EnumItem")
assert.equals(typeof(instance.OnTopOfCoreBlur), "boolean")
assert.equals(typeof(instance.Enabled), "boolean")
assert.equals(instance.ZIndexBehavior.EnumType, ZIndexBehavior)
end)
end)
end)
3 changes: 2 additions & 1 deletion lib/libs/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local names = {
"math",
"string",
}

local libs = {}
Expand All @@ -8,4 +9,4 @@ for _, name in ipairs(names) do
libs[name] = import("./" .. name)
end

return libs
return libs
36 changes: 36 additions & 0 deletions lib/libs/string.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
local rbxString = {}

for key, value in pairs(string) do
rbxString[key] = value
end

rbxString.split = function(str, sep)
local result = {}

if sep == "" then
for i = 1, #str do
result[i] = str:sub(i, i)
end
else
if sep == nil then
sep = ","
end

local count = 1
local pos = 1
local a, b = str:find(sep, pos, true)

while a do
result[count] = str:sub(pos, a - 1)
count = count + 1
pos = b + 1
a, b = str:find(sep, pos, true)
end

result[count] = str:sub(pos)
end

return result
end

return rbxString
98 changes: 98 additions & 0 deletions lib/libs/string_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
local string = import("./string")

describe("libs.string", function()
describe("split", function()
it("should be a function", function()
assert.is_function(string.split)
end)

it("should return an array of comma separated strings if sep is nil", function()
assert.are.same({"Hello", "world", "and", "lemur"}, string.split("Hello,world,and,lemur"))
end)

it("should return an array of all characters in a string if sep is the empty string", function()
assert.are.same({
"H",
"e",
"l",
"l",
"o",
",",
"w",
"o",
"r",
"l",
"d",
",",
"a",
"n",
"d",
",",
"l",
"e",
"m",
"u",
"r",
}, string.split("Hello,world,and,lemur", ""))
end)

it("should return an empty table if the string and sep is the empty string", function()
assert.are.same({}, string.split("", ""))
end)

it("should return the original string in a table if no sep is matched", function()
assert.are.same({"Hello, world"}, string.split("Hello, world", "K"))
assert.are.same({""}, string.split("", " "))
end)

it("should return empty strings at the front and back when seps are present there", function()
assert.are.same({"", "Validark", "Osyris", "Vorlias", ""}, string.split("/Validark/Osyris/Vorlias/", "/"))
assert.are.same({"", "Validark", "Osyris", "Vorlias"}, string.split("/Validark/Osyris/Vorlias", "/"))
assert.are.same({"Validark", "Osyris", "Vorlias", ""}, string.split("Validark/Osyris/Vorlias/", "/"))
assert.are.same({"Validark", "Osyris", "Vorlias"}, string.split("Validark/Osyris/Vorlias", "/"))
end)

it("should allow multi-character separators", function()
assert.are.same({"Hello", "world"}, string.split("Hello, world", ", "))
end)

it("should literally interpret Lua character classes", function()
assert.are.same({"Hello, world"}, string.split("Hello, world", "%l"))
assert.are.same({"Hel", "o, world"}, string.split("Hel%lo, world", "%l"))
end)

it("should match Roblox's internal tests", function()
-- Provided by tiffany352 at https://github.com/LPGhatguy/lemur/pull/190
local char = string.char
local ZWJ = char(0xe2, 0x80, 0x8d)
assert.are.same({ "" }, string.split("", ","))
assert.are.same({ "foo", "", "bar" }, string.split("foo,,bar", ","))
assert.are.same({ "", "foo" }, string.split(",foo", ","))
assert.are.same({ "foo", "" }, string.split("foo,", ","))
assert.are.same({ "", "" }, string.split(",", ","))
assert.are.same({ "", "", "" }, string.split(",,", ","))
assert.are.same({ "" }, string.split("", "~~~"))
assert.are.same({ "~~" }, string.split("~~", "~~~"))
assert.are.same({ "~~ ~~" }, string.split("~~ ~~", "~~~"))
assert.are.same({ "foo", "bar" }, string.split("foo~~~bar", "~~~"))
assert.are.same({ "foo", "", "bar" }, string.split("foo~~~~~~bar", "~~~"))
assert.are.same({ "", "foo" }, string.split("~~~foo", "~~~"))
assert.are.same({ "foo", "" }, string.split("foo~~~", "~~~"))
assert.are.same({ "", "" }, string.split("~~~", "~~~"))
assert.are.same({ "", "", "" }, string.split("~~~~~~", "~~~"))
assert.are.same({ "", "", "O" }, string.split("OOOOO", "OO"))
assert.are.same({ " ws " }, string.split(" ws ", ","))
assert.are.same({ "foo ", " bar" }, string.split("foo , bar", ","))
assert.are.same({ "我很高兴", "你呢?" }, string.split("我很高兴,你呢?", ""))
assert.are.same({ "👩", "👩", "👧", "👧" }, string.split("👩‍👩‍👧‍👧", ZWJ))
assert.are.same({ "foo", "bar" }, string.split("foo\0bar", "\0"))
assert.are.same({ "foo", "bar", "" }, string.split("foo\0bar\0", "\0"))
assert.are.same({ "foo", "bar" }, string.split("foo\0\0bar", "\0\0"))
assert.are.same({ "foo\0" }, string.split("foo\0", "\0\0"))
assert.are.same({ "foo", "\0" }, string.split("foo\0\0\0", "\0\0"))
assert.are.same({ }, string.split("", ""))
assert.are.same({ "a", "b", "c" }, string.split("abc", ""))
assert.are.same({ char(0xef), char(0xbc), char(0x9f) }, string.split("", ""))
end)
end)
end)
25 changes: 25 additions & 0 deletions lib/types/Vector2.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local assign = import("../assign")
local typeKey = import("../typeKey")
local typeof = import("../functions/typeof")

local Vector2 = {}

Expand Down Expand Up @@ -36,6 +37,30 @@ function metatable:__sub(other)
return Vector2.new(self.X - other.X, self.Y - other.Y)
end

function metatable:__mul(other)
if typeof(self) == "Vector2" and typeof(other) == "Vector2" then
return Vector2.new(self.X * other.X, self.Y * other.Y)
elseif typeof(self) == "Vector2" and typeof(other) == "number" then
return Vector2.new(self.X * other, self.Y * other)
elseif typeof(self) == "number" and typeof(other) == "Vector2" then
return Vector2.new(other.X * self, other.Y * self)
else
error("attempt to multiply a Vector2 with an incompatible value type or nil")
end
end

function metatable:__div(other)
if typeof(self) == "Vector2" and typeof(other) == "Vector2" then
return Vector2.new(self.X / other.X, self.Y / other.Y)
elseif typeof(self) == "Vector2" and typeof(other) == "number" then
return Vector2.new(self.X / other, self.Y / other)
elseif typeof(self) == "number" and typeof(other) == "Vector2" then
return Vector2.new(other.X / self, other.Y / self)
else
error("attempt to divide a Vector2 with an incompatible value type or nil")
end
end

function metatable:__eq(other)
return self.X == other.X and self.Y == other.Y
end
Expand Down
Loading

0 comments on commit 69111ac

Please sign in to comment.