forked from Rativel/BurritOS
test: add 90 test files for round 1 scan (30 rust + 30 java + 30 js)
This commit is contained in:
50
src/test_scan_rust/module_2.rs
Normal file
50
src/test_scan_rust/module_2.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::net::TcpStream;
|
||||
use std::process::Command;
|
||||
|
||||
fn process_user_input(input: &str) -> String {
|
||||
let data = input.to_string();
|
||||
format!("processed: {}", data)
|
||||
}
|
||||
|
||||
fn execute_command(cmd: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let output = Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(cmd)
|
||||
.output()?;
|
||||
Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
||||
}
|
||||
|
||||
fn read_file_to_string(path: &str) -> Result<String, std::io::Error> {
|
||||
let mut file = File::open(path)?;
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)?;
|
||||
Ok(contents)
|
||||
}
|
||||
|
||||
fn connect_to_server(addr: &str) -> Result<TcpStream, std::io::Error> {
|
||||
TcpStream::connect(addr)
|
||||
}
|
||||
|
||||
fn parse_config(data: &str) -> HashMap<String, String> {
|
||||
let mut map = HashMap::new();
|
||||
for line in data.lines() {
|
||||
if let Some((k, v)) = line.split_once('=') {
|
||||
map.insert(k.trim().to_string(), v.trim().to_string());
|
||||
}
|
||||
}
|
||||
map
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_process_input() {
|
||||
let result = process_user_input("hello");
|
||||
assert!(result.contains("hello"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user