#[cfg(test)]
mod tests {
use crate::*;
#[test]
fn switch_basic() {
let source = r#"
Sub Test()
result = Switch(x = 1, "One", x = 2, "Two", True, "Other")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_variable_assignment() {
let source = r#"
Sub Test()
Dim grade As String
grade = Switch(score >= 90, "A", score >= 80, "B", True, "F")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_grade_calculation() {
let source = r#"
Sub Test()
grade = Switch(score >= 90, "A", score >= 80, "B", score >= 70, "C", True, "F")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_function_return() {
let source = r#"
Function GetStatus(code As Integer) As String
GetStatus = Switch(code = 0, "OK", code = 1, "Warning", True, "Error")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_if_statement() {
let source = r"
Sub Test()
If Switch(status = 1, True, status = 2, True, True, False) Then
ProcessItem
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_msgbox() {
let source = r#"
Sub Test()
MsgBox Switch(day = 1, "Monday", day = 2, "Tuesday", True, "Other")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_select_case() {
let source = r#"
Sub Test()
Select Case Switch(type = 1, "A", type = 2, "B", True, "C")
Case "A"
DoSomething
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_for_loop() {
let source = r#"
Sub Test()
For i = 1 To 10
value = Switch(i < 5, "Low", i < 8, "Mid", True, "High")
Next i
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_array_assignment() {
let source = r#"
Sub Test()
categories(i) = Switch(values(i) < 10, "Small", values(i) < 100, "Medium", True, "Large")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_function_argument() {
let source = r#"
Sub Test()
Call DisplayMessage(Switch(level = 1, "Info", level = 2, "Warning", True, "Error"))
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_comparison() {
let source = r"
Sub Test()
If Switch(x > 10, True, y > 10, True, True, False) Then
ProcessData
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_debug_print() {
let source = r#"
Sub Test()
Debug.Print Switch(flag, "Enabled", True, "Disabled")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_do_while() {
let source = r"
Sub Test()
Do While Switch(counter < 10, True, True, False)
counter = counter + 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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_do_until() {
let source = r#"
Sub Test()
Do Until Switch(status = "Done", True, True, False)
status = Process()
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_while_wend() {
let source = r"
Sub Test()
While Switch(i < max, True, True, False)
i = i + 1
Wend
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_iif() {
let source = r#"
Sub Test()
result = IIf(flag, Switch(x = 1, "A", True, "B"), "Default")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_with_statement() {
let source = r#"
Sub Test()
With obj
.Status = Switch(.Value > 100, "High", .Value > 50, "Medium", True, "Low")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_parentheses() {
let source = r"
Sub Test()
result = (Switch(a > b, a, True, b))
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_error_handling() {
let source = r#"
Sub Test()
On Error Resume Next
category = Switch(val < 0, "Negative", val = 0, "Zero", True, "Positive")
If Err.Number <> 0 Then
category = "Error"
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_property_assignment() {
let source = r#"
Sub Test()
obj.Priority = Switch(urgent, "High", important, "Medium", True, "Low")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_concatenation() {
let source = r#"
Sub Test()
message = "Status: " & Switch(code = 0, "OK", code = 1, "Error", True, "Unknown")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_numeric_result() {
let source = r"
Sub Test()
discount = Switch(qty >= 100, 0.2, qty >= 50, 0.1, qty >= 10, 0.05, True, 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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_print_statement() {
let source = r#"
Sub Test()
Print #1, Switch(type = 1, "Type A", type = 2, "Type B", True, "Unknown")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_class_usage() {
let source = r#"
Sub Test()
Set obj = New DataProcessor
obj.Category = Switch(value > 1000, "A", value > 100, "B", True, "C")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_nested() {
let source = r#"
Sub Test()
result = Switch(x > 0, Switch(x > 100, "Large", True, "Small"), True, "Negative")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_elseif() {
let source = r#"
Sub Test()
If x = 1 Then
y = "One"
ElseIf x = 2 Then
y = Switch(z > 0, "Two-Positive", True, "Two-Negative")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn switch_complex_conditions() {
let source = r#"
Sub Test()
priority = Switch(urgent And important, "Critical", urgent, "High", important, "Medium", True, "Low")
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/logic/switch");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
}