const DEFAULT_N_MESSAGES_TO_PRINT: usize = 100;
#[derive(Clone, Debug)]
pub struct Opts {
pub(crate) make_post_table: bool,
pub(crate) max_n_errors: usize,
pub(crate) compile_gsub: bool,
pub(crate) compile_gpos: bool,
}
impl Opts {
pub fn new() -> Self {
Self::default()
}
pub fn make_post_table(mut self, flag: bool) -> Self {
self.make_post_table = flag;
self
}
pub fn max_error_messages(mut self, max_n_errors: usize) -> Self {
self.max_n_errors = max_n_errors;
self
}
pub fn compile_gpos(mut self, flag: bool) -> Self {
self.compile_gpos = flag;
self
}
pub fn compile_gsub(mut self, flag: bool) -> Self {
self.compile_gsub = flag;
self
}
}
impl Default for Opts {
fn default() -> Self {
Self {
make_post_table: false,
max_n_errors: DEFAULT_N_MESSAGES_TO_PRINT,
compile_gsub: true,
compile_gpos: true,
}
}
}
#[cfg(test)]
mod tests {
static OSWALD_DIR: &str = "./test-data/real-files/oswald";
use std::path::Path;
use crate::{
compile::{Compilation, MockVariationInfo, NopFeatureProvider},
Compiler,
};
use super::*;
#[test]
fn skip_tables() {
fn compile_oswald(opts: Opts) -> Compilation {
let glyph_order = Path::new(OSWALD_DIR).join("glyph_order.txt");
let features = Path::new(OSWALD_DIR).join("features.fea");
let glyph_order = std::fs::read_to_string(glyph_order).unwrap();
let glyph_order = crate::compile::parse_glyph_order(&glyph_order).unwrap();
Compiler::<NopFeatureProvider, MockVariationInfo>::new(features, &glyph_order)
.with_opts(opts)
.compile()
.unwrap()
}
let compilation = compile_oswald(Opts::new());
assert!(compilation.gpos.is_some());
assert!(compilation.gsub.is_some());
let compilation = compile_oswald(Opts::new().compile_gsub(false));
assert!(compilation.gpos.is_some());
assert!(compilation.gsub.is_none());
let compilation = compile_oswald(Opts::new().compile_gpos(false));
assert!(compilation.gpos.is_none());
assert!(compilation.gsub.is_some());
}
}