Skip to content

Commit

Permalink
Tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
WINSDK committed Apr 25, 2024
1 parent f1ed0f0 commit 2f8e9ef
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 115 deletions.
96 changes: 52 additions & 44 deletions debugvault/src/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,47 +73,55 @@ impl Match {
}
}

// #[cfg(test)]
// mod test {
// use super::*;
//
// #[test]
// fn insert() {
// let mut tree = PrefixMatch::default();
// tree.insert("file", 0);
// tree.insert("file_name", 1);
// tree.insert("file::name", 2);
// tree.insert("file::no", 3);
// tree.reorder();
// let expected = [
// ("file", 0),
// ("file::name", 2),
// ("file::no", 3),
// ("file_name", 1),
// ];
// assert_eq!(tree.items.len(), expected.len(), "Mismatched length");
// for (x, y) in tree.items.iter().zip(expected.iter()) {
// assert_eq!(x.0, y.0, "Mismatched strings");
// assert_eq!(x.1, y.1, "Mismatched metadata");
// }
// }
//
// #[test]
// fn find() {
// let mut tree = PrefixMatch::default();
// tree.insert("file", 0);
// tree.insert("file_name", 1);
// tree.insert("file::name", 2);
// tree.insert("file::no", 3);
// tree.reorder();
// let expected = [
// ("file::name", 2),
// ("file::no", 3),
// ];
// assert_eq!(tree.find("file::").range.len(), expected.len(), "Mismatched length");
// for (x, y) in tree.find("file::").iter(&tree).zip(expected.iter()) {
// assert_eq!(x.0, y.0, "Mismatched strings");
// assert_eq!(*x.1, y.1, "Mismatched metadata");
// }
// }
// }
#[cfg(test)]
mod test {
use crate::demangler::TokenStream;
use super::*;

fn symbol(s: &str) -> Arc<Symbol> {
Arc::new(Symbol {
name_as_str: Arc::from(s),
name: TokenStream::simple(s),
module: None,
is_intrinsics: false
})
}

#[test]
fn insert() {
let mut tree = PrefixMatcher::default();
tree.insert(&symbol("file"));
tree.insert(&symbol("file_name"));
tree.insert(&symbol("file::name"));
tree.insert(&symbol("file::no"));
tree.reorder();
let expected = [
"file",
"file::name",
"file::no",
"file_name",
];
assert_eq!(tree.items.len(), expected.len(), "Mismatched length");
for (x, y) in tree.items.iter().zip(expected.iter()) {
assert_eq!(&x.as_str(), y, "Mismatch");
}
}

#[test]
fn find() {
let mut tree = PrefixMatcher::default();
tree.insert(&symbol("file"));
tree.insert(&symbol("file_name"));
tree.insert(&symbol("file::name"));
tree.insert(&symbol("file::no"));
tree.reorder();
let expected = [
"file::name",
"file::no",
];
assert_eq!(tree.find("file::").range.len(), expected.len(), "Mismatched length");
for (x, y) in tree.find("file::").iter(&tree).zip(expected.iter()) {
assert_eq!(&x.as_str(), y, "Mismatch");
}
}
}
40 changes: 0 additions & 40 deletions gui/src/widgets/text_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,6 @@ pub struct TextEditOutput {
/// The text edit state stored between frames.
///
/// Attention: You also need to `store` the updated state.
/// ```
/// # use egui::text::CCursor;
/// # use egui::text_edit::{CCursorRange, TextEditOutput};
/// # use egui::TextEdit;
/// # egui::__run_test_ui(|ui| {
/// # let mut text = String::new();
/// let mut output = TextEdit::singleline(&mut text).show(ui);
///
/// // Create a new selection range
/// let min = CCursor::new(0);
/// let max = CCursor::new(0);
/// let new_range = CCursorRange::two(min, max);
///
/// // Update the state
/// output.state.set_ccursor_range(Some(new_range));
/// // Store the updated state
/// output.state.store(ui.ctx(), output.response.id);
/// # });
/// ```
#[derive(Clone, Default)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
Expand Down Expand Up @@ -273,27 +254,6 @@ impl<'t> TextEdit<'t> {
}

/// Show a faint hint text when the text field is empty.
///
/// If the hint text needs to be persisted even when the text field has input,
/// the following workaround can be used:
/// ```
/// # egui::__run_test_ui(|ui| {
/// # let mut my_string = String::new();
/// # use egui::{ Color32, FontId };
/// let text_edit = egui::TextEdit::multiline(&mut my_string)
/// .desired_width(f32::INFINITY);
/// let output = text_edit.show(ui);
/// let painter = ui.painter_at(output.response.rect);
/// let text_color = Color32::from_rgba_premultiplied(100, 100, 100, 100);
/// let galley = painter.layout(
/// String::from("Enter text"),
/// FontId::default(),
/// Color32::from_rgba_premultiplied(100, 100, 100, 100),
/// f32::INFINITY
/// );
/// painter.galley(output.text_draw_pos, galley, text_color);
/// # });
/// ```
#[inline]
pub fn hint_text(mut self, hint_text: impl Into<WidgetText>) -> Self {
self.hint_text = hint_text.into();
Expand Down
31 changes: 0 additions & 31 deletions infinite_scroll/src/egui_inbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,37 +94,6 @@ mod egui_impl {

/// Utility to send messages to egui views from async functions, callbacks, etc. without
/// having to use interior mutability.
/// Example:
/// ```no_run
/// use eframe::egui;
/// use egui::CentralPanel;
/// use egui_inbox::UiInbox;
///
/// pub fn main() -> eframe::Result<()> {
/// let mut inbox = UiInbox::new();
/// let mut state = None;
///
/// eframe::run_simple_native(
/// "DnD Simple Example",
/// Default::default(),
/// move |ctx, _frame| {
/// CentralPanel::default().show(ctx, |ui| {
/// inbox.replace(ui, &mut state);
///
/// ui.label(format!("State: {:?}", state));
/// if ui.button("Async Task").clicked() {
/// state = Some("Waiting for async task to complete".to_string());
/// let mut sender = inbox.sender();
/// std::thread::spawn(move || {
/// std::thread::sleep(std::time::Duration::from_secs(1));
/// sender.send(Some("Hello from another thread!".to_string())).ok();
/// });
/// }
/// });
/// },
/// )
/// }
/// ```
pub struct UiInbox<T> {
state: Arc<Mutex<State<T>>>,
}
Expand Down

0 comments on commit 2f8e9ef

Please sign in to comment.