mirror of
https://github.com/MrBeanCpp/MIT.git
synced 2026-02-07 04:13:50 +08:00
45 lines
1.0 KiB
Rust
45 lines
1.0 KiB
Rust
use sha1::{Sha1, Digest};
|
|
use std::fs::File;
|
|
use std::io::{Write, BufReader, BufRead, Error};
|
|
use mit::utils::util;
|
|
|
|
#[test]
|
|
fn test_hash() {
|
|
let mut hasher = Sha1::new();
|
|
hasher.update(String::from("hello world"));
|
|
let result = format!("{:x}", hasher.finalize());
|
|
println!("{}", result);
|
|
println!("{}", util::calc_hash(&String::from("hello world")));
|
|
}
|
|
|
|
#[test]
|
|
fn test_write() -> Result<(), Error> {
|
|
util::setup_test_with_mit();
|
|
let path = "lines.txt";
|
|
//create会截断文件
|
|
let mut output = File::create(path)?; // ? 用于传播错误
|
|
write!(output, "Rust\nWrite\nRead4")?;
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn test_read() -> Result<(), Error> {
|
|
util::setup_test_with_mit();
|
|
let path = "lines.txt";
|
|
let input = File::open(path)?;
|
|
let buffered = BufReader::new(input);
|
|
|
|
for line in buffered.lines() {
|
|
println!("{}", line?);
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn test_string() {
|
|
let mut s = String::from("Hello");
|
|
s.push_str(", world!");
|
|
s += "2";
|
|
s.push('!');
|
|
println!("{}", s);
|
|
} |