mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Add test for async custom instance methods in roblox builtin
This commit is contained in:
parent
ec6060a6cb
commit
37afe7b05e
2 changed files with 23 additions and 12 deletions
|
@ -128,10 +128,6 @@ fn implement_property(
|
||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// TODO: Wrap getter and setter functions in async compat layers,
|
|
||||||
// the roblox library does not know about the Lune runtime or the
|
|
||||||
// scheduler and users may want to call async functions, some of
|
|
||||||
// which are not obvious that they are async such as print, warn, ...
|
|
||||||
InstanceRegistry::insert_property_getter(lua, &class_name, &property_name, property_getter)
|
InstanceRegistry::insert_property_getter(lua, &class_name, &property_name, property_getter)
|
||||||
.into_lua_err()?;
|
.into_lua_err()?;
|
||||||
InstanceRegistry::insert_property_setter(lua, &class_name, &property_name, property_setter)
|
InstanceRegistry::insert_property_setter(lua, &class_name, &property_name, property_setter)
|
||||||
|
@ -143,7 +139,6 @@ fn implement_method(
|
||||||
lua: &Lua,
|
lua: &Lua,
|
||||||
(class_name, method_name, method): (String, String, LuaFunction),
|
(class_name, method_name, method): (String, String, LuaFunction),
|
||||||
) -> LuaResult<()> {
|
) -> LuaResult<()> {
|
||||||
// TODO: Same as above, wrap the provided method in an async compat layer
|
|
||||||
InstanceRegistry::insert_method(lua, &class_name, &method_name, method).into_lua_err()?;
|
InstanceRegistry::insert_method(lua, &class_name, &method_name, method).into_lua_err()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,28 @@
|
||||||
|
local net = require("@lune/net")
|
||||||
local roblox = require("@lune/roblox")
|
local roblox = require("@lune/roblox")
|
||||||
|
|
||||||
local game = roblox.Instance.new("DataModel")
|
roblox.implementMethod("HttpService", "GetAsync", function(_, url: string)
|
||||||
local http = game:GetService("HttpService") :: any
|
local response = net.request({
|
||||||
|
method = "GET",
|
||||||
roblox.implementMethod("HttpService", "GetAsync", function()
|
url = url,
|
||||||
-- TODO: Fill in method body
|
})
|
||||||
|
return response.body
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- TODO: Fill in rest of test cases here
|
roblox.implementMethod("HttpService", "JSONDecode", function(_, value)
|
||||||
|
return net.jsonDecode(value)
|
||||||
|
end)
|
||||||
|
|
||||||
http:GetAsync()
|
-- Reference: https://create.roblox.com/docs/reference/engine/classes/HttpService#GetAsync
|
||||||
|
|
||||||
|
local URL_ASTROS = "http://api.open-notify.org/astros.json"
|
||||||
|
|
||||||
|
local game = roblox.Instance.new("DataModel")
|
||||||
|
local HttpService = game:GetService("HttpService") :: any
|
||||||
|
|
||||||
|
local response = HttpService:GetAsync(URL_ASTROS)
|
||||||
|
local data = HttpService:JSONDecode(response)
|
||||||
|
|
||||||
|
assert(type(data) == "table", "Returned JSON data should decode to a table")
|
||||||
|
assert(data.message == "success", "Returned JSON data should have a 'message' with value 'success'")
|
||||||
|
assert(type(data.people) == "table", "Returned JSON data should have a 'people' table")
|
||||||
|
|
Loading…
Reference in a new issue