#[cfg(test)]
mod tests {
use crate::*;
#[test]
fn array_simple() {
let source = r"
Sub Test()
x = Array(1, 2, 3)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_empty() {
let source = r"
Sub Test()
x = Array()
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_single_element() {
let source = r"
Sub Test()
x = Array(42)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_strings() {
let source = r#"
Sub Test()
names = Array("Alice", "Bob", "Charlie")
End Sub
"#;
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_mixed_types() {
let source = r#"
Sub Test()
mixed = Array("Hello", 42, True, 3.14)
End Sub
"#;
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_with_variables() {
let source = r"
Sub Test()
result = Array(a, b, c, d)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_with_expressions() {
let source = r"
Sub Test()
arr = Array(x + 1, y * 2, z - 3)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_in_dim() {
let source = r"
Sub Test()
Dim data As Variant
data = Array(1, 2, 3, 4, 5)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_function_return() {
let source = r"
Function GetValues() As Variant
GetValues = Array(10, 20, 30)
End Function
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_in_for_each() {
let source = r"
Sub Test()
For Each item In Array(1, 2, 3)
Process item
Next item
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_element_access() {
let source = r#"
Sub Test()
x = Array("A", "B", "C")(0)
End Sub
"#;
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_with_dates() {
let source = r"
Sub Test()
dates = Array(#1/1/2025#, #12/31/2025#)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_with_null() {
let source = r"
Sub Test()
values = Array(Null, Empty, Nothing)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_nested_calls() {
let source = r"
Sub Test()
matrix = Array(Array(1, 2), Array(3, 4))
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_in_function_call() {
let source = r"
Sub Test()
ProcessData Array(1, 2, 3)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_case_insensitive() {
let source = r"
Sub Test()
a = ARRAY(1, 2)
b = array(3, 4)
c = ArRaY(5, 6)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_with_ubound() {
let source = r"
Sub Test()
Dim arr As Variant
arr = Array(1, 2, 3)
Dim size As Integer
size = UBound(arr)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_in_if_condition() {
let source = r"
Sub Test()
If UBound(Array(1, 2, 3)) > 0 Then
Process
End If
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_multiple_calls() {
let source = r#"
Sub Test()
arr1 = Array(1, 2, 3)
arr2 = Array("A", "B", "C")
arr3 = Array(True, False)
End Sub
"#;
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_with_line_continuation() {
let source = r"
Sub Test()
data = Array(1, 2, _
3, 4, _
5, 6)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_preserves_whitespace() {
let source = r"
Sub Test()
x = Array ( 1 , 2 , 3 )
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_in_select_case() {
let source = r"
Sub Test()
Select Case value
Case Array(1, 2, 3)
Process
End Select
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_with_property_access() {
let source = r"
Sub Test()
values = Array(obj.Prop1, obj.Prop2)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_with_function_calls() {
let source = r"
Sub Test()
results = Array(GetA(), GetB(), GetC())
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_in_print() {
let source = r"
Sub Test()
Debug.Print Array(1, 2, 3)(0)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_in_with_block() {
let source = r"
Sub Test()
With myObject
.Data = Array(1, 2, 3)
End With
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_numeric_literals() {
let source = r"
Sub Test()
nums = Array(1%, 2&, 3!, 4#, 5@)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_at_module_level() {
let source = r"
Const DEFAULT_VALUES = Array(0, 1, 2)
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_in_do_loop() {
let source = r"
Sub Test()
Do While i < UBound(Array(1, 2, 3))
i = i + 1
Loop
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn array_long_list() {
let source = r"
Sub Test()
data = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
End Sub
";
let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
let cst = cst_opt.expect("CST should be parsed");
let tree = cst.to_serializable();
let mut settings = insta::Settings::clone_current();
settings
.set_snapshot_path("../../../../../snapshots/syntax/library/functions/arrays/array");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
}