Assert the bitrate refusals on the shared NumberEdit itself
Browse files at this commit9dc74546f0e16c12d746a8d103e6e18d82ea0050Parent: f1bc4e0- test
- assert the bitrate refusals on the shared NumberEdit itself
3 changed files +15 -18
- crates/app/src/export_ui.rs +0 -11
- crates/app/src/tests/cards.rs +14 -6
- crates/app/src/tests/mod.rs +1 -1
crates/app/src/export_ui.rsmodified+0 -11
| @@ -903,17 +903,6 @@ pub(crate) const MBPS_MAX: u32 = 50; | |||
| 903 | /// than being dropped keystroke by keystroke. | 903 | /// than being dropped keystroke by keystroke. |
| 904 | pub(crate) const MBPS_DIGITS: usize = 3; | 904 | pub(crate) const MBPS_DIGITS: usize = 3; |
| 905 | 905 | ||
| 906 | -/// A typed bitrate as the card takes it, or the reason it is not one. The words | ||
| 907 | -/// are the row's: they are what the field shows in place of its hint. | ||
| 908 | -pub(crate) fn commit_mbps(text: &str) -> Result<u32, String> { | ||
| 909 | - match text.parse::<u32>() { | ||
| 910 | - Ok(mbps) if (MBPS_MIN..=MBPS_MAX).contains(&mbps) => Ok(mbps), | ||
| 911 | - Ok(0) => Err(format!("0 is not a rate — {MBPS_MIN}–{MBPS_MAX} Mbps")), | ||
| 912 | - Ok(mbps) => Err(format!("{mbps} is past the {MBPS_MAX} Mbps ceiling")), | ||
| 913 | - Err(_) => Err(format!("type a number — {MBPS_MIN}–{MBPS_MAX} Mbps")), | ||
| 914 | - } | ||
| 915 | -} | ||
| 916 | - | ||
| 917 | /// A clip's share of the lane. A timeline with no length reads as one full-width | 906 | /// A clip's share of the lane. A timeline with no length reads as one full-width |
| 918 | /// box rather than as NaN, which gpui would carry into layout. | 907 | /// box rather than as NaN, which gpui would carry into layout. |
| 919 | /// Why this timeline cannot be written in `format`, if it cannot. | 908 | /// Why this timeline cannot be written in `format`, if it cannot. |
crates/app/src/tests/cards.rsmodified+14 -6
| @@ -1022,12 +1022,20 @@ fn a_typed_bitrate_is_a_field_and_not_a_key_capture() { | |||
| 1022 | assert_eq!(edit.commit(), Some(5)); | 1022 | assert_eq!(edit.commit(), Some(5)); |
| 1023 | 1023 | ||
| 1024 | // Empty, zero, and past the digit cap: each its own reason, none of | 1024 | // Empty, zero, and past the digit cap: each its own reason, none of |
| 1025 | - // them silent. | 1025 | + // them silent -- asserted on the widget itself, the door the card uses. |
| 1026 | - assert!(commit_mbps("").is_err()); | 1026 | + let mut edit = mbps_edit(0); |
| 1027 | - assert!(commit_mbps("0").unwrap_err().contains("not a rate")); | 1027 | + assert_eq!(edit.commit(), None, "empty is not a number"); |
| 1028 | - assert_eq!(commit_mbps("1"), Ok(MBPS_MIN)); | 1028 | + let mut edit = mbps_edit(0); |
| 1029 | - assert_eq!(commit_mbps("50"), Ok(MBPS_MAX)); | 1029 | + edit.digit(0); |
| 1030 | - assert!(commit_mbps("51").is_err()); | 1030 | + assert_eq!(edit.commit(), None); |
| 1031 | + assert!(edit.refusal.clone().expect("zero says why").contains("0 is not a value")); | ||
| 1032 | + assert_eq!(mbps_edit(MBPS_MIN).commit(), Some(MBPS_MIN)); | ||
| 1033 | + assert_eq!(mbps_edit(MBPS_MAX).commit(), Some(MBPS_MAX)); | ||
| 1034 | + let mut edit = mbps_edit(0); | ||
| 1035 | + for digit in [5, 1] { | ||
| 1036 | + edit.digit(digit); | ||
| 1037 | + } | ||
| 1038 | + assert_eq!(edit.commit(), None, "51 is past the ceiling"); | ||
| 1031 | let mut edit = mbps_edit(0); | 1039 | let mut edit = mbps_edit(0); |
| 1032 | for digit in [9, 9, 9, 9] { | 1040 | for digit in [9, 9, 9, 9] { |
| 1033 | edit.digit(digit); | 1041 | edit.digit(digit); |
crates/app/src/tests/mod.rsmodified+1 -1
| @@ -22,7 +22,7 @@ use super::{ | |||
| 22 | SPEED_PRESETS, SPEED_STEP, STATUS_ERROR, STATUS_SUCCESS, STATUS_WARNING, SUB_PLAN_CHARS, | 22 | SPEED_PRESETS, SPEED_STEP, STATUS_ERROR, STATUS_SUCCESS, STATUS_WARNING, SUB_PLAN_CHARS, |
| 23 | Source, Speed, StreamInfo, TIMELINE_SHARE, Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, | 23 | Source, Speed, StreamInfo, TIMELINE_SHARE, Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, |
| 24 | WAVE_COLS_MAX, Wave, ZOOM_MIN_FRAMES, active_lane, band_label, bitrate_detail, bitrate_refusal, | 24 | WAVE_COLS_MAX, Wave, ZOOM_MIN_FRAMES, active_lane, band_label, bitrate_detail, bitrate_refusal, |
| 25 | - clipboard_after_remove, color_snap, commit_mbps, containers, enable, enable_lane, envelope, | 25 | + clipboard_after_remove, color_snap, containers, enable, enable_lane, envelope, |
| 26 | eq_card_w, eq_freq, eq_freq_label, eq_graph_h, eq_spectrum, eq_x, eq_y, estimated_bytes, | 26 | eq_card_w, eq_freq, eq_freq_label, eq_graph_h, eq_spectrum, eq_x, eq_y, estimated_bytes, |
| 27 | export_path, export_settings, format_line, format_refusal, fps_choices, fps_label, frac_along, | 27 | export_path, export_settings, format_line, format_refusal, fps_choices, fps_label, frac_along, |
| 28 | frac_down, frame_at, frame_rate_ladder, histogram, inserted_band, is_project, keymap, | 28 | frac_down, frame_at, frame_rate_ladder, histogram, inserted_band, is_project, keymap, |