-
Notifications
You must be signed in to change notification settings - Fork 83
/
check_file.rs
93 lines (77 loc) · 3.02 KB
/
check_file.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
mod data;
use assert_fs::prelude::*;
use typos_cli::file::FileChecker;
#[divan::bench(args = data::DATA)]
fn found_files(bencher: divan::Bencher, sample: &data::Data) {
let dict = typos_cli::dict::BuiltIn::new(Default::default());
let tokenizer = typos::tokens::Tokenizer::new();
let policy = typos_cli::policy::Policy::new()
.dict(&dict)
.tokenizer(&tokenizer);
let temp = assert_fs::TempDir::new().unwrap();
let sample_path = temp.child(sample.name());
sample_path.write_str(sample.content()).unwrap();
bencher
.counter(divan::counter::BytesCount::of_str(sample.content()))
.bench_local(|| {
typos_cli::file::FoundFiles.check_file(sample_path.path(), true, &policy, &PrintSilent)
})
}
#[divan::bench(args = data::DATA)]
fn identifiers(bencher: divan::Bencher, sample: &data::Data) {
let dict = typos_cli::dict::BuiltIn::new(Default::default());
let tokenizer = typos::tokens::Tokenizer::new();
let policy = typos_cli::policy::Policy::new()
.dict(&dict)
.tokenizer(&tokenizer);
let temp = assert_fs::TempDir::new().unwrap();
let sample_path = temp.child(sample.name());
sample_path.write_str(sample.content()).unwrap();
bencher
.counter(divan::counter::BytesCount::of_str(sample.content()))
.bench_local(|| {
typos_cli::file::Identifiers.check_file(sample_path.path(), true, &policy, &PrintSilent)
})
}
#[divan::bench(args = data::DATA)]
fn words(bencher: divan::Bencher, sample: &data::Data) {
let dict = typos_cli::dict::BuiltIn::new(Default::default());
let tokenizer = typos::tokens::Tokenizer::new();
let policy = typos_cli::policy::Policy::new()
.dict(&dict)
.tokenizer(&tokenizer);
let temp = assert_fs::TempDir::new().unwrap();
let sample_path = temp.child(sample.name());
sample_path.write_str(sample.content()).unwrap();
bencher
.counter(divan::counter::BytesCount::of_str(sample.content()))
.bench_local(|| {
typos_cli::file::Words.check_file(sample_path.path(), true, &policy, &PrintSilent)
})
}
#[divan::bench(args = data::DATA)]
fn typos(bencher: divan::Bencher, sample: &data::Data) {
let dict = typos_cli::dict::BuiltIn::new(Default::default());
let tokenizer = typos::tokens::Tokenizer::new();
let policy = typos_cli::policy::Policy::new()
.dict(&dict)
.tokenizer(&tokenizer);
let temp = assert_fs::TempDir::new().unwrap();
let sample_path = temp.child(sample.name());
sample_path.write_str(sample.content()).unwrap();
bencher
.counter(divan::counter::BytesCount::of_str(sample.content()))
.bench_local(|| {
typos_cli::file::Typos.check_file(sample_path.path(), true, &policy, &PrintSilent)
})
}
#[derive(Debug, Default)]
pub struct PrintSilent;
impl typos_cli::report::Report for PrintSilent {
fn report(&self, _msg: typos_cli::report::Message) -> Result<(), std::io::Error> {
Ok(())
}
}
fn main() {
divan::main();
}