mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-25 10:31:02 -05:00
refactor(dict): Make codegen more specific
This commit is contained in:
parent
4c91f16ae1
commit
b798780a13
3 changed files with 8 additions and 9 deletions
|
@ -1,3 +1,3 @@
|
||||||
mod dict_codegen;
|
mod word_codegen;
|
||||||
|
|
||||||
pub use crate::dict_codegen::WORD_TRIE;
|
pub use crate::word_codegen::WORD_TRIE;
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
const DICT: &[u8] = include_bytes!("../assets/words.csv");
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn codegen() {
|
fn codegen() {
|
||||||
let mut content = vec![];
|
let mut content = vec![];
|
||||||
generate(&mut content);
|
const DICT: &[u8] = include_bytes!("../assets/words.csv");
|
||||||
|
generate(&mut content, "WORD", DICT);
|
||||||
|
|
||||||
let content = String::from_utf8(content).unwrap();
|
let content = String::from_utf8(content).unwrap();
|
||||||
let content = codegenrs::rustfmt(&content, None).unwrap();
|
let content = codegenrs::rustfmt(&content, None).unwrap();
|
||||||
snapbox::assert_eq_path("./src/dict_codegen.rs", content);
|
snapbox::assert_eq_path("./src/word_codegen.rs", content);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate<W: std::io::Write>(file: &mut W) {
|
fn generate<W: std::io::Write>(file: &mut W, prefix: &str, dict: &[u8]) {
|
||||||
writeln!(
|
writeln!(
|
||||||
file,
|
file,
|
||||||
"// This file is @generated by {}",
|
"// This file is @generated by {}",
|
||||||
|
@ -23,13 +22,13 @@ fn generate<W: std::io::Write>(file: &mut W) {
|
||||||
let records: Vec<_> = csv::ReaderBuilder::new()
|
let records: Vec<_> = csv::ReaderBuilder::new()
|
||||||
.has_headers(false)
|
.has_headers(false)
|
||||||
.flexible(true)
|
.flexible(true)
|
||||||
.from_reader(DICT)
|
.from_reader(dict)
|
||||||
.records()
|
.records()
|
||||||
.map(|r| r.unwrap())
|
.map(|r| r.unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
dictgen::generate_trie(
|
dictgen::generate_trie(
|
||||||
file,
|
file,
|
||||||
"WORD",
|
prefix,
|
||||||
"&'static [&'static str]",
|
"&'static [&'static str]",
|
||||||
records.iter().map(|record| {
|
records.iter().map(|record| {
|
||||||
let mut record_fields = record.iter();
|
let mut record_fields = record.iter();
|
||||||
|
|
Loading…
Reference in a new issue