Skip to content

Commit

Permalink
Config files for new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed Jan 13, 2025
1 parent c941aba commit b3cf2ad
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 7 deletions.
1 change: 1 addition & 0 deletions notes.org
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Options and documentation
** Args struct
** OptionArgs struct
** OptionArgs new function
** Implement Default, Display, from for Args
** CLI command
** CLI args parser function
Expand Down
31 changes: 31 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,37 @@ impl Default for OptionArgs {
}
}

impl OptionArgs {
pub fn new() -> Self {
Self {
check: None,
print: None,
fail_on_change: None,
wrap: None,
wraplen: None,
wrapmin: None,
tabsize: None,
tabchar: None,
stdin: None,
config: None,
noconfig: None,
lists: vec![
"itemize",
"enumerate",
"description",
"inlineroman",
"inventory",
]
.into_iter()
.map(std::borrow::ToOwned::to_owned)
.collect(),
verbosity: None,
arguments: None,
files: vec![],
}
}
}

/// Get all arguments from CLI, config file, and defaults, and merge them
pub fn get_args() -> Args {
let mut args = get_cli_args();
Expand Down
50 changes: 43 additions & 7 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
use crate::args::*;
use crate::config::*;
use crate::format::format_file;
use crate::logging::*;
use colored::Colorize;
use merge::Merge;
use similar::{ChangeTag, TextDiff};
use std::fs;
use std::path::PathBuf;

fn test_file(source_file: &str, target_file: &str) -> bool {
let args = Args::default();
fn test_file(
source_file: &str,
target_file: &str,
config_file: Option<PathBuf>,
) -> bool {
// Get arguments from config file if it exists
let mut args = OptionArgs::new();
args.config = config_file;
let config = get_config(&args);
let config_args = get_config_args(config);
if let Some(c) = config_args {
args.merge(c);
}
args.merge(OptionArgs::default());
let args = Args::from(args);

let mut logs = Vec::<Log>::new();
let source_text = fs::read_to_string(source_file).unwrap();
let target_text = fs::read_to_string(target_file).unwrap();
Expand Down Expand Up @@ -63,9 +79,19 @@ fn test_source() {
for file in source_files {
let in_file = test_dir.path().join("source").join(file.clone());
let out_file = test_dir.path().join("target").join(file.clone());
let config_file = test_dir.path().join("tex-fmt.toml");
let config_file = if config_file.exists() {
Some(config_file)
} else {
None
};
dbg!(&in_file);
if !test_file(in_file.to_str().unwrap(), out_file.to_str().unwrap())
{
dbg!(&config_file);
if !test_file(
in_file.to_str().unwrap(),
out_file.to_str().unwrap(),
config_file,
) {
panic!("Failed in {file}");
}
}
Expand All @@ -81,9 +107,17 @@ fn test_target() {
let target_files = read_files_from_dir(&target_dir);
for file in target_files {
let in_file = test_dir.path().join("target").join(file.clone());
dbg!(&in_file);
if !test_file(in_file.to_str().unwrap(), in_file.to_str().unwrap())
{
let config_file = test_dir.path().join("tex-fmt.toml");
let config_file = if config_file.exists() {
Some(config_file)
} else {
None
};
if !test_file(
in_file.to_str().unwrap(),
in_file.to_str().unwrap(),
config_file,
) {
panic!("Failed in {file}");
}
}
Expand All @@ -102,12 +136,14 @@ fn test_short() {
if !test_file(
&format!("tests/{source_file}"),
&format!("tests/{target_file}"),
None,
) {
fail = true;
}
if !test_file(
&format!("tests/{target_file}"),
&format!("tests/{target_file}"),
None,
) {
fail = true;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/tabsize/source/tabsize.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
\documentclass{article}

\begin{document}

\begin{itemize}
\item Lists with items
over multiple lines
\end{itemize}

\begin{equation}
E = m c^2
\end{equation}

\end{document}
14 changes: 14 additions & 0 deletions tests/tabsize/target/tabsize.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
\documentclass{article}

\begin{document}

\begin{itemize}
\item Lists with items
over multiple lines
\end{itemize}

\begin{equation}
E = m c^2
\end{equation}

\end{document}
1 change: 1 addition & 0 deletions tests/tabsize/tex-fmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tabsize = 4

0 comments on commit b3cf2ad

Please sign in to comment.