| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
pub mod chrome; |
| 135 |
pub mod containment; |
| 136 |
pub mod error; |
| 137 |
pub mod frame; |
| 138 |
mod path; |
| 139 |
pub mod renderer; |
| 140 |
pub mod request; |
| 141 |
pub mod response; |
| 142 |
pub mod router; |
| 143 |
pub mod screen; |
| 144 |
pub mod stage; |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
pub use makeover_layout as layout; |
| 153 |
|
| 154 |
pub use crate::chrome::{Band, Binding, Brand, Chrome, Disclose, Panel, Place, Role}; |
| 155 |
pub use crate::containment::{Containment, Element, Level, Of}; |
| 156 |
pub use crate::error::{Class, RouteError}; |
| 157 |
pub use crate::frame::Frame; |
| 158 |
pub use crate::renderer::Renderer; |
| 159 |
pub use crate::request::{Method, Params, Request}; |
| 160 |
pub use crate::response::{ |
| 161 |
Address, Anchor, Invalidated, Locating, Message, Outcome, Picked, Response, Sought, |
| 162 |
safe_file_name, |
| 163 |
}; |
| 164 |
pub use crate::router::{Handler, Router}; |
| 165 |
pub use crate::screen::{ |
| 166 |
Accepted, Act, Action, Adds, Answer, Bar, CUTOFFS, Candidate, Canvas, Cell, CellKey, Chart, |
| 167 |
Choice, Choosing, Clock, Column, Consult, Curve, Destination, Discovery, Document, Feed, |
| 168 |
FeedKind, Field, Figure, Held, Image, Instance, Jump, Meter, Node, Outline, Placed, Prefill, |
| 169 |
Progress, Prose, Question, Ranked, RegionKind, Repeat, Repeating, Replaces, Rest, Reveal, |
| 170 |
Richness, Row, Run, Screen, Slot, SocialKind, Table, Tag, ThemeChoice, Trust, folded, |
| 171 |
folded_by, writable_root_attr, |
| 172 |
}; |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
pub use crate::screen::{Body, Picks}; |
| 178 |
|
| 179 |
#[cfg(test)] |
| 180 |
mod tests { |
| 181 |
use super::*; |
| 182 |
use crate::layout::{Arrangement, Tone}; |
| 183 |
|
| 184 |
|
| 185 |
struct State { |
| 186 |
greeting: &'static str, |
| 187 |
} |
| 188 |
|
| 189 |
fn home(state: &State, _request: Request) -> Result<Response, RouteError> { |
| 190 |
Ok(Screen::sidebar_content("Home") |
| 191 |
.with(Slot::new("content", RegionKind::Pane).with(Node::text(state.greeting))) |
| 192 |
.into()) |
| 193 |
} |
| 194 |
|
| 195 |
fn new_task(_state: &State, _request: Request) -> Result<Response, RouteError> { |
| 196 |
Ok(Response::fragment("detail", Node::text("a new task"))) |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
#[allow(clippy::needless_pass_by_value)] |
| 202 |
fn show_task(_state: &State, request: Request) -> Result<Response, RouteError> { |
| 203 |
let id = request.captures.require("id")?.to_owned(); |
| 204 |
Ok(Response::fragment("detail", Node::text(id))) |
| 205 |
} |
| 206 |
|
| 207 |
fn forbidden(_state: &State, _request: Request) -> Result<Response, RouteError> { |
| 208 |
Err(RouteError::denied("not yours")) |
| 209 |
} |
| 210 |
|
| 211 |
fn router() -> Router<State> { |
| 212 |
|
| 213 |
|
| 214 |
Router::new() |
| 215 |
.get("/task/{id}", show_task) |
| 216 |
.get("/task/new", new_task) |
| 217 |
.get("/", home) |
| 218 |
.post("/task/{id}/delete", forbidden) |
| 219 |
} |
| 220 |
|
| 221 |
fn state() -> State { |
| 222 |
State { greeting: "hello" } |
| 223 |
} |
| 224 |
|
| 225 |
fn text_of(response: &Response) -> Option<&str> { |
| 226 |
match &response.outcome { |
| 227 |
Outcome::Fragment { |
| 228 |
node: Node::Text { text, .. }, |
| 229 |
.. |
| 230 |
} => Some(text), |
| 231 |
_ => None, |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
#[test] |
| 236 |
fn a_static_route_beats_a_capture_whatever_the_order() { |
| 237 |
let answer = router() |
| 238 |
.handle(&state(), Request::get("/task/new")) |
| 239 |
.unwrap(); |
| 240 |
assert_eq!(text_of(&answer), Some("a new task")); |
| 241 |
} |
| 242 |
|
| 243 |
#[test] |
| 244 |
fn a_capture_reaches_the_handler() { |
| 245 |
let answer = router().handle(&state(), Request::get("/task/7")).unwrap(); |
| 246 |
assert_eq!(text_of(&answer), Some("7")); |
| 247 |
} |
| 248 |
|
| 249 |
#[test] |
| 250 |
fn the_path_capture_wins_over_a_supplied_value() { |
| 251 |
|
| 252 |
let sent = Params::new().with("id", "9"); |
| 253 |
let answer = router() |
| 254 |
.handle(&state(), Request::get("/task/7").carrying(sent)) |
| 255 |
.unwrap(); |
| 256 |
assert_eq!(text_of(&answer), Some("7")); |
| 257 |
} |
| 258 |
|
| 259 |
#[test] |
| 260 |
fn a_read_and_a_write_are_different_routes_at_one_address() { |
| 261 |
let router = router(); |
| 262 |
let missing = router |
| 263 |
.handle(&state(), Request::post("/task/7")) |
| 264 |
.unwrap_err(); |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
assert_eq!(missing.class, Class::Unsupported); |
| 269 |
assert_eq!(missing.class.http_status(), 405); |
| 270 |
assert!(missing.message.contains("another method")); |
| 271 |
} |
| 272 |
|
| 273 |
#[test] |
| 274 |
fn a_verb_that_misses_names_the_verbs_that_would_not_have() { |
| 275 |
let refused = Router::<State>::new() |
| 276 |
.get("/pricing", home) |
| 277 |
.post("/pricing", home) |
| 278 |
.handle( |
| 279 |
&state(), |
| 280 |
Request { |
| 281 |
method: Method::Delete, |
| 282 |
..Request::get("/pricing") |
| 283 |
}, |
| 284 |
) |
| 285 |
.unwrap_err(); |
| 286 |
|
| 287 |
assert_eq!(refused.class, Class::Unsupported); |
| 288 |
assert_eq!(refused.allow, vec![Method::Get, Method::Post]); |
| 289 |
|
| 290 |
|
| 291 |
assert_eq!(refused.allow_header().as_deref(), Some("GET, POST")); |
| 292 |
} |
| 293 |
|
| 294 |
#[test] |
| 295 |
fn the_allow_list_does_not_depend_on_the_order_routes_were_registered() { |
| 296 |
let late = Router::<State>::new() |
| 297 |
.post("/pricing", home) |
| 298 |
.get("/pricing", home) |
| 299 |
.handle( |
| 300 |
&state(), |
| 301 |
Request { |
| 302 |
method: Method::Delete, |
| 303 |
..Request::get("/pricing") |
| 304 |
}, |
| 305 |
) |
| 306 |
.unwrap_err(); |
| 307 |
assert_eq!(late.allow_header().as_deref(), Some("GET, POST")); |
| 308 |
} |
| 309 |
|
| 310 |
#[test] |
| 311 |
fn an_address_that_is_simply_absent_claims_no_verbs() { |
| 312 |
let missing = router() |
| 313 |
.handle(&state(), Request::get("/nowhere")) |
| 314 |
.unwrap_err(); |
| 315 |
|
| 316 |
|
| 317 |
assert!(missing.allow.is_empty()); |
| 318 |
assert!(missing.allow_header().is_none()); |
| 319 |
} |
| 320 |
|
| 321 |
#[test] |
| 322 |
fn the_verbs_at_an_address_can_be_asked_for_directly() { |
| 323 |
assert_eq!(router().verbs_at("/task/new"), vec![Method::Get]); |
| 324 |
assert_eq!(router().verbs_at("/task/7/delete"), vec![Method::Post]); |
| 325 |
assert!(router().verbs_at("/nowhere").is_empty()); |
| 326 |
} |
| 327 |
|
| 328 |
#[test] |
| 329 |
fn an_unknown_path_says_so_without_mentioning_a_method() { |
| 330 |
let missing = router() |
| 331 |
.handle(&state(), Request::get("/nowhere")) |
| 332 |
.unwrap_err(); |
| 333 |
assert_eq!(missing.class, Class::NotFound); |
| 334 |
assert!(!missing.message.contains("another method")); |
| 335 |
} |
| 336 |
|
| 337 |
#[test] |
| 338 |
fn a_denial_carries_a_banner_and_a_status() { |
| 339 |
let denied = router() |
| 340 |
.handle(&state(), Request::post("/task/7/delete")) |
| 341 |
.unwrap_err(); |
| 342 |
assert_eq!(denied.class, Class::Denied); |
| 343 |
assert_eq!(denied.class.http_status(), 403); |
| 344 |
assert_eq!(denied.notice, layout::Notice::Banner); |
| 345 |
assert_eq!(denied.tone(), Tone::Warning); |
| 346 |
assert!(!denied.class.is_ours()); |
| 347 |
} |
| 348 |
|
| 349 |
#[test] |
| 350 |
fn a_missing_parameter_is_our_bug_not_the_users() { |
| 351 |
|
| 352 |
|
| 353 |
let missing = show_task(&state(), Request::get("/task/7")).unwrap_err(); |
| 354 |
assert_eq!(missing.class, Class::Internal); |
| 355 |
assert!(missing.class.is_ours()); |
| 356 |
} |
| 357 |
|
| 358 |
#[test] |
| 359 |
fn a_screen_answers_with_no_target_and_a_fragment_with_one() { |
| 360 |
let router = router(); |
| 361 |
let screen = router.handle(&state(), Request::get("/")).unwrap(); |
| 362 |
assert_eq!(screen.target(), None); |
| 363 |
|
| 364 |
let fragment = router.handle(&state(), Request::get("/task/7")).unwrap(); |
| 365 |
assert_eq!(fragment.target(), Some("detail")); |
| 366 |
} |
| 367 |
|
| 368 |
#[test] |
| 369 |
fn the_route_table_reads_back_most_specific_first() { |
| 370 |
let router = router(); |
| 371 |
let table: Vec<_> = router.routes().collect(); |
| 372 |
let new_at = table.iter().position(|(_, p)| *p == "/task/new").unwrap(); |
| 373 |
let id_at = table.iter().position(|(_, p)| *p == "/task/{id}").unwrap(); |
| 374 |
assert!(new_at < id_at); |
| 375 |
assert_eq!(router.len(), 4); |
| 376 |
} |
| 377 |
|
| 378 |
#[test] |
| 379 |
#[should_panic(expected = "registered twice")] |
| 380 |
fn registering_one_route_twice_is_a_bug() { |
| 381 |
let _ = Router::<State>::new() |
| 382 |
.get("/task/{id}", show_task) |
| 383 |
.get("/task/{id}", show_task); |
| 384 |
} |
| 385 |
|
| 386 |
#[test] |
| 387 |
fn a_slot_is_found_at_any_depth() { |
| 388 |
let screen = Screen::new("Tabs", Arrangement::list_detail(true)).with( |
| 389 |
Slot::new("tabs", RegionKind::TabGroup) |
| 390 |
.with(Node::Region(Slot::new("pane-a", RegionKind::Pane))), |
| 391 |
); |
| 392 |
assert!(screen.slot("tabs").is_some()); |
| 393 |
assert!(screen.slot("pane-a").is_some()); |
| 394 |
assert!(screen.slot("pane-b").is_none()); |
| 395 |
} |
| 396 |
|
| 397 |
#[test] |
| 398 |
fn a_fragment_replaces_a_top_level_regions_contents() { |
| 399 |
let mut screen = Screen::sidebar_content("Home").with( |
| 400 |
Slot::new("content", RegionKind::Pane) |
| 401 |
.with(Node::text("first")) |
| 402 |
.with(Node::text("second")), |
| 403 |
); |
| 404 |
|
| 405 |
assert!(screen.replace("content", Node::text("after"))); |
| 406 |
|
| 407 |
let slot = screen.slot("content").expect("the region is still there"); |
| 408 |
|
| 409 |
|
| 410 |
assert_eq!(slot.body, Body::All(vec![Ranked::new(Node::text("after"))])); |
| 411 |
} |
| 412 |
|
| 413 |
#[test] |
| 414 |
fn a_fragment_reaches_a_region_nested_inside_another() { |
| 415 |
let mut screen = Screen::new("Tabs", Arrangement::list_detail(true)).with( |
| 416 |
Slot::new("tabs", RegionKind::TabGroup) |
| 417 |
.with(Node::Region(Slot::new("pane-a", RegionKind::Pane))), |
| 418 |
); |
| 419 |
|
| 420 |
assert!(screen.replace("pane-a", Node::text("loaded"))); |
| 421 |
|
| 422 |
let pane = screen.slot("pane-a").expect("the nested region"); |
| 423 |
assert_eq!( |
| 424 |
pane.body, |
| 425 |
Body::All(vec![Ranked::new(Node::text("loaded"))]) |
| 426 |
); |
| 427 |
|
| 428 |
|
| 429 |
let tabs = screen.slot("tabs").expect("the outer region"); |
| 430 |
assert_eq!(tabs.body.len(), 1); |
| 431 |
} |
| 432 |
|
| 433 |
#[test] |
| 434 |
fn a_pending_region_stops_being_pending_when_its_content_arrives() { |
| 435 |
let mut screen = |
| 436 |
Screen::sidebar_content("Home").with(Slot::new("content", RegionKind::Pane).pending()); |
| 437 |
|
| 438 |
assert!(screen.replace("content", Node::text("here"))); |
| 439 |
|
| 440 |
let slot = screen.slot("content").expect("the region"); |
| 441 |
assert_eq!(slot.readiness, layout::Readiness::Ready); |
| 442 |
} |
| 443 |
|
| 444 |
#[test] |
| 445 |
fn a_fragment_for_a_region_that_is_not_there_answers_false() { |
| 446 |
let mut screen = |
| 447 |
Screen::sidebar_content("Home").with(Slot::new("content", RegionKind::Pane)); |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
assert!(!screen.replace("detail", Node::text("nowhere"))); |
| 453 |
assert!(screen.slot("content").expect("untouched").body.is_empty()); |
| 454 |
} |
| 455 |
|
| 456 |
#[test] |
| 457 |
fn an_owned_field_borrows_back_as_the_description_layers_own() { |
| 458 |
let field = Field::select( |
| 459 |
"priority", |
| 460 |
"Priority", |
| 461 |
vec![Choice::plain("high"), Choice::new("low", "Low")], |
| 462 |
) |
| 463 |
.required() |
| 464 |
.error("pick one"); |
| 465 |
|
| 466 |
field.with_layout(|borrowed| { |
| 467 |
assert_eq!(borrowed.name, "priority"); |
| 468 |
assert_eq!(borrowed.options.len(), 2); |
| 469 |
assert_eq!(borrowed.options[1].label, "Low"); |
| 470 |
assert!(borrowed.required); |
| 471 |
|
| 472 |
assert!(borrowed.invalid()); |
| 473 |
assert!(borrowed.kind.offers_options()); |
| 474 |
}); |
| 475 |
} |
| 476 |
|
| 477 |
#[test] |
| 478 |
fn the_opaque_regions_are_the_undescribed_ones() { |
| 479 |
assert!(RegionKind::Pane.described()); |
| 480 |
assert!( |
| 481 |
!RegionKind::Handover { |
| 482 |
name: "day-plan".into() |
| 483 |
} |
| 484 |
.described() |
| 485 |
); |
| 486 |
} |
| 487 |
|
| 488 |
#[test] |
| 489 |
fn a_group_contains_a_section_and_claims_nothing_else() { |
| 490 |
use crate::containment::{Containment, Element}; |
| 491 |
|
| 492 |
let group = Slot::group("appearance") |
| 493 |
.with(Node::section("Appearance")) |
| 494 |
.with(Node::text("Theme")); |
| 495 |
|
| 496 |
assert_eq!(group.kind, RegionKind::Group); |
| 497 |
assert!(group.kind.described()); |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
assert_eq!(group.kind.depth(), layout::Depth::Flat); |
| 502 |
assert_eq!(RegionKind::Pane.depth(), layout::Depth::Well); |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
assert_eq!(group.containment(), Containment::Blocks); |
| 507 |
assert_eq!(group.body.len(), 2); |
| 508 |
} |
| 509 |
|
| 510 |
#[test] |
| 511 |
fn a_screen_nobody_described_is_indexable() { |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
assert!(Discovery::default().indexable); |
| 516 |
assert!(Screen::sidebar_content("Home").discovery.indexable); |
| 517 |
assert!( |
| 518 |
!Screen::sidebar_content("Home") |
| 519 |
.indexed(false) |
| 520 |
.discovery |
| 521 |
.indexable |
| 522 |
); |
| 523 |
} |
| 524 |
|
| 525 |
#[test] |
| 526 |
fn every_social_kind_has_a_distinct_spelling() { |
| 527 |
|
| 528 |
|
| 529 |
let kinds = [ |
| 530 |
SocialKind::Website, |
| 531 |
SocialKind::Article, |
| 532 |
SocialKind::Profile, |
| 533 |
SocialKind::Product, |
| 534 |
SocialKind::Video, |
| 535 |
SocialKind::Song, |
| 536 |
]; |
| 537 |
let mut seen = Vec::new(); |
| 538 |
for kind in kinds { |
| 539 |
let spelling = kind.as_str(); |
| 540 |
assert!(!spelling.is_empty(), "{kind:?} spells nothing"); |
| 541 |
assert!(!seen.contains(&spelling), "{spelling} is spelled twice"); |
| 542 |
seen.push(spelling); |
| 543 |
} |
| 544 |
assert_eq!(SocialKind::default(), SocialKind::Website); |
| 545 |
} |
| 546 |
|
| 547 |
#[test] |
| 548 |
fn every_feed_kind_has_a_distinct_media_type() { |
| 549 |
|
| 550 |
|
| 551 |
let kinds = [FeedKind::Rss, FeedKind::Atom, FeedKind::JsonFeed]; |
| 552 |
let mut seen = Vec::new(); |
| 553 |
for kind in kinds { |
| 554 |
let spelling = kind.media_type(); |
| 555 |
assert!(!spelling.is_empty(), "{kind:?} spells nothing"); |
| 556 |
assert!(!seen.contains(&spelling), "{spelling} is spelled twice"); |
| 557 |
seen.push(spelling); |
| 558 |
} |
| 559 |
assert_eq!(FeedKind::default(), FeedKind::Rss); |
| 560 |
} |
| 561 |
|
| 562 |
#[test] |
| 563 |
fn a_screen_says_its_feed_once_and_nobody_says_it_is_offering_one() { |
| 564 |
|
| 565 |
assert!(Discovery::default().feed.is_none()); |
| 566 |
let screen = Screen::single("Blog").syndicating(Feed::new( |
| 567 |
FeedKind::Rss, |
| 568 |
"Project updates", |
| 569 |
"/p/thing/feed.xml", |
| 570 |
)); |
| 571 |
let feed = screen.discovery.feed.as_ref().expect("said"); |
| 572 |
assert_eq!(feed.kind.media_type(), "application/rss+xml"); |
| 573 |
assert_eq!(feed.title, "Project updates"); |
| 574 |
assert_eq!(feed.href, "/p/thing/feed.xml"); |
| 575 |
} |
| 576 |
|
| 577 |
#[test] |
| 578 |
fn a_screen_says_where_the_caret_starts_and_most_screens_say_nothing() { |
| 579 |
|
| 580 |
|
| 581 |
assert!(Screen::single("Home").opens_at.is_none()); |
| 582 |
let login = Screen::single("Log in").opening_at("email"); |
| 583 |
assert_eq!(login.opens_at.as_deref(), Some("email")); |
| 584 |
} |
| 585 |
|
| 586 |
#[test] |
| 587 |
fn an_overlay_targets_no_region_and_sends_the_user_nowhere() { |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
let answer = Response::over(Screen::sidebar_content("Palette")); |
| 592 |
assert!(answer.target().is_none()); |
| 593 |
assert!(answer.destination().is_none()); |
| 594 |
assert!(matches!(answer.outcome, Outcome::Over(_))); |
| 595 |
} |
| 596 |
|
| 597 |
#[test] |
| 598 |
fn chrome_is_held_beside_the_router_rather_than_arriving_with_an_answer() { |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
let chrome = Chrome::new().bind("ctrl+k", "Search", Action::get("/palette")); |
| 603 |
assert_eq!( |
| 604 |
chrome.bound("ctrl+k").map(|b| b.label.as_str()), |
| 605 |
Some("Search") |
| 606 |
); |
| 607 |
assert_eq!( |
| 608 |
chrome.bound("ctrl+k").map(|b| &b.action), |
| 609 |
Some(&Action::get("/palette")) |
| 610 |
); |
| 611 |
} |
| 612 |
|
| 613 |
#[test] |
| 614 |
fn a_field_asks_for_room_the_way_a_column_does() { |
| 615 |
use crate::layout::Width; |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
let quiet = Field::new(layout::FieldKind::Text, "query", "Search"); |
| 626 |
assert_eq!(quiet.width, Width::Fill); |
| 627 |
assert_eq!(quiet.width, Column::new("Name").width); |
| 628 |
|
| 629 |
let sized = quiet.width(Width::Content); |
| 630 |
assert_eq!(sized.width, Width::Content); |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
#[test] |
| 636 |
fn a_repeating_question_reads_back_as_a_list() { |
| 637 |
let params = Params::new() |
| 638 |
.with("title", "Standup") |
| 639 |
.with("reminder[1]", "900") |
| 640 |
.with("reminder[0]", "300") |
| 641 |
.with("reminder[2]", "3600"); |
| 642 |
|
| 643 |
|
| 644 |
assert_eq!(params.repeated("reminder"), ["300", "900", "3600"]); |
| 645 |
|
| 646 |
assert_eq!(params.get("title"), Some("Standup")); |
| 647 |
assert!(params.repeated("title").is_empty()); |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
let holed = Params::new() |
| 652 |
.with("reminder[0]", "300") |
| 653 |
.with("reminder[2]", "3600"); |
| 654 |
assert_eq!(holed.repeated("reminder"), ["300", "3600"]); |
| 655 |
|
| 656 |
|
| 657 |
assert!(Params::new().repeated("reminder").is_empty()); |
| 658 |
|
| 659 |
|
| 660 |
let near = Params::new().with("reminders", "300"); |
| 661 |
assert!(near.repeated("reminder").is_empty()); |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
#[test] |
| 666 |
fn a_grouped_slot_reads_back_one_part_at_a_time() { |
| 667 |
let params = Params::new() |
| 668 |
.with("note", "two files") |
| 669 |
.with("file[1].name", "b.wav") |
| 670 |
.with("file[1].size", "8") |
| 671 |
.with("file[0].name", "a.wav") |
| 672 |
.with("file[0].size", "4"); |
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
assert_eq!(params.repeated_part("file", "name"), ["a.wav", "b.wav"]); |
| 677 |
assert_eq!(params.repeated_part("file", "size"), ["4", "8"]); |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
assert!(params.repeated("file").is_empty()); |
| 682 |
assert!(params.repeated_part("file", "missing").is_empty()); |
| 683 |
assert_eq!(params.get("note"), Some("two files")); |
| 684 |
|
| 685 |
|
| 686 |
let holed = Params::new() |
| 687 |
.with("file[0].name", "a.wav") |
| 688 |
.with("file[2].name", "c.wav"); |
| 689 |
assert_eq!(holed.repeated_part("file", "name"), ["a.wav", "c.wav"]); |
| 690 |
} |
| 691 |
} |
| 692 |
|