Add web modules (crypto, wiki, define, urban, tinyurl, down) + shared http/json
All checks were successful
ci / check (push) Successful in 48s
All checks were successful
ci / check (push) Successful in 48s
This commit is contained in:
parent
7846f91afe
commit
c3139b4e4d
14 changed files with 794 additions and 130 deletions
50
tests/tier4.rs
Normal file
50
tests/tier4.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
use rustbot::bot::modules::crypto::format_ticker;
|
||||
use rustbot::bot::modules::define::format_define;
|
||||
use rustbot::bot::modules::down::host_of;
|
||||
use rustbot::bot::modules::urban::format_urban;
|
||||
use rustbot::bot::modules::wiki::{format_summary, pick_title};
|
||||
|
||||
#[test]
|
||||
fn crypto_formats_ticker() {
|
||||
let body = r#"{"last":"63836.11","high":"64658.00","low":"63477.46","volume":"1032.2"}"#;
|
||||
let out = format_ticker("btc", body);
|
||||
assert!(out.contains("BTC/USD: $63836.11"), "{out}");
|
||||
assert!(out.contains("high $64658.00"), "{out}");
|
||||
assert!(out.contains("low $63477.46"), "{out}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wiki_picks_title_and_formats_summary() {
|
||||
let os = r#"["Rust programming",["Rust (programming language)"],[""],["https://en.wikipedia.org/wiki/Rust_(programming_language)"]]"#;
|
||||
assert_eq!(
|
||||
pick_title(os).as_deref(),
|
||||
Some("Rust (programming language)")
|
||||
);
|
||||
let sum = r#"{"title":"Rust (programming language)","extract":"Rust is a language."}"#;
|
||||
assert_eq!(
|
||||
format_summary(sum),
|
||||
"Rust (programming language) — Rust is a language."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn define_formats_first_meaning() {
|
||||
let body = r#"[{"word":"hello","meanings":[{"partOfSpeech":"noun","definitions":[{"definition":"a greeting"}]}]}]"#;
|
||||
assert_eq!(format_define("hello", body), "hello (noun): a greeting");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn urban_formats_and_strips_brackets() {
|
||||
let body = "{\"list\":[{\"word\":\"irc\",\"definition\":\"[Internet] Relay\\r\\nChat\"}]}";
|
||||
let out = format_urban("irc", body);
|
||||
assert!(out.starts_with("irc: Internet Relay"), "{out}");
|
||||
assert!(!out.contains('['), "{out}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn down_parses_host() {
|
||||
assert_eq!(host_of("https://example.com/path?x=1"), "example.com");
|
||||
assert_eq!(host_of("example.com:8080"), "example.com");
|
||||
assert_eq!(host_of("user@host.net"), "host.net");
|
||||
assert_eq!(host_of("//foo.org/"), "foo.org");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue