-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathundefined_global_test.rs
More file actions
60 lines (54 loc) · 1.59 KB
/
undefined_global_test.rs
File metadata and controls
60 lines (54 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#[cfg(test)]
mod test {
use crate::{DiagnosticCode, VirtualWorkspace};
#[test]
fn test_issue_250() {
let mut ws = VirtualWorkspace::new_with_init_std_lib();
assert!(ws.check_code_for(
DiagnosticCode::UndefinedGlobal,
r#"
--- @class A
--- @field field any
local A = {}
function A:method()
pcall(function()
return self.field
end)
end
"#
));
}
#[test]
fn test_return_cast_self_no_undefined_global() {
let mut ws = VirtualWorkspace::new();
// @return_cast self should not produce undefined-global error in methods
assert!(!ws.check_code_for(
DiagnosticCode::UndefinedGlobal,
r#"
---@class MyClass
local MyClass = {}
---@return_cast self MyClass
function MyClass:check1()
return true
end
"#
));
}
#[test]
fn test_return_cast_self_field_no_undefined_global() {
let mut ws = VirtualWorkspace::new();
// @return_cast self.field should not produce undefined-global error in methods
assert!(!ws.check_code_for(
DiagnosticCode::UndefinedGlobal,
r#"
---@class MyClass
---@field value string|number
local MyClass = {}
---@return_cast self.value string
function MyClass:check_string()
return type(self.value) == "string"
end
"#
));
}
}