Skip to content

Commit 4897fe3

Browse files
committed
fix: existing doctests not compiling
1 parent 3a951c7 commit 4897fe3

File tree

5 files changed

+45
-16
lines changed

5 files changed

+45
-16
lines changed

packages/wm/src/common/direction.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ impl Direction {
1717
///
1818
/// Example:
1919
/// ```
20-
/// Direction::Left.inverse() // Direction::Right
20+
/// # use wm::common::Direction;
21+
/// let dir = Direction::Left.inverse();
22+
/// assert_eq!(dir, Direction::Right);
2123
/// ```
2224
pub fn inverse(&self) -> Direction {
2325
match self {
@@ -36,7 +38,10 @@ impl FromStr for Direction {
3638
///
3739
/// Example:
3840
/// ```
39-
/// Direction::from_str("left") // Direction::Left
41+
/// # use wm::common::Direction;
42+
/// # use std::str::FromStr;
43+
/// let dir = Direction::from_str("left");
44+
/// assert_eq!(dir.unwrap(), Direction::Left);
4045
/// ```
4146
fn from_str(unparsed: &str) -> anyhow::Result<Self> {
4247
match unparsed {

packages/wm/src/common/length_value.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ impl FromStr for LengthValue {
5050
///
5151
/// Example:
5252
/// ```
53-
/// LengthValue::from_str("100px") // { amount: 100.0, unit: LengthUnit::Pixel }
53+
/// # use wm::common::{LengthValue, LengthUnit};
54+
/// # use std::str::FromStr;
55+
/// let check = LengthValue {
56+
/// amount: 100.0,
57+
/// unit: LengthUnit::Pixel,
58+
/// };
59+
/// let parsed = LengthValue::from_str("100px");
60+
/// assert_eq!(parsed.unwrap(), check);
5461
/// ```
5562
fn from_str(unparsed: &str) -> anyhow::Result<Self> {
5663
let units_regex = Regex::new(r"([+-]?\d+)(%|px)?")?;

packages/wm/src/common/platform/platform.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,23 @@ impl Platform {
337337
///
338338
/// # Examples
339339
///
340-
/// ```
341-
/// let (prog, args) = parse_command("code .")?;
342-
/// assert_eq!(prog, "code");
343-
/// assert_eq!(args, ".");
340+
/// ```no_run
341+
/// # // Since this checks if the path exists, not sure how to test this.
342+
/// # // Don't think you can `use` a struct method.
343+
/// # use wm::common::platform::Platform;
344+
/// fn main() -> anyhow::Result<()> {
345+
/// let (prog, args) = Platform::parse_command("code .")?;
346+
/// assert_eq!(prog, "code");
347+
/// assert_eq!(args, ".");
348+
///
349+
/// let (prog, args) = Platform::parse_command(
350+
/// r#"C:\Program Files\Git\git-bash --cd=C:\Users\larsb\.glaze-wm"#,
351+
/// )?;
352+
/// assert_eq!(prog, r#"C:\Program Files\Git\git-bash"#);
353+
/// assert_eq!(args, r#"--cd=C:\Users\larsb\.glaze-wm"#);
344354
///
345-
/// let (prog, args) = parse_command(
346-
/// r#"C:\Program Files\Git\git-bash --cd=C:\Users\larsb\.glaze-wm"#,
347-
/// )?;
348-
/// assert_eq!(prog, r#"C:\Program Files\Git\git-bash"#);
349-
/// assert_eq!(args, r#"--cd=C:\Users\larsb\.glaze-wm"#);
355+
/// Ok(())
356+
/// }
350357
/// ```
351358
pub fn parse_command(command: &str) -> anyhow::Result<(String, String)> {
352359
// Expand environment variables in the command string.

packages/wm/src/common/tiling_direction.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ impl TilingDirection {
1717
///
1818
/// Example:
1919
/// ```
20-
/// TilingDirection::Horizontal.inverse() // TilingDirection::Vertical
20+
/// # use wm::common::TilingDirection;
21+
/// let dir = TilingDirection::Horizontal.inverse();
22+
/// assert_eq!(dir, TilingDirection::Vertical);
2123
/// ```
2224
pub fn inverse(&self) -> TilingDirection {
2325
match self {
@@ -31,7 +33,9 @@ impl TilingDirection {
3133
///
3234
/// Example:
3335
/// ```
34-
/// TilingDirection::from_direction(Direction::Left) // TilingDirection::Horizontal
36+
/// # use wm::common::{Direction, TilingDirection};
37+
/// let dir = TilingDirection::from_direction(&Direction::Left);
38+
/// assert_eq!(dir, TilingDirection::Horizontal);
3539
/// ```
3640
pub fn from_direction(direction: &Direction) -> TilingDirection {
3741
match direction {
@@ -48,7 +52,13 @@ impl FromStr for TilingDirection {
4852
///
4953
/// Example:
5054
/// ```
51-
/// TilingDirection::from_str("horizontal") // TilingDirection::Horizontal
55+
/// # use wm::common::TilingDirection;
56+
/// # use std::str::FromStr;
57+
/// let dir = TilingDirection::from_str("horizontal");
58+
/// assert_eq!(dir.unwrap(), TilingDirection::Horizontal);
59+
///
60+
/// let dir = TilingDirection::from_str("vertical");
61+
/// assert_eq!(dir.unwrap(), TilingDirection::Vertical);
5262
/// ```
5363
fn from_str(unparsed: &str) -> anyhow::Result<Self> {
5464
match unparsed {

packages/wm/src/containers/commands/flatten_child_split_containers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::containers::{
88
/// parent container.
99
///
1010
/// For example:
11-
/// ```
11+
/// ```no_run,compile_fail,ignore
1212
/// H[1 H[V[2, 3]]] -> H[1, 2, 3]
1313
/// H[1 H[2, 3]] -> H[1, 2, 3]
1414
/// H[V[1]] -> V[1]

0 commit comments

Comments
 (0)