#[cfg(test)]
mod tests {
use crate::*;
#[test]
fn ascb_simple_character() {
let source = r#"
Sub Test()
byteVal = AscB("A")
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_extended_ansi() {
let source = r"
Sub Test()
code = AscB(extendedChar)
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_control_character() {
let source = r"
Sub Test()
tabByte = AscB(vbTab)
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_is_ascii_function() {
let source = r"
Function IsASCII(char As String) As Boolean
If Len(char) = 0 Then Exit Function
IsASCII = (AscB(char) < 128)
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_is_control_char() {
let source = r"
Function IsControlChar(char As String) As Boolean
Dim byteVal As Integer
byteVal = AscB(char)
IsControlChar = (byteVal < 32 Or byteVal = 127)
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_compare_bytes() {
let source = r"
Function CompareBytes(str1 As String, str2 As String) As Integer
CompareBytes = AscB(str1) - AscB(str2)
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_checksum_calculation() {
let source = r"
Function SimpleChecksum(text As String) As Long
Dim i As Long
For i = 1 To Len(text)
checksum = checksum + AscB(Mid(text, i, 1))
Next i
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_detect_line_ending() {
let source = r#"
Function DetectLineEnding(text As String) As String
Dim byteVal As Integer
byteVal = AscB(Mid(text, 1, 1))
If byteVal = 13 Then
DetectLineEnding = "CR"
End If
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_byte_to_hex() {
let source = r#"
Function ByteToHex(char As String) As String
Dim byteVal As Integer
byteVal = AscB(char)
ByteToHex = Right("0" & Hex(byteVal), 2)
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_case_insensitive_compare() {
let source = r"
Function ByteEqualsIgnoreCase(char1 As String, char2 As String) As Boolean
Dim byte1 As Integer, byte2 As Integer
byte1 = AscB(char1)
byte2 = AscB(char2)
ByteEqualsIgnoreCase = (byte1 = byte2)
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_filter_printable() {
let source = r"
Function FilterPrintable(text As String) As String
Dim byteVal As Integer
byteVal = AscB(Mid(text, 1, 1))
If byteVal >= 32 And byteVal <= 126 Then
result = result & Mid(text, 1, 1)
End If
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_url_encoding_check() {
let source = r"
Function NeedsURLEncoding(char As String) As Boolean
Dim byteVal As Integer
byteVal = AscB(char)
If byteVal >= 48 And byteVal <= 57 Then
NeedsURLEncoding = False
End If
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_binary_parser() {
let source = r"
Function ParseBinaryHeader(data As String) As Variant
Dim header As Variant
header(1) = AscB(Mid(data, 1, 1))
header(2) = AscB(Mid(data, 2, 1))
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_xor_encrypt() {
let source = r"
Function XOREncrypt(text As String, key As String) As String
Dim textByte As Integer, keyByte As Integer
textByte = AscB(Mid(text, 1, 1))
keyByte = AscB(Mid(key, 1, 1))
result = ChrB(textByte Xor keyByte)
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_csv_parser() {
let source = r"
Function ParseCSVField(field As String) As String
Dim byteVal As Integer
byteVal = AscB(Mid(field, 1, 1))
If byteVal = 34 Then
inQuotes = True
End If
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_charset_validator() {
let source = r"
Function ValidateCharacterSet(text As String, validSet As String) As Boolean
Dim textByte As Integer
textByte = AscB(Mid(text, 1, 1))
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_safe_wrapper() {
let source = r"
Function SafeAscB(text As String) As Integer
If Len(text) = 0 Then
SafeAscB = -1
Exit Function
End If
SafeAscB = AscB(text)
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_in_loop() {
let source = r"
Sub Test()
For i = 1 To Len(text)
byteVal = AscB(Mid(text, i, 1))
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_with_mid_function() {
let source = r"
Sub Test()
firstByte = AscB(Mid(myString, 1, 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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
#[test]
fn ascb_in_conditional() {
let source = r"
Sub Test()
If AscB(char) >= 65 And AscB(char) <= 90 Then
isUpper = True
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/string/ascb");
settings.set_prepend_module_to_snapshot(false);
let _guard = settings.bind_to_scope();
insta::assert_yaml_snapshot!(tree);
}
}