#[cfg(test)]
mod test {
use crate::{DiagnosticCode, VirtualWorkspace};
#[test]
fn test_1() {
let mut ws = VirtualWorkspace::new();
ws.def(
r#"
---@return any ...
---@return integer offset
local function unpack() end
a, b, c, d = unpack()
"#,
);
assert_eq!(ws.expr_ty("a"), ws.ty("any"));
assert_eq!(ws.expr_ty("b"), ws.ty("integer"));
assert_eq!(ws.expr_ty("c"), ws.ty("nil"));
assert_eq!(ws.expr_ty("d"), ws.ty("nil"));
}
#[test]
fn test_2() {
let mut ws = VirtualWorkspace::new();
ws.def(
r#"
---@return integer offset
---@return any ...
local function unpack() end
a, b, c, d = unpack()
"#,
);
assert_eq!(ws.expr_ty("a"), ws.ty("integer"));
assert_eq!(ws.expr_ty("b"), ws.ty("any"));
assert_eq!(ws.expr_ty("c"), ws.ty("any"));
assert_eq!(ws.expr_ty("d"), ws.ty("any"));
}
#[test]
fn test_3() {
let mut ws = VirtualWorkspace::new();
assert!(ws.check_code_for(
DiagnosticCode::ParamTypeMismatch,
r#"
---@return any ...
---@return integer offset
local function unpack() end
---@param a nil|integer|'l'|'L'
local function test(a) end
local len = unpack()
test(len)
"#,
));
}
}