#[cfg(test)]
mod tests {
use crate::*;
#[test]
fn error_dollar_current_error() {
let source = r"
Sub Test()
On Error Resume Next
x = 1 / 0
msg = 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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_specific_error() {
let source = r"
Sub Test()
msg = Error$(11)
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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_in_handler() {
let source = r#"
Sub Test()
On Error GoTo ErrHandler
Exit Sub
ErrHandler:
msg = "Error: " & 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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_debug_print() {
let source = r#"
Sub Test()
Debug.Print "Error occurred: " & 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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_formatted_message() {
let source = r#"
Sub Test()
msg = "An error occurred: " & 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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_with_number() {
let source = r#"
Sub Test()
Debug.Print "Error " & Err.Number & ": " & 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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_custom_message() {
let source = r#"
Sub Test()
If Err.Number <> 0 Then
msg = "Operation failed: " & 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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_get_specific() {
let source = r"
Sub Test()
errMsg = Error$(53)
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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_logging() {
let source = r#"
Sub Test()
On Error GoTo ErrHandler
Exit Sub
ErrHandler:
Open "errors.log" For Append As #1
Print #1, Now & ": " & Error$()
Close #1
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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_compare_messages() {
let source = r"
Sub Test()
If Error$() = Error$(11) Then
' Handle division by zero
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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_build_report() {
let source = r#"
Sub Test()
report = "Error Number: " & Err.Number & vbCrLf
report = report & "Description: " & Error$() & vbCrLf
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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_messages() {
let source = r#"
Sub Test()
For i = 1 To 100
Debug.Print i & ": " & Error$(i)
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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_user_dialog() {
let source = r#"
Sub Test()
msg = "Sorry, an error occurred:" & vbCrLf & 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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_conditional_handling() {
let source = r#"
Sub Test()
If InStr(Error$(), "File") > 0 Then
' Handle file-related errors
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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_comprehensive_logger() {
let source = r#"
Sub LogError()
Dim msg As String
msg = "Error " & Err.Number & " at " & Now & vbCrLf
msg = msg & "Description: " & Error$() & vbCrLf
msg = msg & "Source: " & Err.Source & vbCrLf
Debug.Print msg
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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_friendly_translator() {
let source = r#"
Function GetFriendlyError() As String
Select Case Err.Number
Case 11
GetFriendlyError = "Cannot divide by zero"
Case 53
GetFriendlyError = "The file was not found"
Case Else
GetFriendlyError = Error$()
End Select
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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_documentation_generator() {
let source = r#"
Sub DocumentErrors()
Dim i As Integer
Open "errors.txt" For Output As #1
For i = 1 To 1000
If Error$(i) <> "" Then
Print #1, i & vbTab & Error$(i)
End If
Next i
Close #1
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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn error_dollar_testing_utility() {
let source = r"
Function TestError(errNum As Integer) As String
On Error Resume Next
Err.Raise errNum
TestError = Error$()
Err.Clear
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/environment/error_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
}