mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Implement tests for color sequences
This commit is contained in:
parent
b662b86922
commit
de656fa26b
5 changed files with 89 additions and 11 deletions
|
@ -5,7 +5,7 @@ use rbx_dom_weak::types::{
|
||||||
ColorSequence as RbxColorSequence, ColorSequenceKeypoint as RbxColorSequenceKeypoint,
|
ColorSequence as RbxColorSequence, ColorSequenceKeypoint as RbxColorSequenceKeypoint,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{Color3, ColorSequenceKeypoint};
|
use super::{super::*, Color3, ColorSequenceKeypoint};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
An implementation of the [ColorSequence](https://create.roblox.com/docs/reference/engine/datatypes/ColorSequence) Roblox datatype.
|
An implementation of the [ColorSequence](https://create.roblox.com/docs/reference/engine/datatypes/ColorSequence) Roblox datatype.
|
||||||
|
@ -62,6 +62,11 @@ impl LuaUserData for ColorSequence {
|
||||||
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
|
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) {
|
||||||
fields.add_field_method_get("Keypoints", |_, this| Ok(this.keypoints.clone()));
|
fields.add_field_method_get("Keypoints", |_, this| Ok(this.keypoints.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||||
|
methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq);
|
||||||
|
methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ColorSequence {
|
impl fmt::Display for ColorSequence {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use core::fmt;
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use rbx_dom_weak::types::ColorSequenceKeypoint as RbxColorSequenceKeypoint;
|
use rbx_dom_weak::types::ColorSequenceKeypoint as RbxColorSequenceKeypoint;
|
||||||
|
|
||||||
use super::Color3;
|
use super::{super::*, Color3};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
An implementation of the [ColorSequenceKeypoint](https://create.roblox.com/docs/reference/engine/datatypes/ColorSequenceKeypoint) Roblox datatype.
|
An implementation of the [ColorSequenceKeypoint](https://create.roblox.com/docs/reference/engine/datatypes/ColorSequenceKeypoint) Roblox datatype.
|
||||||
|
@ -33,6 +33,11 @@ impl LuaUserData for ColorSequenceKeypoint {
|
||||||
fields.add_field_method_get("Time", |_, this| Ok(this.time));
|
fields.add_field_method_get("Time", |_, this| Ok(this.time));
|
||||||
fields.add_field_method_get("Value", |_, this| Ok(this.color));
|
fields.add_field_method_get("Value", |_, this| Ok(this.color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||||
|
methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq);
|
||||||
|
methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ColorSequenceKeypoint {
|
impl fmt::Display for ColorSequenceKeypoint {
|
||||||
|
|
|
@ -38,13 +38,15 @@ macro_rules! create_tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
create_tests! {
|
create_tests! {
|
||||||
datatypes_brick_color: "datatypes/BrickColor",
|
datatypes_brick_color: "datatypes/BrickColor",
|
||||||
datatypes_color3: "datatypes/Color3",
|
datatypes_color3: "datatypes/Color3",
|
||||||
datatypes_enum: "datatypes/Enum",
|
datatypes_color_sequence: "datatypes/ColorSequence",
|
||||||
datatypes_udim: "datatypes/UDim",
|
datatypes_color_sequence_keypoint: "datatypes/ColorSequenceKeypoint",
|
||||||
datatypes_udim2: "datatypes/UDim2",
|
datatypes_enum: "datatypes/Enum",
|
||||||
datatypes_vector2: "datatypes/Vector2",
|
datatypes_udim: "datatypes/UDim",
|
||||||
datatypes_vector2int16: "datatypes/Vector2int16",
|
datatypes_udim2: "datatypes/UDim2",
|
||||||
datatypes_vector3: "datatypes/Vector3",
|
datatypes_vector2: "datatypes/Vector2",
|
||||||
datatypes_vector3int16: "datatypes/Vector3int16",
|
datatypes_vector2int16: "datatypes/Vector2int16",
|
||||||
|
datatypes_vector3: "datatypes/Vector3",
|
||||||
|
datatypes_vector3int16: "datatypes/Vector3int16",
|
||||||
}
|
}
|
||||||
|
|
36
tests/roblox/datatypes/ColorSequence.luau
Normal file
36
tests/roblox/datatypes/ColorSequence.luau
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
-- HACK: Make luau happy, with the mlua rust
|
||||||
|
-- crate all globals are also present in _G
|
||||||
|
local Color3 = _G.Color3
|
||||||
|
local ColorSequence = _G.ColorSequence
|
||||||
|
local ColorSequenceKeypoint = _G.ColorSequenceKeypoint
|
||||||
|
|
||||||
|
-- Constructors & properties
|
||||||
|
|
||||||
|
ColorSequence.new(Color3.new())
|
||||||
|
ColorSequence.new(Color3.new(), Color3.new())
|
||||||
|
local sequence = ColorSequence.new({
|
||||||
|
ColorSequenceKeypoint.new(0, Color3.new(1, 0, 0)),
|
||||||
|
ColorSequenceKeypoint.new(0.5, Color3.new(0, 1, 0)),
|
||||||
|
ColorSequenceKeypoint.new(1, Color3.new(0, 0, 1)),
|
||||||
|
})
|
||||||
|
|
||||||
|
assert(not pcall(function()
|
||||||
|
return ColorSequence.new()
|
||||||
|
end))
|
||||||
|
assert(not pcall(function()
|
||||||
|
return ColorSequence.new(0.5)
|
||||||
|
end))
|
||||||
|
assert(not pcall(function()
|
||||||
|
return ColorSequence.new(false)
|
||||||
|
end))
|
||||||
|
assert(not pcall(function()
|
||||||
|
return ColorSequence.new("", "")
|
||||||
|
end))
|
||||||
|
assert(not pcall(function()
|
||||||
|
return ColorSequence.new(newproxy(true))
|
||||||
|
end))
|
||||||
|
|
||||||
|
assert(#sequence.Keypoints == 3)
|
||||||
|
assert(sequence.Keypoints[1] == ColorSequenceKeypoint.new(0, Color3.new(1, 0, 0)))
|
||||||
|
assert(sequence.Keypoints[2] == ColorSequenceKeypoint.new(0.5, Color3.new(0, 1, 0)))
|
||||||
|
assert(sequence.Keypoints[3] == ColorSequenceKeypoint.new(1, Color3.new(0, 0, 1)))
|
30
tests/roblox/datatypes/ColorSequenceKeypoint.luau
Normal file
30
tests/roblox/datatypes/ColorSequenceKeypoint.luau
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
-- HACK: Make luau happy, with the mlua rust
|
||||||
|
-- crate all globals are also present in _G
|
||||||
|
local Color3 = _G.Color3
|
||||||
|
local ColorSequenceKeypoint = _G.ColorSequenceKeypoint
|
||||||
|
|
||||||
|
-- Constructors & properties
|
||||||
|
|
||||||
|
ColorSequenceKeypoint.new(0, Color3.new())
|
||||||
|
ColorSequenceKeypoint.new(1, Color3.new())
|
||||||
|
|
||||||
|
assert(not pcall(function()
|
||||||
|
return ColorSequenceKeypoint.new()
|
||||||
|
end))
|
||||||
|
assert(not pcall(function()
|
||||||
|
return ColorSequenceKeypoint.new(0.5)
|
||||||
|
end))
|
||||||
|
assert(not pcall(function()
|
||||||
|
return ColorSequenceKeypoint.new(false)
|
||||||
|
end))
|
||||||
|
assert(not pcall(function()
|
||||||
|
return ColorSequenceKeypoint.new("", "")
|
||||||
|
end))
|
||||||
|
assert(not pcall(function()
|
||||||
|
return ColorSequenceKeypoint.new(newproxy(true))
|
||||||
|
end))
|
||||||
|
|
||||||
|
assert(ColorSequenceKeypoint.new(0, Color3.new()).Time == 0)
|
||||||
|
assert(ColorSequenceKeypoint.new(1, Color3.new()).Time == 1)
|
||||||
|
assert(ColorSequenceKeypoint.new(0, Color3.new()).Value == Color3.new())
|
||||||
|
assert(ColorSequenceKeypoint.new(1, Color3.new(1)).Value == Color3.new(1))
|
Loading…
Reference in a new issue