Skip to content

Commit

Permalink
test(parser): only check for comments in ParserMode::Request (#172)
Browse files Browse the repository at this point in the history
* test(parser): only check for comments in ParserMode::Request

* test: merge comment tests
  • Loading branch information
hougesen authored Feb 12, 2024
1 parent 2cf9ecd commit c00e6f0
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions hitt-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,42 @@ DELETE https://mhouge.dk/";
assert!(matches!(uri_token, RequestToken::Uri(uri) if uri == expected_uri));
}

#[test]
fn it_should_only_check_for_comments_when_parsermode_request() {
let url = "https://mhouge.dk/api/something/?refresh=true";
let method = "DELETE";

let status_line = format!("{method} {url}");

for comment_style in ["#", "//"] {
let body = format!("{comment_style} this is not a comment");

let hashtag = format!(
"{status_line}
{body}"
);

let tokens = tokenize(&hashtag, &EMPTY_VARS).expect("it to parse successfully");

assert_eq!(tokens.len(), 3);

let method_token = tokens.first().expect("it to be some");

assert!(
matches!(method_token, RequestToken::Method(m) if m == http::method::Method::DELETE)
);

let uri_token = tokens.get(1).expect("it to be Some");

assert!(matches!(uri_token, RequestToken::Uri(u) if u == url));

let body_token = tokens.get(2).expect("it to be Some");

assert!(matches!(body_token, RequestToken::Body(b) if b == &Some(body)));
}
}

#[test]
fn it_should_support_variables() {
{
Expand Down

0 comments on commit c00e6f0

Please sign in to comment.