Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed May 21, 2024
1 parent 9308680 commit d77f53b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ jobs:
- name: Test CLI
if: matrix.run_tests == true
working-directory: ./toolproof
run: cargo run -- --placeholders toolproof_path="../target/${{ matrix.target }}/release/toolproof"
# toolproof tests itself when run
run: cargo run -- --placeholders toolproof_path="$(pwd)/../target/debug/toolproof"

# TODO: build and package pagebrowse
- name: Create Release Assets
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ jobs:
run: cargo build

- name: Test Lib
working-directory: ./toolproof
run: cargo test

- name: Test CLI
working-directory: ./toolproof
# toolproof tests itself when run
run: cargo run -- --placeholders toolproof_path="$(pwd)/../target/debug/toolproof"
26 changes: 16 additions & 10 deletions toolproof/src/definitions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ mod test {
#[async_trait]
impl ToolproofInstruction for TestInstruction {
fn segments(&self) -> &'static str {
"I am an instruction asking for {argument}"
"__test__ I am an instruction asking for {argument}"
}

async fn run(
Expand All @@ -122,8 +122,9 @@ mod test {
}
}

let users_instruction = parse_segments("I am an instruction asking for \"this argument\"")
.expect("Valid instruction");
let users_instruction =
parse_segments("__test__ I am an instruction asking for \"this argument\"")
.expect("Valid instruction");

let all_instructions = register_instructions();
let matching_instruction = all_instructions
Expand All @@ -132,7 +133,7 @@ mod test {

assert_eq!(
matching_instruction.segments(),
"I am an instruction asking for {argument}"
"__test__ I am an instruction asking for {argument}"
);
}

Expand All @@ -147,7 +148,7 @@ mod test {
#[async_trait]
impl ToolproofRetriever for TestRetriever {
fn segments(&self) -> &'static str {
"the file {filename}"
"__test__ the file {filename}"
}

async fn run(
Expand All @@ -159,14 +160,18 @@ mod test {
}
}

let users_segments = parse_segments("the file \"index.html\"").expect("Valid instruction");
let users_segments =
parse_segments("__test__ the file \"index.html\"").expect("Valid instruction");

let all_segments = register_retrievers();
let matching_retriever = all_segments
.get(&users_segments)
.expect("should be able to retrieve segments");

assert_eq!(matching_retriever.segments(), "the file {filename}");
assert_eq!(
matching_retriever.segments(),
"__test__ the file {filename}"
);
}

#[test]
Expand All @@ -180,7 +185,7 @@ mod test {
#[async_trait]
impl ToolproofAssertion for TestAssertion {
fn segments(&self) -> &'static str {
"be exactly {value}"
"__test__ be exactly {value}"
}

async fn run(
Expand All @@ -193,13 +198,14 @@ mod test {
}
}

let users_segments = parse_segments("be exactly {my_json}").expect("Valid instruction");
let users_segments =
parse_segments("__test__ be exactly {my_json}").expect("Valid instruction");

let all_segments = register_assertions();
let matching_assertion = all_segments
.get(&users_segments)
.expect("should be able to retrieve segments");

assert_eq!(matching_assertion.segments(), "be exactly {value}");
assert_eq!(matching_assertion.segments(), "__test__ be exactly {value}");
}
}
14 changes: 7 additions & 7 deletions toolproof/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub fn parse_segments(s: &str) -> Result<ToolproofSegments, ToolproofInputError>
match mode {
InstMode::None(start) => {
if start < s.len() {
segments.push(Literal(s[start..].to_string()));
segments.push(Literal(s[start..].to_lowercase()));
}
}
InstMode::InQuote(_, q) => return Err(ToolproofInputError::UnclosedValue { expected: q }),
Expand All @@ -226,14 +226,14 @@ mod test {
// look inside Value or Variable segments.
assert_eq!(
segments.segments,
vec![Literal("I run my program".to_string())]
vec![Literal("i run my program".to_string())]
);

let segments = parse_segments("I have a \"public/cat/'index'.html\" file with the body '<h1>Happy post about \"cats</h1>'").expect("Valid segments");
assert_eq!(
segments.segments,
vec![
Literal("I have a ".to_string()),
Literal("i have a ".to_string()),
Value(st("public/cat/'index'.html")),
Literal(" file with the body ".to_string()),
Value(st("<h1>Happy post about \"cats</h1>"))
Expand All @@ -245,9 +245,9 @@ mod test {
assert_eq!(
segments.segments,
vec![
Literal("In my browser, ".to_string()),
Literal("in my browser, ".to_string()),
Value(st("")),
Literal("I eval ".to_string()),
Literal("i eval ".to_string()),
Variable("j\"s".to_string()),
Literal(" and ".to_string()),
Value(st("x")),
Expand All @@ -266,7 +266,7 @@ mod test {
ToolproofTestStep::Instruction {
step: ToolproofSegments {
segments: vec![
Literal("I have a ".to_string()),
Literal("i have a ".to_string()),
Variable("js".to_string()),
Literal(" file".to_string())
]
Expand All @@ -289,7 +289,7 @@ mod test {
ToolproofTestStep::Assertion {
retrieval: ToolproofSegments {
segments: vec![
Literal("The file ".to_string()),
Literal("the file ".to_string()),
Variable("name".to_string())
]
},
Expand Down

0 comments on commit d77f53b

Please sign in to comment.