added test for helper function
This commit is contained in:
@@ -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 {
|
fn asciidoctor_slides(in_path: &str, out_path: &str) -> process::Command {
|
||||||
let mut command = process::Command::new(format!("asciidoctor-revealjs-linux"));
|
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
|
command
|
||||||
.arg(format!("{in_path}"))
|
.arg(format!("{in_path}"))
|
||||||
@@ -38,10 +38,26 @@ fn asciidoctor_slides(in_path: &str, out_path: &str) -> process::Command {
|
|||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path_between(from: &str, to: &str) -> &str {
|
fn path_between(from: String, to: String) -> String {
|
||||||
let from_segments = from.split("/");
|
let from_segments: Vec<&str> = from.split("/").collect();
|
||||||
let to_segments = to.split("/");
|
let to_segments: Vec<&str> = to.split("/").collect();
|
||||||
let last_common
|
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;
|
pub struct AsciiDoctorDocsBuilder;
|
||||||
|
|||||||
19
src/test/builder/asciidoctor.rs
Normal file
19
src/test/builder/asciidoctor.rs
Normal 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
1
src/test/builder/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod asciidoctor;
|
||||||
Reference in New Issue
Block a user