added test for helper function

This commit is contained in:
2023-01-28 14:10:37 +01:00
parent 4c7c7c574d
commit a9eb073b55
3 changed files with 41 additions and 5 deletions

View File

@@ -29,7 +29,7 @@ fn asciidoctor_docs(in_path: &str, out_path: &str) -> process::Command {
fn asciidoctor_slides(in_path: &str, out_path: &str) -> process::Command {
let mut command = process::Command::new(format!("asciidoctor-revealjs-linux"));
let revealjs_path = path_between(out_path, "./dist/slides/revealjs");
let revealjs_path = path_between(out_path.to_string(), "./dist/slides/revealjs".to_string());
command
.arg(format!("{in_path}"))
@@ -38,10 +38,26 @@ fn asciidoctor_slides(in_path: &str, out_path: &str) -> process::Command {
return command;
}
fn path_between(from: &str, to: &str) -> &str {
let from_segments = from.split("/");
let to_segments = to.split("/");
let last_common
fn path_between(from: String, to: String) -> String {
let from_segments: Vec<&str> = from.split("/").collect();
let to_segments: Vec<&str> = to.split("/").collect();
let last_matching_index = last_matching_index(&from_segments, &to_segments);
let number_of_backs = from_segments.len() - last_matching_index;
return "".to_string();
}
pub fn last_matching_index(from_segments: &Vec<&str>, to_segments: &Vec<&str>) -> usize {
for (index, from_segment) in from_segments.iter().enumerate() {
if let Some(to_segment) = to_segments.get(index){
if from_segment != to_segment {
return index - 1;
}
} else {
return index - 1;
}
}
return from_segments.len();
}
pub struct AsciiDoctorDocsBuilder;

View File

@@ -0,0 +1,19 @@
use crate::app::builder::asciidoctor;
#[test]
fn last_matching_index_0() {
let vec1 = vec!["dings", "dings", "dingens"];
let vec2 = vec!["dings", "dings", "dings"];
let last_maching = asciidoctor::last_matching_index(&vec1, &vec2);
assert_eq!(last_maching, 1);
}
#[test]
fn last_matching_index_1() {
let vec1 = vec!["dings", "dings", "dingens", "dings", "dingens"];
let vec2 = vec!["dings", "dings", "dingens", "dings"];
let last_maching = asciidoctor::last_matching_index(&vec1, &vec2);
assert_eq!(last_maching, 3);
}

1
src/test/builder/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod asciidoctor;