#[cfg(test)]
mod tests {
use crate::*;
#[test]
fn second_basic() {
let source = r"
Dim sec As Integer
sec = Second(Now)
";
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_time_string() {
let source = r#"
Dim seconds As Integer
seconds = Second("3:45:30 PM")
"#;
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_if_statement() {
let source = r#"
If Second(Now) = 0 Then
MsgBox "New minute!"
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_function_return() {
let source = r"
Function GetSeconds(timeValue As Date) As Integer
GetSeconds = Second(timeValue)
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_variable_assignment() {
let source = r"
Dim s As Integer
s = Second(currentTime)
";
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_msgbox() {
let source = r#"
MsgBox "Second: " & Second(Time)
"#;
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_debug_print() {
let source = r"
Debug.Print Second(Now)
";
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_select_case() {
let source = r#"
Select Case Second(Now)
Case 0 To 15
msg = "First quarter"
Case 16 To 30
msg = "Second quarter"
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_class_usage() {
let source = r"
Private m_seconds As Integer
Public Sub UpdateTime()
m_seconds = Second(Now)
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_with_statement() {
let source = r"
With timeData
.Seconds = Second(.TimeValue)
End With
";
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_elseif() {
let source = r#"
If Second(t) < 30 Then
half = "First"
ElseIf Second(t) >= 30 Then
half = "Second"
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_for_loop() {
let source = r"
For i = 1 To 10
timestamps(i) = Second(times(i))
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_do_while() {
let source = r"
Do While Second(Now) < 30
DoSomething
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_do_until() {
let source = r"
Do Until Second(currentTime) = 0
currentTime = Now
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_while_wend() {
let source = r"
While Second(Now) > 45
Wait
Wend
";
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_parentheses() {
let source = r"
Dim val As Integer
val = (Second(Now))
";
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_iif() {
let source = r#"
Dim display As String
display = IIf(Second(Now) < 10, "0" & Second(Now), Second(Now))
"#;
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_array_assignment() {
let source = r"
Dim seconds(10) As Integer
seconds(i) = Second(timeArray(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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_property_assignment() {
let source = r"
Set obj = New TimeData
obj.SecondValue = Second(Now)
";
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_function_argument() {
let source = r"
Call LogTime(Second(Now))
";
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_concatenation() {
let source = r#"
Dim msg As String
msg = "Seconds: " & Second(Time)
"#;
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_comparison() {
let source = r#"
If Second(time1) = Second(time2) Then
MsgBox "Same second"
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_modulo() {
let source = r"
If Second(Now) Mod 15 = 0 Then
UpdateDisplay
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_with_format() {
let source = r#"
Dim formatted As String
formatted = Format(Second(Now), "00")
"#;
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_date_literal() {
let source = r"
Dim s As Integer
s = Second(#1/15/2000 10:30:45 AM#)
";
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_error_handling() {
let source = r"
On Error Resume Next
Dim sec As Integer
sec = Second(userInput)
If Err.Number <> 0 Then
sec = 0
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn second_on_error_goto() {
let source = r#"
Sub GetTimeSecond()
On Error GoTo ErrorHandler
Dim s As Integer
s = Second(timeValue)
Exit Sub
ErrorHandler:
MsgBox "Error getting second"
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/datetime/second");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
}