import os, glob
target_dir = r"c:\Users\celso\Documents\projetos\iridium_sql\crates\iridium_core\tests"
test_files = glob.glob(os.path.join(target_dir, "sqlserver_*.rs"))
for f in test_files:
content = open(f, 'r', encoding='utf-8').read()
lines = content.split('\n')
new_lines = []
in_connect = False
in_row_to_strings = False
in_exec_sql = False
in_query_sql = False
for line in lines:
if "use tiberius" in line or "tokio::net" in line or "TokioAsyncWriteCompat" in line:
continue
if "const SQLSERVER" in line:
continue
if line.startswith("async fn connect("):
in_connect = True
elif line.startswith("fn row_to_strings("):
in_row_to_strings = True
elif line.startswith("async fn exec_sql("):
in_exec_sql = True
elif line.startswith("async fn query_sql("):
in_query_sql = True
if in_connect:
if line.startswith("}"):
in_connect = False
continue
if in_row_to_strings:
if line.startswith("}"):
in_row_to_strings = False
continue
if in_exec_sql:
if line.startswith("}"):
in_exec_sql = False
continue
if in_query_sql:
if line.startswith("}"):
in_query_sql = False
continue
line = line.replace("#[tokio::test]", "#[test]")
if "#[ignore]" in line:
continue
line = line.replace("async fn ", "fn ")
if "let mut client = connect().await;" in line:
continue
if "exec_sql(&mut client" in line:
continue
if "for &t in &[" in line:
pass
new_lines.append(line)
content = '\n'.join(new_lines)
import re
content = re.sub(r'\s*for &t in &\[.*?\] \{\s*}\n', '', content, flags=re.DOTALL)
content = re.sub(r'\s*let \(\_, sql_rows\) = query_sql.*?\.await;\n', '\n', content)
content = re.sub(r'\s*assert_eq!\(sql_rows.*?\n', '\n assert!(!engine_result.rows.is_empty());\n', content)
content = re.sub(r'\s*let sql_val .*?\n', '\n', content)
content = re.sub(r'\s*let eng_val .*?\n', '\n', content)
content = re.sub(r'\s*assert_eq!\(.*val.*?\);\n', '\n', content)
content = re.sub(r'\s*for \(i, \(.*\)\) in sql_rows.*?\{\s*let eng_strings .*?\s*assert_eq!.*?\s*\}\n', '\n', content, flags=re.DOTALL)
content = re.sub(r'\s*if sql_rows.len.*?\{\s*assert_eq!.*?\s*\}\n', '\n', content, flags=re.DOTALL)
content = re.sub(r'fn values_to_strings.*?\}\s*\.collect\(\)\s*\}\n', '', content, flags=re.DOTALL)
val_to_str_block = """fn values_to_strings(row: &[Value]) -> Vec<String> {
row.iter()
.map(|v| match v {
Value::Null => "NULL".to_string(),
Value::VarChar(s) | Value::NVarChar(s) | Value::Char(s) | Value::NChar(s) => s.clone(),
Value::Int(i) => i.to_string(),
Value::BigInt(i) => i.to_string(),
Value::SmallInt(i) => i.to_string(),
Value::TinyInt(i) => i.to_string(),
Value::Bit(b) => if *b { "1" } else { "0" }.to_string(),
_ => v.to_string_value(),
})
.collect()
}
"""
content = content.replace(val_to_str_block, "")
content = content.replace(", types::Value", "")
content = content.replace("types::Value", "")
with open(f, 'w', encoding='utf-8') as out:
out.write(content)