Compare commits
6 Commits
main
...
legacy_wea
| Author | SHA1 | Date |
|---|---|---|
|
|
5f0ddbeefb | |
|
|
c0d008b6a4 | |
|
|
e838e4e286 | |
|
|
897ea9983a | |
|
|
51bbf45b57 | |
|
|
a155e53b30 |
|
|
@ -27,5 +27,8 @@ Cargo.lock
|
|||
callgrind*
|
||||
cache.out
|
||||
tarpaulin-report.html
|
||||
*.html
|
||||
*.bkp
|
||||
coverage/
|
||||
testdata/
|
||||
# snapshots/
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
cargo-features = ["codegen-backend"]
|
||||
# cargo-features = ["edition2024"]
|
||||
|
||||
[workspace]
|
||||
|
|
@ -13,7 +14,10 @@ version = "0.2.0"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[profile.dev]
|
||||
debug = 0
|
||||
debug = true
|
||||
strip = false
|
||||
codegen-backend = "cranelift"
|
||||
split-debuginfo = "off"
|
||||
# codegen-backend = "cranelift"
|
||||
|
||||
[profile.release]
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 23%"><title>test-coverage: 23%</title><linearGradient id="bms-446d4cb5ae0bdc86" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-446d4cb5ae0bdc86"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-446d4cb5ae0bdc86)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#e05d44"/><rect width="122" height="18" fill="url(#bms-446d4cb5ae0bdc86)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">23%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">23%</text></g></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 38%"><title>test-coverage: 38%</title><linearGradient id="bms-ef2093ce1077dbe3" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-ef2093ce1077dbe3"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-ef2093ce1077dbe3)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#e05d44"/><rect width="122" height="18" fill="url(#bms-ef2093ce1077dbe3)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">38%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">38%</text></g></svg>
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
|
@ -7,3 +7,6 @@ edition = "2024"
|
|||
clap = { version = "4.5.28", features = ["derive"] }
|
||||
phf = { version = "0.11.3", features = ["macros"] }
|
||||
serde = { version = "1.0.217", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
insta = { version = "1.42.2", features = ["yaml"] }
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ static HELP_STR_TO_GRAPH: LazyLock<String> = LazyLock::new(|| {
|
|||
});
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
/// All target type
|
||||
pub enum GraphTargetType {
|
||||
/// Make all graphs
|
||||
|
|
@ -71,11 +72,30 @@ impl From<&str> for GraphTargetType {
|
|||
}
|
||||
}
|
||||
|
||||
// #[cfg(test)]
|
||||
// mod tests {
|
||||
// use super::*;
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::graph::HELP_STR_TO_GRAPH;
|
||||
|
||||
// #[test]
|
||||
// fn it_works() {}
|
||||
// }
|
||||
//
|
||||
use super::GraphTargetType;
|
||||
|
||||
#[test]
|
||||
fn test_help_str() {
|
||||
/// Doc comment
|
||||
insta::assert_yaml_snapshot!(HELP_STR_TO_GRAPH.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_block_prog_and_verbosity() {
|
||||
assert_eq!(GraphTargetType::from("generate"), GraphTargetType::Generate);
|
||||
assert_eq!(GraphTargetType::from("gen"), GraphTargetType::Generate);
|
||||
assert_eq!(GraphTargetType::from("remove"), GraphTargetType::Remove);
|
||||
assert_eq!(GraphTargetType::from("clean"), GraphTargetType::Remove);
|
||||
assert_eq!(GraphTargetType::from("init"), GraphTargetType::Init);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_bad_graph() {
|
||||
let _ = GraphTargetType::from("bad_graph");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,3 +148,41 @@ impl From<&str> for MakeTargets {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::make::{
|
||||
HELP_BLOCK_SELECTION, HELP_BUILD_TARGET_LIST, HELP_VERBOSITY_LEVEL, VerboseLevel,
|
||||
};
|
||||
|
||||
use super::MakeTargets;
|
||||
|
||||
#[test]
|
||||
fn test_help_str() {
|
||||
insta::assert_yaml_snapshot!(HELP_BLOCK_SELECTION.to_string());
|
||||
insta::assert_yaml_snapshot!(HELP_VERBOSITY_LEVEL.to_string());
|
||||
insta::assert_yaml_snapshot!(HELP_BUILD_TARGET_LIST.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_block_prog_and_verbosity() {
|
||||
assert_eq!(VerboseLevel::from("misc"), VerboseLevel::Misc);
|
||||
assert_eq!(VerboseLevel::from("box"), VerboseLevel::Box);
|
||||
assert_eq!(VerboseLevel::from("context"), VerboseLevel::Context);
|
||||
assert_eq!(VerboseLevel::from("info"), VerboseLevel::Info);
|
||||
assert_eq!(VerboseLevel::from("warning"), VerboseLevel::Warning);
|
||||
assert_eq!(VerboseLevel::from("error"), VerboseLevel::Error);
|
||||
assert_eq!(VerboseLevel::from("critical"), VerboseLevel::Critical);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_bad_verbose() {
|
||||
let _ = VerboseLevel::from("bad_level");
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_bad_make() {
|
||||
let _ = MakeTargets::from("bad_make");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: config/src/graph.rs
|
||||
expression: HELP_STR_TO_GRAPH.to_string()
|
||||
---
|
||||
"init, generate, gen, clean, remove"
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: config/src/make.rs
|
||||
expression: HELP_VERBOSITY_LEVEL.to_string()
|
||||
---
|
||||
"box, context, critical, error, info, misc, warning"
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: config/src/make.rs
|
||||
expression: HELP_BUILD_TARGET_LIST.to_string()
|
||||
---
|
||||
"clean, list, glossaries, all"
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: config/src/make.rs
|
||||
expression: HELP_BLOCK_SELECTION.to_string()
|
||||
---
|
||||
"block, cargo, class, cool, curse, fade, fine, load, neo, rough, vert"
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: config/src/tablegen.rs
|
||||
expression: HELP_STR_TO_TARGET_TABLES.to_string()
|
||||
---
|
||||
"all, classes, craft, files"
|
||||
|
|
@ -9,6 +9,7 @@ use std::sync::LazyLock;
|
|||
|
||||
/// An enumeration representing different target types.
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(test, derive(serde::Serialize))]
|
||||
pub enum TableGenerationTarget {
|
||||
/// Processes all classes
|
||||
Classes,
|
||||
|
|
@ -97,3 +98,26 @@ pub struct Craft {
|
|||
/// The no_headers table end string formatter
|
||||
pub end_empty: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::tablegen::{HELP_STR_TO_TARGET_TABLES, TableGenerationTarget};
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_bad_targets() {
|
||||
let _ = TableGenerationTarget::from("bob");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_targets() {
|
||||
let _ = TableGenerationTarget::from("all");
|
||||
let _ = TableGenerationTarget::from("files");
|
||||
let _ = TableGenerationTarget::from("craft");
|
||||
let _ = TableGenerationTarget::from("classes");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_str_gen() {
|
||||
insta::assert_yaml_snapshot!(HELP_STR_TO_TARGET_TABLES.to_string());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
//!
|
||||
#![warn(missing_docs)]
|
||||
#![warn(clippy::missing_docs_in_private_items)]
|
||||
#![feature(coverage_attribute)]
|
||||
#![coverage(off)]
|
||||
|
||||
// Workspace
|
||||
use graphs::make_graphs;
|
||||
|
|
|
|||
|
|
@ -14,3 +14,6 @@ phf = { version = "0.11.3", features = ["macros"] }
|
|||
regex = "1.11.1"
|
||||
regex_static = "0.1.1"
|
||||
serde = { version = "1.0.217", features = ["derive", "alloc"] }
|
||||
|
||||
[dev-dependencies]
|
||||
insta = { version = "1.42.2", features = ["yaml"] }
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
//! The following functions are re-exported from the module `tablegen`:
|
||||
//!
|
||||
//! - [`table_gen`]: Handling the whole conversion and auto dispatch.
|
||||
|
||||
#![feature(coverage_attribute)]
|
||||
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
|
||||
mod table_structs;
|
||||
mod table_types;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tablegen/src/tablegen.rs
|
||||
expression: "make_latex_string(\"🩸⚡☽◅⧆Ø⌭☆🗘½0.5& ++ (++) (--) -★★★ ★★★ +★★★\")"
|
||||
---
|
||||
"\\blood{}\\gauge{}\\slash{}\\pierce{}\\blunt{}\\o{}\\torque{}\\ddzero{}\\reload{}\\sfrac{1}{2}\\sfrac{1}{2}\\& ++ $(++)$ $(--)$ \\ddmod{-}{3} \\ddlvl{3} \\ddmod{+}{3}"
|
||||
|
|
@ -8,6 +8,7 @@ use regex_static::once_cell::sync::Lazy;
|
|||
/// All the type of tsv that can be processed by the program
|
||||
// #[enum_dispatch]
|
||||
#[derive(Clone)]
|
||||
#[cfg_attr(test, derive(Debug, PartialEq))]
|
||||
pub enum TableTargets {
|
||||
/// A class tsv
|
||||
Classes,
|
||||
|
|
@ -51,3 +52,37 @@ pub(super) static RE_STARS: Lazy<Regex> = regex_static::lazy_regex!(r"★+");
|
|||
pub(super) static RE_PLUS_STARS: Lazy<Regex> = regex_static::lazy_regex!(r"([\+-])(★+)");
|
||||
/// The regex for finding all (+/-) and replacing them with mathmode
|
||||
pub(super) static RE_MATHS: Lazy<Regex> = regex_static::lazy_regex!(r"\([\+-]+\)");
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::table_structs::{RE_MATHS, RE_PLUS_STARS, RE_STARS};
|
||||
|
||||
#[test]
|
||||
fn test_regex() {
|
||||
assert_eq!(RE_STARS.find("Bob ★★★★ zz").unwrap().as_str(), "★★★★");
|
||||
assert!(RE_STARS.find("Bob zz").is_none());
|
||||
|
||||
assert_eq!(
|
||||
RE_PLUS_STARS
|
||||
.captures("Bob +★★★★ zz")
|
||||
.unwrap()
|
||||
.get(2)
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
"★★★★"
|
||||
);
|
||||
assert_eq!(
|
||||
RE_PLUS_STARS
|
||||
.captures("Bob -★★★★ zz")
|
||||
.unwrap()
|
||||
.get(2)
|
||||
.unwrap()
|
||||
.as_str(),
|
||||
"★★★★"
|
||||
);
|
||||
assert!(RE_PLUS_STARS.captures("Bob ★★★★ zz").is_none());
|
||||
assert_eq!(RE_MATHS.find("Bob (+++)").unwrap().as_str(), "(+++)");
|
||||
assert_eq!(RE_MATHS.find("Bob (--)").unwrap().as_str(), "(--)");
|
||||
assert!(RE_MATHS.find("Bob -- ++ ").is_none());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
//! This module consists of several submodules:
|
||||
//! - `table_structs`: Defines the structure and behavior of tables.
|
||||
//! - `table_types`: Contains types related to TSV files and LaTeX code generation.
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use config::tablegen::{TableArgs, TableGenerationTarget};
|
||||
use glob::glob;
|
||||
use regex::Captures;
|
||||
|
|
@ -46,6 +46,7 @@ use crate::{
|
|||
/// Generate the tables for the specified files
|
||||
///
|
||||
/// In charge of the dispatch and the whole conversion
|
||||
#[coverage(off)] // DISPATCH: Can't cover a dispatch
|
||||
pub fn table_gen(args: &TableArgs, config: &Config) -> Result<()> {
|
||||
let list_files = match args.kind {
|
||||
TableGenerationTarget::Classes => {
|
||||
|
|
@ -83,6 +84,7 @@ pub fn table_gen(args: &TableArgs, config: &Config) -> Result<()> {
|
|||
}
|
||||
|
||||
/// Process any type of file, one by one and call the right converter function
|
||||
#[coverage(off)] // IO: This function does I/O and can't be tested
|
||||
fn process_files(list_files: &mut Vec<PathBuf>, args: &TableArgs, config: &Config) -> Result<()> {
|
||||
for f in list_files {
|
||||
if let Err(e) = process_one_file(f, args, config) {
|
||||
|
|
@ -93,6 +95,7 @@ fn process_files(list_files: &mut Vec<PathBuf>, args: &TableArgs, config: &Confi
|
|||
}
|
||||
|
||||
/// Process one file
|
||||
#[coverage(off)] // IO: This function does I/O and can't be tested
|
||||
fn process_one_file(f: &mut PathBuf, args: &TableArgs, config: &Config) -> Result<()> {
|
||||
let tt = extract_type(f)?;
|
||||
let tsv: Box<dyn WriteTable> = match tt {
|
||||
|
|
@ -107,13 +110,18 @@ fn process_one_file(f: &mut PathBuf, args: &TableArgs, config: &Config) -> Resul
|
|||
}
|
||||
|
||||
#[inline]
|
||||
#[coverage(off)] // INLINE: The coverage is badly reported it is however covered in the testing scenario
|
||||
/// Extract the type of target of the given file
|
||||
fn extract_type(f: &Path) -> Result<&TableTargets> {
|
||||
let key = &f
|
||||
.file_name()
|
||||
.context("The filename of can't be extracted...skipping")?
|
||||
.to_str()
|
||||
.context("Can't convert filename to string")?[7..10];
|
||||
.context("Can't convert filename to string")?;
|
||||
if key.len() < 10 {
|
||||
return Err(anyhow!("Filename doens't have the correct formatting"));
|
||||
}
|
||||
let key = &key[7..10]; // TODO[!]: Horrible practice, clean this
|
||||
STR_TO_TARGET_FULL.get(key).with_context(|| {
|
||||
format!(
|
||||
"Could not find the type of file given based on the prefix of your file ({})\n\
|
||||
|
|
@ -128,6 +136,7 @@ fn extract_type(f: &Path) -> Result<&TableTargets> {
|
|||
|
||||
/// List all files matching a pattern in the given directory
|
||||
#[inline]
|
||||
#[coverage(off)] // IO: This function does I/O and can't be tested
|
||||
fn list_dir(pattern: &str) -> Vec<PathBuf> {
|
||||
// println!("{}", pattern);
|
||||
// println!("{:?}", glob(pattern));
|
||||
|
|
@ -143,6 +152,7 @@ fn list_dir(pattern: &str) -> Vec<PathBuf> {
|
|||
/// This function reads in a TSV file, processes its contents according to the provided configuration,
|
||||
/// and writes out the resulting LaTeX code as a string. If an error occurs during processing or writing,
|
||||
/// it will be returned as part of the result.
|
||||
#[coverage(off)] // BAD_IO: This function does I/O and can't be tested
|
||||
pub fn export_tsv(
|
||||
f: &Path,
|
||||
tsv: Box<dyn WriteTable>,
|
||||
|
|
@ -197,6 +207,7 @@ pub(super) fn make_latex_string(arg: &str) -> String {
|
|||
///
|
||||
/// This function reads in a tab-separated values (TSV) file and returns it as a Table object,
|
||||
/// which can be used to generate LaTeX code or perform other operations on the data.
|
||||
#[coverage(off)] // BAD_IO: This function does I/O and can't be tested
|
||||
fn read_tsv_classes<T>(filename: &T) -> Result<ClassesArray, Error>
|
||||
where
|
||||
T: AsRef<Path>,
|
||||
|
|
@ -231,6 +242,7 @@ where
|
|||
/// Reads a TSV file into a table.
|
||||
///
|
||||
/// Reads a tab-separated values (TSV) file and deserializes its contents into a table.
|
||||
#[coverage(off)] // BAD_IO: This function does I/O and can't be tested
|
||||
fn read_generic_tsv(filename: &Path, craft_type: &TableTargets) -> Result<Box<dyn WriteTable>> {
|
||||
let file = File::open(filename)?;
|
||||
let rdr = csv::ReaderBuilder::new()
|
||||
|
|
@ -259,6 +271,7 @@ fn read_generic_tsv(filename: &Path, craft_type: &TableTargets) -> Result<Box<dy
|
|||
///
|
||||
/// This function takes in a Table object and returns its contents as a formatted string,
|
||||
/// which can be used to generate LaTeX code or perform other operations on the data.
|
||||
#[coverage(off)] // BAD_IO: This function does I/O and can't be tested
|
||||
pub(super) fn tsv_to_string(tsv: Box<dyn WriteTable>, config: &Config) -> Result<String> {
|
||||
tsv.write_table(config)
|
||||
}
|
||||
|
|
@ -289,3 +302,66 @@ pub(super) fn tsv_to_string(tsv: Box<dyn WriteTable>, config: &Config) -> Result
|
|||
// let craft_array = CraftArray { row: levels };
|
||||
// Ok(Box::new(craft_array))
|
||||
// }
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::path::Path;
|
||||
|
||||
use crate::{table_structs::TableTargets, tablegen::extract_type};
|
||||
|
||||
use super::make_latex_string;
|
||||
|
||||
#[test]
|
||||
fn test_str_clean() {
|
||||
insta::assert_yaml_snapshot!(make_latex_string(
|
||||
"🩸⚡☽◅⧆Ø⌭☆🗘½0.5& ++ (++) (--) -★★★ ★★★ +★★★"
|
||||
));
|
||||
}
|
||||
#[test]
|
||||
fn test_extension() {
|
||||
Path::new("");
|
||||
|
||||
assert!(extract_type(Path::new("short")).is_err());
|
||||
assert_eq!(
|
||||
extract_type(Path::new("000000-cls")).unwrap(),
|
||||
&TableTargets::Classes
|
||||
);
|
||||
assert_eq!(
|
||||
extract_type(Path::new("000000-fud")).unwrap(),
|
||||
&TableTargets::Food
|
||||
);
|
||||
assert_eq!(
|
||||
extract_type(Path::new("000000-alc")).unwrap(),
|
||||
&TableTargets::Alchemy
|
||||
);
|
||||
assert_eq!(
|
||||
extract_type(Path::new("000000-frg")).unwrap(),
|
||||
&TableTargets::Forge
|
||||
);
|
||||
assert_eq!(
|
||||
extract_type(Path::new("000000-mpi")).unwrap(),
|
||||
&TableTargets::MPieges
|
||||
);
|
||||
assert_eq!(
|
||||
extract_type(Path::new("000000-wpn")).unwrap(),
|
||||
&TableTargets::Weapons
|
||||
);
|
||||
assert_eq!(
|
||||
extract_type(Path::new("000000-arm")).unwrap(),
|
||||
&TableTargets::Armors
|
||||
);
|
||||
assert_eq!(
|
||||
extract_type(Path::new("000000-gdg")).unwrap(),
|
||||
&TableTargets::Gadgets
|
||||
);
|
||||
assert_eq!(
|
||||
extract_type(Path::new("000000-pot")).unwrap(),
|
||||
&TableTargets::Potions
|
||||
);
|
||||
assert_eq!(
|
||||
extract_type(Path::new("000000-trp")).unwrap(),
|
||||
&TableTargets::Traps
|
||||
);
|
||||
assert!(extract_type(Path::new("000000-bad")).is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ more_fields = {path ="../more_fields"}
|
|||
comfy-table = "7.1.4"
|
||||
csv = "1.3.1"
|
||||
probability = "0.20.3"
|
||||
rusqlite = { version = "0.33.0" } # , features = ["bundled"]
|
||||
rusqlite = { version = "0.33.0" , features = ["bundled"]}
|
||||
serde = { version = "1.0.217", features = ["derive"] }
|
||||
serde_rusqlite = "0.37.0"
|
||||
serde_json = { version = "1.0.138", features = ["alloc"] }
|
||||
|
|
@ -24,10 +24,9 @@ regex = "1.11.1"
|
|||
pretty_assertions = "^1.4"
|
||||
logos = "^0.15"
|
||||
clap = { version = "4.5.30", features = ["derive"] }
|
||||
insta = { version = "1.42.2", features = ["yaml"] }
|
||||
|
||||
[[bench]]
|
||||
name = "iter_creation"
|
||||
harness = false
|
||||
|
||||
# [lints.rust]
|
||||
# unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] }
|
||||
|
|
|
|||
|
|
@ -181,3 +181,39 @@ pub fn initial_plot_chart(chart_name: &str, sub_charts: &[&str]) -> Chart {
|
|||
.y_axis(Axis::new().grid_index(2).min(0))
|
||||
.y_axis(Axis::new().grid_index(3).min(0))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::{
|
||||
interfaces::RecipeCollection,
|
||||
weaponry_structs::{Equipement, InitialEquipementList, RefinedEquipementList},
|
||||
};
|
||||
|
||||
use super::{initial_chart, initial_plot_chart};
|
||||
|
||||
#[test]
|
||||
fn test_export() {
|
||||
let data = InitialEquipementList::from_vectored(vec![
|
||||
Equipement::default(),
|
||||
Equipement::default(),
|
||||
]);
|
||||
|
||||
let rdata = RefinedEquipementList::from(data);
|
||||
let _chart = initial_chart("Charto");
|
||||
let _chart2 = initial_plot_chart("Charto", &["Bob", "Bob2", "Bob3", "Bob4"]);
|
||||
add_field_to_chart!(
|
||||
rdata,
|
||||
_chart,
|
||||
(
|
||||
index # &String,
|
||||
dps_safe # f64,
|
||||
),
|
||||
|ref_equipement|{
|
||||
(
|
||||
&ref_equipement.advanced.display_name,
|
||||
ref_equipement.advanced.avg_damage_2a_safe,
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
//! handling of the whole crafting process when the times comes
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::{path::Path, rc::Rc};
|
||||
use std::{path::Path, sync::Arc};
|
||||
|
||||
use more_fields::FieldsAsSlice;
|
||||
use rusqlite::Connection;
|
||||
|
|
@ -148,9 +148,9 @@ where
|
|||
|
||||
/// Type alias represinting the inner function parameter
|
||||
// #![feature(trait_alias)]
|
||||
pub(super) type FilterFunctionType<T> = dyn Fn(&T, &T) -> bool;
|
||||
pub(super) type FilterFunctionType<T> = dyn Fn(&T, &T) -> bool + Send + Sync;
|
||||
/// Type alias representing a filter
|
||||
pub(super) type FilterType<T> = Box<Rc<FilterFunctionType<T>>>;
|
||||
pub(super) type FilterType<T> = Arc<FilterFunctionType<T>>;
|
||||
|
||||
#[derive(Clone)]
|
||||
/// A generic Filtering function
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ pub struct RefinedEquipement {
|
|||
}
|
||||
|
||||
/// The complete equipement list, refined with all advanced stats
|
||||
#[derive(Serialize)]
|
||||
pub struct RefinedEquipementList {
|
||||
/// Inner list of Refined Equipements
|
||||
// TODO[!]: The use of pub stays for the usage of the example showcasing the macro in export
|
||||
|
|
@ -414,3 +415,49 @@ macro_rules! sort_by_size_then {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{AdvancedStats, RefinedEquipementList};
|
||||
use crate::{
|
||||
interfaces::{RecipeCollection, ToAnalysis},
|
||||
weaponry_structs::{
|
||||
Equipement, InitialEquipementList, equipement_structs::InnerEquipementStats,
|
||||
},
|
||||
};
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_export_tex() {
|
||||
todo!()
|
||||
}
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_export_csv() {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_analysis() {
|
||||
let ls = RefinedEquipementList::default();
|
||||
let mut ls = ls.inner_filter(|c| c.inner.rarity == 0);
|
||||
ls.inner_sort(|l, r| l.inner.rarity.cmp(&r.inner.rarity));
|
||||
let _ = std::fs::create_dir("testdata");
|
||||
let _ = std::fs::remove_file("testdata/testgraph.html");
|
||||
let _ = std::fs::remove_file("testdata/testgraph_plots.html");
|
||||
assert!(ls.write_html("testgraph").is_ok());
|
||||
}
|
||||
#[test]
|
||||
fn test_scenario() {
|
||||
let ls = RefinedEquipementList::default();
|
||||
let _chart = ls.make_cross_plots_graph();
|
||||
let _chart2 = ls.make_regular_graph();
|
||||
}
|
||||
#[test]
|
||||
fn test_impls() {
|
||||
let a = AdvancedStats::from(&InnerEquipementStats::random_new());
|
||||
let _ = serde_json::to_string(&a);
|
||||
let ls = InitialEquipementList::from_vectored(vec![Equipement::default()]);
|
||||
let _ = RefinedEquipementList::from(ls);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,22 +111,6 @@ impl Add for DamageType {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::*;
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_fields_serialisation() {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_fields_deserialisation() {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
// // TODO[!]: Implement all the soundness below
|
||||
|
||||
// /// The final enum of all categories to be given to the character sheet
|
||||
|
|
@ -254,6 +238,7 @@ pub enum EquipementTargets {
|
|||
Ranged,
|
||||
}
|
||||
|
||||
#[coverage(off)] // IGNORED: Any test would just be a repeat of this enum
|
||||
impl EquipementTargets {
|
||||
/// Assert wether a target can be applied to an original shape
|
||||
pub fn can_apply_onto(&self, lsh: &WeaponBaseShape) -> bool {
|
||||
|
|
@ -286,3 +271,28 @@ pub enum WeaponBaseSize {
|
|||
Heavy,
|
||||
SuperHeavy,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::weaponry_structs::{DamageMod, DamageType, PhysicalDamageType};
|
||||
|
||||
use super::SpecialField;
|
||||
|
||||
#[test]
|
||||
fn test_impls() {
|
||||
let mut a = SpecialField::new(vec!["a".to_owned(), "b".to_owned()]);
|
||||
assert_eq!((*a).len(), 2);
|
||||
(*a).push("c".to_string());
|
||||
assert_eq!((*a).len(), 3);
|
||||
|
||||
let b = DamageType::new(vec![DamageMod::Primary(PhysicalDamageType::Blunt)]);
|
||||
assert!(matches!(
|
||||
b[0],
|
||||
DamageMod::Primary(PhysicalDamageType::Blunt)
|
||||
));
|
||||
|
||||
println!("{b}");
|
||||
let c = b + DamageType::new(vec![DamageMod::Secondary(PhysicalDamageType::Pierce)]);
|
||||
assert_eq!(c.len(), 2);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
//! These impls are here to either prettify output, or allow for smoother implementation of other traits and inner workings
|
||||
|
||||
use crate::interfaces::FilterFunction;
|
||||
use std::{fmt::Debug, rc::Rc};
|
||||
use std::{fmt::Debug, sync::Arc};
|
||||
|
||||
impl<T> Debug for FilterFunction<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
|
|
@ -14,7 +14,7 @@ impl<T> Debug for FilterFunction<T> {
|
|||
}
|
||||
impl<T> Default for FilterFunction<T> {
|
||||
fn default() -> Self {
|
||||
FilterFunction(Box::new(Rc::new(|_, _| true)))
|
||||
FilterFunction(Arc::new(|_, _| true))
|
||||
}
|
||||
}
|
||||
impl<T> PartialEq for FilterFunction<T> {
|
||||
|
|
@ -32,6 +32,8 @@ mod test {
|
|||
fn test_filter_weapons() {
|
||||
let _ = format!("{:?}", FilterFunction::<Equipement>::default());
|
||||
let r = FilterFunction::<Equipement>::new(&|_, _| false) == FilterFunction::default();
|
||||
|
||||
// const B: LazyLock<&'static dyn Fn(&InnerEquipementStats, &InnerEquipementStats) -> bool> =
|
||||
assert!(r);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,25 +8,23 @@
|
|||
//! Implementations to transform all Specialized equipement into a generic Equipement
|
||||
//! A specific implementation could be preferable, but this simplicity might allow for easier developpement
|
||||
|
||||
use comfy_table::{Table, modifiers::UTF8_ROUND_CORNERS};
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::interfaces::{FilterFunction, Reportable};
|
||||
|
||||
use super::{
|
||||
Equipement, InitialEquipementList,
|
||||
equipement_advanced_repr::RefinedEquipementList,
|
||||
equipement_structs::{
|
||||
EqFinishing, EqMaterial, EqNature, EqShape, InnerEquipementStats,
|
||||
filter_id_unique_and_right_category,
|
||||
EqFinishing, EqMaterial, EqNature, EqShape, FILTER_TRUE, FILTER_UNIQUE_AND_RIGHT_CATEGORY,
|
||||
InnerEquipementStats,
|
||||
},
|
||||
};
|
||||
use crate::interfaces::Reportable;
|
||||
use comfy_table::{Table, modifiers::UTF8_ROUND_CORNERS};
|
||||
use std::fmt::Display;
|
||||
|
||||
impl From<EqShape> for Equipement {
|
||||
fn from(val: EqShape) -> Self {
|
||||
Self {
|
||||
stats: val.stats,
|
||||
..Default::default()
|
||||
filter_function: FILTER_TRUE.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +33,7 @@ impl From<EqMaterial> for Equipement {
|
|||
fn from(val: EqMaterial) -> Self {
|
||||
Self {
|
||||
stats: val.stats,
|
||||
filter_function: FilterFunction::new(filter_id_unique_and_right_category()),
|
||||
filter_function: FILTER_UNIQUE_AND_RIGHT_CATEGORY.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,7 +43,7 @@ impl From<EqNature> for Equipement {
|
|||
Self {
|
||||
stats: val.stats,
|
||||
// Checks that the nature is compatible with the previous iteration
|
||||
filter_function: FilterFunction::new(filter_id_unique_and_right_category()),
|
||||
filter_function: FILTER_UNIQUE_AND_RIGHT_CATEGORY.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +52,7 @@ impl From<EqFinishing> for Equipement {
|
|||
fn from(val: EqFinishing) -> Self {
|
||||
Self {
|
||||
stats: val.stats,
|
||||
..Default::default()
|
||||
filter_function: FILTER_TRUE.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -183,7 +181,10 @@ mod test {
|
|||
weaponry_structs::{
|
||||
Equipement, InitialEquipementList,
|
||||
equipement_advanced_repr::RefinedEquipementList,
|
||||
equipement_structs::{DatabaseEquipementStats, InnerEquipementStats},
|
||||
equipement_structs::{
|
||||
DatabaseEquipementStats, EqFinishing, EqMaterial, EqNature, EqShape,
|
||||
InnerEquipementStats,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -237,5 +238,17 @@ mod test {
|
|||
|
||||
println!("{}", feqlist.get_report(None));
|
||||
println!("{}", eqlist.get_report(None));
|
||||
println!("{}", feqlist.get_report(Some("Title")));
|
||||
println!("{}", eqlist.get_report(Some("Title")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion() {
|
||||
let (_, _, _, _) = (
|
||||
Equipement::from(EqShape::default()),
|
||||
Equipement::from(EqMaterial::default()),
|
||||
Equipement::from(EqNature::default()),
|
||||
Equipement::from(EqFinishing::default()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ pub struct IndividualElementsScenario {
|
|||
|
||||
impl CrossRecipeScenario {
|
||||
/// Generate all the operations to be processed with the current config
|
||||
// TODO[!]: Consider adding to interface
|
||||
///
|
||||
/// This is a very implementation specific step and function internally as a helper
|
||||
fn generate_selected_operation(
|
||||
&self,
|
||||
) -> Result<Vec<InitialEquipementList>, FatalEquipementError> {
|
||||
|
|
@ -141,6 +142,7 @@ impl Scenario for CrossRecipeScenario {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{ConfigEquipementScenario, CrossRecipeScenario};
|
||||
use crate::{
|
||||
interfaces::{RecipeDatabase, Scenario},
|
||||
weaponry_structs::{
|
||||
|
|
@ -149,13 +151,8 @@ mod test {
|
|||
},
|
||||
};
|
||||
|
||||
use super::{ConfigEquipementScenario, CrossRecipeScenario};
|
||||
|
||||
#[test]
|
||||
fn test_scenario() {}
|
||||
#[test]
|
||||
fn test_deserde_into() {
|
||||
let b = CrossRecipeScenario {
|
||||
fn mock_cross_with_db() -> CrossRecipeScenario {
|
||||
let cross_rec_scenario = CrossRecipeScenario {
|
||||
database: EquipementDatabase {
|
||||
conn: rusqlite::Connection::open_in_memory().unwrap(),
|
||||
},
|
||||
|
|
@ -168,16 +165,57 @@ mod test {
|
|||
finishing: None,
|
||||
},
|
||||
};
|
||||
|
||||
b.get_database()
|
||||
cross_rec_scenario
|
||||
.get_database()
|
||||
.initialize_empty_table::<DatabaseEquipementStats>("Finishing")
|
||||
.unwrap();
|
||||
b.get_database()
|
||||
cross_rec_scenario
|
||||
.get_database()
|
||||
.insert_row::<DatabaseEquipementStats>(
|
||||
"Finishing",
|
||||
DatabaseEquipementStats::random_new(),
|
||||
)
|
||||
.unwrap();
|
||||
cross_rec_scenario
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_gen() {
|
||||
let refined_list = CrossRecipeScenario::new_with_config(ConfigEquipementScenario {
|
||||
table_name: "Equipements".into(),
|
||||
db_path: String::new(),
|
||||
shape: None,
|
||||
materials: None,
|
||||
nature: None,
|
||||
finishing: None,
|
||||
})
|
||||
.unwrap();
|
||||
assert!(refined_list.generate_selected_operation().is_err());
|
||||
}
|
||||
#[test]
|
||||
fn test_scenario_with_snapshot() {
|
||||
let path_a = "../databases/weapons.db";
|
||||
let path_b = "./databases/weapons.db";
|
||||
let path = if std::fs::exists(path_a).unwrap() {
|
||||
path_a
|
||||
} else {
|
||||
path_b
|
||||
};
|
||||
let refined_list = CrossRecipeScenario::new_with_config(ConfigEquipementScenario {
|
||||
table_name: "Equipements".into(),
|
||||
db_path: path.into(),
|
||||
shape: Some(()),
|
||||
materials: Some(1),
|
||||
nature: Some(()),
|
||||
finishing: Some(()),
|
||||
})
|
||||
.unwrap();
|
||||
let final_list = refined_list.generate_refined_recipes().unwrap();
|
||||
insta::assert_yaml_snapshot!(final_list);
|
||||
}
|
||||
#[test]
|
||||
fn test_deserde_into() {
|
||||
let b = mock_cross_with_db();
|
||||
<CrossRecipeScenario as Scenario>::get_database(&b);
|
||||
let r = b
|
||||
.deserde_into_processed_representation::<EqFinishing>(None)
|
||||
|
|
|
|||
|
|
@ -2,18 +2,16 @@
|
|||
// File: weaponry/src/weaponry_structs/equipement_structs.rs
|
||||
//! Base equipement structures
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::interfaces::{FilterFunction, FilterFunctionType};
|
||||
use more_fields::FieldsAsSlice;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{
|
||||
DamageType, SpecialField,
|
||||
equipement_fields::{
|
||||
EquipementSerializedCategory, EquipementTargets, WeaponBaseShape, WeaponBaseSize,
|
||||
},
|
||||
};
|
||||
use crate::interfaces::{FilterFunction, FilterFunctionType};
|
||||
use more_fields::FieldsAsSlice;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::{Arc, LazyLock};
|
||||
|
||||
/// The final equipement list
|
||||
///
|
||||
|
|
@ -70,9 +68,24 @@ impl<T> FilterFunction<T> {
|
|||
/// Generate and save a new filter,
|
||||
/// the use of a static reference allows for reuse of a generic filter
|
||||
pub fn new(filter: &'static FilterFunctionType<T>) -> Self {
|
||||
Self(Box::new(Rc::new(filter)))
|
||||
Self(Arc::new(filter))
|
||||
}
|
||||
}
|
||||
|
||||
/// Filter letting every instance being merged
|
||||
pub(crate) static FILTER_TRUE: LazyLock<FilterFunction<InnerEquipementStats>> =
|
||||
LazyLock::new(|| FilterFunction::<InnerEquipementStats>(Arc::new(|_, _| true)));
|
||||
/// Filter letting the merge happen iff the id is unique (not present in the previous element)
|
||||
/// and the category should allow the merge
|
||||
pub(crate) static FILTER_UNIQUE_AND_RIGHT_CATEGORY: LazyLock<FilterFunction<InnerEquipementStats>> =
|
||||
LazyLock::new(|| {
|
||||
FilterFunction::<InnerEquipementStats>(Arc::new(filter_id_unique_and_right_category()))
|
||||
});
|
||||
/// Filter letting the merge happen iff the id is unique (not present in the previous element)
|
||||
#[allow(dead_code)]
|
||||
pub(crate) static FILTER_UNIQUE: LazyLock<FilterFunction<InnerEquipementStats>> =
|
||||
LazyLock::new(|| FilterFunction::<InnerEquipementStats>(Arc::new(filter_id_unique())));
|
||||
|
||||
/// The inner statistics of the equipement, used across all parts and final weapon
|
||||
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
||||
#[derive(Clone, Default, FieldsAsSlice, Debug)]
|
||||
|
|
@ -273,9 +286,16 @@ impl From<InnerEquipementStats> for EqFinishing {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{
|
||||
EqFinishing, EqMaterial, EqShape, Equipement, InitialEquipementList, InnerEquipementStats,
|
||||
EqFinishing, EqMaterial, EqNature, EqShape, Equipement, FILTER_UNIQUE,
|
||||
InitialEquipementList, InnerEquipementStats,
|
||||
};
|
||||
use crate::{
|
||||
interfaces::RecipeCollection,
|
||||
weaponry_structs::{
|
||||
WeaponBaseShape, equipement_fields::EquipementTargets,
|
||||
equipement_structs::filter_id_unique_and_right_category,
|
||||
},
|
||||
};
|
||||
use crate::interfaces::RecipeCollection;
|
||||
|
||||
fn list_equip() -> Vec<Equipement> {
|
||||
(0..10)
|
||||
|
|
@ -289,6 +309,7 @@ mod test {
|
|||
fn test_struct_creation() {
|
||||
let _stats = InnerEquipementStats::default();
|
||||
let _eq1 = Equipement {
|
||||
filter_function: FILTER_UNIQUE.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
@ -309,9 +330,43 @@ mod test {
|
|||
leq.combine_all(&InitialEquipementList::from_vectored(finishing));
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_default_behaviour() {
|
||||
unimplemented!()
|
||||
fn test_filter() {
|
||||
let mut a = InnerEquipementStats {
|
||||
id: vec![1, 2],
|
||||
target_category: None,
|
||||
category_base: Some(WeaponBaseShape::Staves),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut b = InnerEquipementStats {
|
||||
id: vec![3, 4],
|
||||
target_category: Some(EquipementTargets::Weapons),
|
||||
..Default::default()
|
||||
};
|
||||
assert!(filter_id_unique_and_right_category()(&b, &a));
|
||||
|
||||
a.category_base = Some(WeaponBaseShape::Armors);
|
||||
assert!(!filter_id_unique_and_right_category()(&b, &a));
|
||||
|
||||
a.category_base = None;
|
||||
assert!(!filter_id_unique_and_right_category()(&b, &a));
|
||||
|
||||
b.target_category = None;
|
||||
assert!(!filter_id_unique_and_right_category()(&b, &a));
|
||||
|
||||
a.category_base = Some(WeaponBaseShape::Blunt);
|
||||
assert!(!filter_id_unique_and_right_category()(&b, &a));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion() {
|
||||
let st = InnerEquipementStats::random_new();
|
||||
let (_, _, _, _) = (
|
||||
EqShape::from(st.clone()),
|
||||
EqFinishing::from(st.clone()),
|
||||
EqMaterial::from(st.clone()),
|
||||
EqNature::from(st.clone()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use super::equipement_advanced_repr::RefinedEquipementList;
|
|||
/// A rather full view of an equipement, this multi field allow for a great amount of different operations but incurrs a rather hefty calculation price
|
||||
struct EquipementFullView {}
|
||||
|
||||
#[coverage(off)]
|
||||
impl ViewTable for EquipementFullView {
|
||||
type InterestElementList = RefinedEquipementList;
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue