aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Pasquet <dev@etenil.net>2022-02-10 23:13:11 +0000
committerGuillaume Pasquet <dev@etenil.net>2022-02-10 23:13:11 +0000
commit9f4fec0dce1e931356c567fa11d9435f44fbbf50 (patch)
tree918b52c8f579d91ff220002acfc93c9f1e631642
parentd80f0a09fd52670cc32965d86cf1b8617d7b4461 (diff)
Working barbfile parsing
-rw-r--r--README.md2
-rw-r--r--TODO (renamed from TODO.org)0
-rw-r--r--doc/logo-128.pngbin0 -> 15312 bytes
-rw-r--r--doc/logo-64.pngbin0 -> 8380 bytes
-rw-r--r--doc/logo-readme.pngbin0 -> 11322 bytes
-rw-r--r--doc/logo.pngbin9255 -> 27643 bytes
-rw-r--r--src/barbfile.rs30
7 files changed, 22 insertions, 10 deletions
diff --git a/README.md b/README.md
index c46bbd5..f8663f4 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
BARB
====
-![Barb logo](doc/logo.png)
+![Barb logo](doc/logo-readme.png)
Barb is a file-based API query tool written in Rust that works nicely with version control and fits into unix terminal usage.
diff --git a/TODO.org b/TODO
index c307705..c307705 100644
--- a/TODO.org
+++ b/TODO
diff --git a/doc/logo-128.png b/doc/logo-128.png
new file mode 100644
index 0000000..07943bf
--- /dev/null
+++ b/doc/logo-128.png
Binary files differ
diff --git a/doc/logo-64.png b/doc/logo-64.png
new file mode 100644
index 0000000..d5ff9f4
--- /dev/null
+++ b/doc/logo-64.png
Binary files differ
diff --git a/doc/logo-readme.png b/doc/logo-readme.png
new file mode 100644
index 0000000..b8a482b
--- /dev/null
+++ b/doc/logo-readme.png
Binary files differ
diff --git a/doc/logo.png b/doc/logo.png
index bbb343e..dd83daa 100644
--- a/doc/logo.png
+++ b/doc/logo.png
Binary files differ
diff --git a/src/barbfile.rs b/src/barbfile.rs
index f203c84..26ab583 100644
--- a/src/barbfile.rs
+++ b/src/barbfile.rs
@@ -127,9 +127,11 @@ impl FromStr for BarbFile {
let (method, url) = decode_url_line(lines.next().ok_or(BarbParseError {})?)?;
let mut headers: Vec<Header> = vec![];
let mut filter = None;
- for line in lines {
- if !matches!(line.chars().nth(0), Some('#')) {
- break; // Reached the end of the header.
+
+ for line in &mut lines {
+ if line == "" {
+ // End of header.
+ break;
}
if let Some(_) = line.find(':') {
@@ -144,9 +146,11 @@ impl FromStr for BarbFile {
}
}
+ let body = lines.fold(String::from(""), |acc, x| acc + x);
+
Ok(BarbFile {
header: BarbHeader::new(method, url, headers, filter),
- body: None,
+ body: if body == "" {None} else {Some(body)},
})
}
}
@@ -183,22 +187,30 @@ mod tests {
}
#[test]
- fn test_parse_barbfile() {
+ fn test_parse_barbfile_no_body() {
let barbfile =
BarbFile::from_str("#GET^https://blah.com/api/blah\n#Authorization: BLAH\n#|filtr\n")
.unwrap();
- assert_eq!(barbfile.body, None);
assert!(matches!(barbfile.header.method, Method::GET));
assert_eq!(barbfile.header.url, "https://blah.com/api/blah");
assert_eq!(barbfile.header.filter, Some(String::from("filtr")));
- println!("{:?}", barbfile.header.headers);
assert_eq!(barbfile.header.headers.len(), 1);
assert_eq!(barbfile.header.headers[0].name, "Authorization");
assert_eq!(barbfile.header.headers[0].value, "BLAH");
+ assert_eq!(barbfile.body, None);
}
#[test]
- fn test_toto() {
- assert!(true);
+ fn test_parse_barbfile_body() {
+ let barbfile =
+ BarbFile::from_str("#POST^https://blah.com/api/blah\n#Authorization: BLAH\n#|filtr\n\n{\"key\":\"value\"}\n")
+ .unwrap();
+ assert!(matches!(barbfile.header.method, Method::POST));
+ assert_eq!(barbfile.header.url, "https://blah.com/api/blah");
+ assert_eq!(barbfile.header.filter, Some(String::from("filtr")));
+ assert_eq!(barbfile.header.headers.len(), 1);
+ assert_eq!(barbfile.header.headers[0].name, "Authorization");
+ assert_eq!(barbfile.header.headers[0].value, "BLAH");
+ assert_eq!(barbfile.body, Some(String::from("{\"key\":\"value\"}")))
}
}