mirror of
https://github.com/crate-ci/typos.git
synced 2024-12-24 08:32:10 -05:00
46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
const DICT: &[u8] = include_bytes!("../assets/words.csv");
|
|
|
|
#[test]
|
|
fn codegen() {
|
|
let mut content = vec![];
|
|
generate(&mut content);
|
|
|
|
let content = String::from_utf8(content).unwrap();
|
|
let content = codegenrs::rustfmt(&content, None).unwrap();
|
|
snapbox::assert_eq_path("./src/dict_codegen.rs", content);
|
|
}
|
|
|
|
fn generate<W: std::io::Write>(file: &mut W) {
|
|
writeln!(
|
|
file,
|
|
"// This file is @generated by {}",
|
|
file!().replace('\\', "/")
|
|
)
|
|
.unwrap();
|
|
writeln!(file, "#![allow(clippy::unreadable_literal)]",).unwrap();
|
|
writeln!(file).unwrap();
|
|
|
|
let records: Vec<_> = csv::ReaderBuilder::new()
|
|
.has_headers(false)
|
|
.flexible(true)
|
|
.from_reader(DICT)
|
|
.records()
|
|
.map(|r| r.unwrap())
|
|
.collect();
|
|
dictgen::generate_trie(
|
|
file,
|
|
"WORD",
|
|
"&'static [&'static str]",
|
|
records.iter().map(|record| {
|
|
let mut record_fields = record.iter();
|
|
let key = record_fields.next().unwrap();
|
|
let value = format!(
|
|
"&[{}]",
|
|
itertools::join(record_fields.map(|field| format!(r#""{}""#, field)), ", ")
|
|
);
|
|
(key, value)
|
|
}),
|
|
64,
|
|
)
|
|
.unwrap();
|
|
}
|