Fix doc-tests

This commit is contained in:
Alexandre Bury 2015-06-04 11:40:35 -07:00
parent 1e42631fb3
commit cb523e88ae
8 changed files with 30 additions and 8 deletions

View File

@ -293,7 +293,7 @@ impl From<io::Error> for Error {
/// ///
/// Here is an example file: /// Here is an example file:
/// ///
/// ``` /// ```text
/// background = "#5555FF" /// background = "#5555FF"
/// shadow = "#000000" /// shadow = "#000000"
/// view = "#888888" /// view = "#888888"

View File

@ -4,7 +4,7 @@
//! It allows to easily build layouts for text-based applications. //! It allows to easily build layouts for text-based applications.
//! //!
//! ## Example //! ## Example
//! ``` //! ```no_run
//! extern crate cursive; //! extern crate cursive;
//! //!
//! use cursive::Cursive; //! use cursive::Cursive;
@ -15,7 +15,7 @@
//! //!
//! siv.add_layer(TextView::new("Hello World!\nPress q to quit.")); //! siv.add_layer(TextView::new("Hello World!\nPress q to quit."));
//! //!
//! siv.add_global_callback('q' as i32, |s| s.quit()); //! siv.add_global_callback('q', |s| s.quit());
//! //!
//! siv.run(); //! siv.run();
//! } //! }

View File

@ -73,6 +73,9 @@ impl Printer {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # use cursive::printer::Printer;
/// # use cursive::color;
/// # let printer = Printer::new((6,4));
/// printer.with_color(color::HIGHLIGHT, |printer| { /// printer.with_color(color::HIGHLIGHT, |printer| {
/// printer.print((0,0), "This text is highlighted!"); /// printer.print((0,0), "This text is highlighted!");
/// }); /// });
@ -103,6 +106,8 @@ impl Printer {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # use cursive::printer::Printer;
/// # let printer = Printer::new((6,4));
/// printer.print_box((0,0), (6,4)); /// printer.print_box((0,0), (6,4));
/// ``` /// ```
pub fn print_box<T: ToVec2>(&self, start: T, size: T) { pub fn print_box<T: ToVec2>(&self, start: T, size: T) {

View File

@ -14,8 +14,9 @@ impl BoxView {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # use cursive::view::{BoxView,TextView};
/// // Creates a 20x4 BoxView with a TextView content. /// // Creates a 20x4 BoxView with a TextView content.
/// let box = BoxView::new((20,4), TextView::new("Hello!")) /// let view = BoxView::new((20,4), TextView::new("Hello!"));
/// ``` /// ```
pub fn new<S: ToVec2, V: View + 'static>(size: S, view: V) -> Self { pub fn new<S: ToVec2, V: View + 'static>(size: S, view: V) -> Self {
BoxView { BoxView {

View File

@ -21,7 +21,8 @@ enum Focus {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// let dialog = Dialog::new(TextView::new("Hello!")).button("Ok", |s,_| s.quit()); /// # use cursive::view::{Dialog,TextView};
/// let dialog = Dialog::new(TextView::new("Hello!")).button("Ok", |s| s.quit());
/// ``` /// ```
pub struct Dialog { pub struct Dialog {
title: String, title: String,

View File

@ -33,6 +33,7 @@ pub use self::id_view::IdView;
pub use self::shadow_view::ShadowView; pub use self::shadow_view::ShadowView;
pub use self::edit_view::EditView; pub use self::edit_view::EditView;
pub use self::select_view::SelectView; pub use self::select_view::SelectView;
pub use self::scroll::ScrollBase;
use event::{Event,EventResult}; use event::{Event,EventResult};
use vec::{Vec2,ToVec2}; use vec::{Vec2,ToVec2};

View File

@ -86,6 +86,12 @@ impl ScrollBase {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # use cursive::view::ScrollBase;
/// # use cursive::printer::Printer;
/// # let scrollbase = ScrollBase::new();
/// # let printer = Printer::new((5,1));
/// # let printer = &printer;
/// let lines = ["Line 1", "Line number 2"];
/// scrollbase.draw(printer, |printer, i| { /// scrollbase.draw(printer, |printer, i| {
/// printer.print((0,0), lines[i]); /// printer.print((0,0), lines[i]);
/// }); /// });

View File

@ -77,26 +77,33 @@ impl <T: ViewWrapper> View for T {
/// ///
/// If the wrapped view is in a box, just name it in the macro: /// If the wrapped view is in a box, just name it in the macro:
/// ///
/// ``` /// ```rust
/// # #[macro_use] extern crate cursive;
/// # use cursive::view::{View,ViewWrapper};
/// struct BoxFooView { /// struct BoxFooView {
/// content: Box<View>, /// content: Box<View>,
/// } /// }
/// ///
/// impl ViewWrapper for FooView { /// impl ViewWrapper for BoxFooView {
/// wrap_impl!(self.content); /// wrap_impl!(self.content);
/// } /// }
///
/// # fn main() { }
/// ``` /// ```
/// ///
/// If the content is directly a view, reference it: /// If the content is directly a view, reference it:
/// ///
/// ``` /// ```
/// # #[macro_use] extern crate cursive;
/// # use cursive::view::{View,ViewWrapper};
/// struct FooView<T: View> { /// struct FooView<T: View> {
/// view: T, /// view: T,
/// } /// }
/// ///
/// impl <T> ViewWrapper for FooView<T> { /// impl <T: View> ViewWrapper for FooView<T> {
/// wrap_impl!(&self.view); /// wrap_impl!(&self.view);
/// } /// }
/// # fn main() { }
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! wrap_impl { macro_rules! wrap_impl {
@ -121,3 +128,4 @@ macro_rules! wrap_impl {
} }
}; };
} }