ronantakizawa/codereview-bench huggingface dataset:
Repository: zellij-org/zellij
File: zellij-utils/src/input/unit/layout_test.rs (Rust)

Code before:
            }
            pane_template name="vertical-sandwich" split_direction="Vertical" {
                pane
                children
                pane
            }
            horizontal-with-vertical-top name="my tab" {
                pane
                pane
            }
            horizontal-with-vertical-top
        }
    "#;
    let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap();
    assert_snapshot!(format!("{:#?}", layout));
}

#[test]
fn layout_with_pane_excluded_from_sync() {
    let kdl_layout = r#"
        layout {
            pane exclude_from_sync=true
        }
    "#;
    let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap();
    assert_snapshot!(format!("{:?}", layout));
}

#[test]
fn cannot_define_tab_template_name_with_space() {
    let kdl_layout = r#"
        layout {
            tab_template name="with space" {
                pane
                children
                pane
            }
            pane
        }
    "#;
    let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None);
    assert!(layout.is_err(), "error provided for tab name with space");
}

#[test]
fn cannot_define_pane_template_name_with_space() {
    let kdl_layout = r#"
        layout {
            pane_template name="with space" {
                pane
                children

Review comment (suggestion):
Could we maybe do `{:#?}` instead of `{:?}`? This will spread it out with proper indentations and I think it will be easier to review.

Code after:
            }
            pane_template name="vertical-sandwich" split_direction="Vertical" {
                pane
                children
                pane
            }
            horizontal-with-vertical-top name="my tab" {
                pane
                pane
            }
            horizontal-with-vertical-top
        }
    "#;
    let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap();
    assert_snapshot!(format!("{:#?}", layout));
}

#[test]
fn layout_with_pane_excluded_from_sync() {
    let kdl_layout = r#"
        layout {
            pane exclude_from_sync=true
        }
    "#;
    let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap();
    assert_snapshot!(format!("{:#?}", layout));
}

#[test]
fn cannot_define_tab_template_name_with_space() {
    let kdl_layout = r#"
        layout {
            tab_template name="with space" {
                pane
                children
                pane
            }
            pane
        }
    "#;
    let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None);
    assert!(layout.is_err(), "error provided for tab name with space");
}

#[test]
fn cannot_define_pane_template_name_with_space() {
    let kdl_layout = r#"
        layout {
            pane_template name="with space" {
                pane
                children
Repository: zellij-org/zellij
File: zellij-utils/src/cli.rs (Rust)

Code before:
use crate::data::{Direction, InputMode, Resize};
use crate::setup::Setup;
use crate::{
    consts::{ZELLIJ_CONFIG_DIR_ENV, ZELLIJ_CONFIG_FILE_ENV},
    input::options::CliOptions,
};
use clap::{Parser, Subcommand};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use url::Url;

fn validate_session(name: &str) -> Result<String, String> {
    #[cfg(unix)]
    {
        let mut socket_path = crate::consts::ZELLIJ_SOCK_DIR.clone();
        let available_length = 108_usize
            .saturating_sub(socket_path.as_os_str().len())
            .saturating_sub(1);
        socket_path.push(name);
        if socket_path.as_os_str().len() >= 108 {
            // socket path must be less than 108 bytes
            return Err(format!(
                "session name must be less than {} characters",
                available_length
            ));
        };
    };

    Ok(name.to_owned())
}

#[derive(Parser, Default, Debug, Clone, Serialize, Deserialize)]
#[clap(version, name = "zellij")]
pub struct CliArgs {
    /// Maximum panes on screen, caution: opening more panes will close old ones
    #[clap(long, value_parser)]
    pub max_panes: Option<usize>,

    /// Change where zellij looks for plugins
    #[clap(long, value_parser, overrides_with = "data_dir")]
    pub data_dir: Option<PathBuf>,

    /// Run server listening at the specified socket path
    #[clap(long, value_parser, hide = true, overrides_with = "server")]
    pub server: Option<PathBuf>,

Review comment (refactor):
Consider extracting `108` into some constant just because it's being reused here and under `available_length`

Code after:
use crate::data::{Direction, InputMode, Resize};
use crate::setup::Setup;
use crate::{
    consts::{ZELLIJ_CONFIG_DIR_ENV, ZELLIJ_CONFIG_FILE_ENV},
    input::options::CliOptions,
};
use clap::{Parser, Subcommand};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use url::Url;

fn validate_session(name: &str) -> Result<String, String> {
    #[cfg(unix)]
    {
        use crate::consts::ZELLIJ_SOCK_MAX_LENGTH;

        let mut socket_path = crate::consts::ZELLIJ_SOCK_DIR.clone();
        socket_path.push(name);

        if socket_path.as_os_str().len() >= ZELLIJ_SOCK_MAX_LENGTH {
            // socket path must be less than 108 bytes
            let available_length = ZELLIJ_SOCK_MAX_LENGTH
                .saturating_sub(socket_path.as_os_str().len())
                .saturating_sub(1);

            return Err(format!(
                "session name must be less than {} characters",
                available_length
            ));
        };
    };

    Ok(name.to_owned())
}

#[derive(Parser, Default, Debug, Clone, Serialize, Deserialize)]
#[clap(version, name = "zellij")]
pub struct CliArgs {
    /// Maximum panes on screen, caution: opening more panes will close old ones
    #[clap(long, value_parser)]
    pub max_panes: Option<usize>,

    /// Change where zellij looks for plugins
    #[clap(long, value_parser, overrides_with = "data_dir")]
    pub data_dir: Option<PathBuf>,