#[cfg(test)]
mod tests {
use crate::*;
#[test]
fn command_dollar_simple() {
let source = r"
Sub Main()
args = Command$()
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_assignment() {
let source = r"
Sub Main()
Dim cmdLine As String
cmdLine = Command$()
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_in_condition() {
let source = r#"
Sub Main()
If Command$() <> "" Then
MsgBox "Arguments provided"
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_with_trim() {
let source = r"
Sub Main()
filename = Trim$(Command$())
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_with_instr() {
let source = r#"
Sub Main()
If InStr(Command$(), "/debug") > 0 Then
EnableDebug
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_parse_args() {
let source = r#"
Function ParseArguments() As Collection
Dim args As String
args = Command$()
If args = "" Then Exit Function
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/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_multiple_checks() {
let source = r#"
Sub Main()
Dim args As String
args = Command$()
If InStr(args, "/debug") > 0 Then Debug = True
If InStr(args, "/silent") > 0 Then Silent = True
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_file_opener() {
let source = r#"
Sub Main()
Dim filename As String
filename = Trim$(Command$())
If filename <> "" Then
OpenFile filename
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_with_split() {
let source = r#"
Sub Main()
Dim parts() As String
parts = Split(Command$(), " ")
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_logging() {
let source = r#"
Sub Main()
Dim logFile As Integer
logFile = FreeFile
Print #logFile, "Args: " & Command$()
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_ucase() {
let source = r"
Sub Main()
Dim args As String
args = UCase$(Command$())
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_lcase() {
let source = r"
Sub Main()
args = LCase$(Trim$(Command$()))
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_help_check() {
let source = r#"
Sub Main()
If Command$() = "/?" Then
DisplayHelp
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_replace() {
let source = r#"
Sub Main()
args = Replace$(Command$(), "/batch", "")
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_concatenation() {
let source = r#"
Sub Main()
msg = "Started with: " & Command$()
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_function_call() {
let source = r"
Function HasSwitch(switchName As String) As Boolean
Dim args As String
args = UCase$(Command$())
HasSwitch = (InStr(args, switchName) > 0)
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/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_empty_check() {
let source = r#"
Sub Main()
If Len(Command$()) = 0 Then
MsgBox "No arguments"
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_direct_print() {
let source = r"
Sub Main()
Debug.Print Command$()
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn command_dollar_select_case() {
let source = r#"
Sub Main()
Select Case LCase$(Command$())
Case "/debug"
DebugMode = True
Case "/release"
DebugMode = False
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/interaction/command_dollar",
);
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
}