Friendlier weather output

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Jean Chevronnet 2026-07-29 18:14:51 +00:00
parent f3cb9a6f30
commit b312ff0338
No known key found for this signature in database
GPG key ID: 439666D63A9477E4
2 changed files with 39 additions and 12 deletions

View file

@ -2,7 +2,7 @@ use std::collections::BTreeMap;
use std::path::PathBuf;
use rustbot::bot::module::{Action, Command, Module};
use rustbot::bot::modules::weather::{parse_db, to_json, Weather};
use rustbot::bot::modules::weather::{format_weather, parse_db, to_json, Weather};
fn cmd<'a>(sender: &'a str, name: &'a str, args: &'a [&'a str]) -> Command<'a> {
Command { sender, reply_to: "#chan", name, args, prefix: ">", network: "test" }
@ -65,3 +65,19 @@ fn w_without_saved_location_hints_to_add() {
let r = reply(&w.on_command(&cmd("nobody", "w", &[]))).to_string();
assert!(r.contains("add"), "reply: {r:?}");
}
#[test]
fn format_weather_builds_friendly_line() {
let out = format_weather("73700|☀️ |Sunny|+23°C|+18°C|↘8km/h|45%", "73700");
assert!(out.contains("☀️"), "{out}");
assert!(out.contains("73700: Sunny"), "{out}");
assert!(out.contains("23°C") && !out.contains("+23"), "{out}");
assert!(out.contains("feels like 18°C"), "{out}");
assert!(out.contains("45%"), "{out}");
}
#[test]
fn format_weather_friendly_not_found() {
let out = format_weather("location not found: upstream error", "zzz");
assert!(out.contains("couldn't find 'zzz'"), "{out}");
}