#[cfg(test)]
mod tests {
use crate::*;
#[test]
fn doevents_basic() {
let source = r"
DoEvents
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_with_parentheses() {
let source = r"
DoEvents()
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_in_loop() {
let source = r"
For i = 1 To 10000
ProcessItem i
If i Mod 100 = 0 Then DoEvents
Next i
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_with_assignment() {
let source = r"
formCount = DoEvents()
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_in_do_loop() {
let source = r"
Do Until EOF(1)
ProcessLine line
DoEvents
Loop
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_cancellable_operation() {
let source = r"
For i = 1 To 100000
If cancelOperation Then Exit For
ProcessItem i
If i Mod 100 = 0 Then DoEvents
Next i
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_with_status_update() {
let source = r#"
lblStatus.Caption = "Processing..."
DoEvents
ProcessData
"#;
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_progress_bar() {
let source = r"
ProgressBar1.Value = i
DoEvents
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_while_loop() {
let source = r#"
Do While fileName <> ""
ProcessFile fileName
fileName = Dir
DoEvents
Loop
"#;
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_batch_update() {
let source = r"
Do Until rs.EOF
rs.Update
If count Mod 25 = 0 Then DoEvents
rs.MoveNext
Loop
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_multi_step() {
let source = r#"
lblStatus.Caption = "Step 1"
DoEvents
LoadData
lblStatus.Caption = "Step 2"
DoEvents
ProcessData
"#;
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_in_function() {
let source = r"
Function ProcessData() As Boolean
Dim i As Long
For i = 1 To 1000
ProcessItem i
DoEvents
Next i
ProcessData = True
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_with_error_handling() {
let source = r"
On Error Resume Next
For i = 1 To 10000
ProcessItem i
DoEvents
Next i
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_reentrancy_guard() {
let source = r"
If isProcessing Then Exit Sub
isProcessing = True
For i = 1 To 1000
DoEvents
Next i
isProcessing = False
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_file_processing() {
let source = r"
Do Until EOF(fileNum)
Line Input #fileNum, line
ProcessLine line
lineCount = lineCount + 1
If lineCount Mod 100 = 0 Then DoEvents
Loop
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_conditional() {
let source = r"
If Timer - lastUpdate > 0.1 Then
DoEvents
lastUpdate = Timer
End If
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_select_case() {
let source = r"
Select Case step
Case 1
x = DoEvents()
ProcessStep1
Case 2
y = DoEvents()
ProcessStep2
End Select
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_nested_loop() {
let source = r"
For i = 1 To 100
For j = 1 To 100
Process i, j
Next j
DoEvents
Next i
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_with_sleep() {
let source = r"
Do Until processingComplete
DoEvents
Sleep 10
Loop
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_search_operation() {
let source = r#"
fileName = Dir("*.*")
Do While fileName <> ""
If InStr(fileName, searchTerm) > 0 Then
lstResults.AddItem fileName
End If
DoEvents
fileName = Dir
Loop
"#;
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_animation() {
let source = r"
For i = 1 To 100
shpIndicator.Left = i * 50
DoEvents
Next i
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_inline_if() {
let source = r"
If i Mod 100 = 0 Then DoEvents Else ProcessFast
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_record_processing() {
let source = r"
For Each item In collection
ProcessItem item
DoEvents
Next item
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_export() {
let source = r#"
For i = 1 To recordCount
ExportRecord i
If i Mod 50 = 0 Then
lblProgress.Caption = i & " exported"
DoEvents
End If
Next i
"#;
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn doevents_with_call() {
let source = r"
Call DoEvents
";
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/interaction/doevents",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
}