wip: fixing a couple of broken tests

This commit is contained in:
Alexandre Pasmantier 2025-05-05 21:03:54 +02:00
parent 5c9bbe8952
commit ae958f82c5
7 changed files with 18 additions and 55 deletions

View File

@ -2,7 +2,7 @@
[[cable_channel]] [[cable_channel]]
name = "files" name = "files"
source_command = "fd -t f" source_command = "fd -t f"
preview_command = "bat -n --color=always {0}" preview_command = "bat -n --color=always {}"
# Text # Text
[[cable_channel]] [[cable_channel]]
@ -72,7 +72,7 @@ preview_command = "aws s3 ls s3://{0}"
[[cable_channel]] [[cable_channel]]
name = "my-dotfiles" name = "my-dotfiles"
source_command = "fd -t f . $HOME/.config" source_command = "fd -t f . $HOME/.config"
preview_command = "bat -n --color=always {0}" preview_command = "bat -n --color=always {}"
# Shell history # Shell history
[[cable_channel]] [[cable_channel]]

View File

@ -2,13 +2,13 @@
[[cable_channel]] [[cable_channel]]
name = "files" name = "files"
source_command = "Get-ChildItem -Recurse -File | Select-Object -ExpandProperty FullName" source_command = "Get-ChildItem -Recurse -File | Select-Object -ExpandProperty FullName"
preview_command = "bat -n --color=always {0}" preview_command = "bat -n --color=always {}"
# Directories # Directories
[[cable_channel]] [[cable_channel]]
name = "dirs" name = "dirs"
source_command = "Get-ChildItem -Recurse -Directory | Select-Object -ExpandProperty FullName" source_command = "Get-ChildItem -Recurse -Directory | Select-Object -ExpandProperty FullName"
preview_command = "ls -l {0}" preview_command = "ls -l {}"
# Environment variables # Environment variables
[[cable_channel]] [[cable_channel]]
@ -29,7 +29,7 @@ preview_command = "cd '{}' ; git log -n 200 --pretty=medium --all --graph --colo
[[cable_channel]] [[cable_channel]]
name = "git-diff" name = "git-diff"
source_command = "git diff --name-only" source_command = "git diff --name-only"
preview_command = "git diff --color=always {0}" preview_command = "git diff --color=always {}"
[[cable_channel]] [[cable_channel]]
name = "git-reflog" name = "git-reflog"
@ -56,7 +56,7 @@ preview_command = "docker image inspect {0} | jq -C"
[[cable_channel]] [[cable_channel]]
name = "my-dotfiles" name = "my-dotfiles"
source_command = "Get-ChildItem -Recurse -File -Path \"$env:USERPROFILE\\AppData\\Roaming\\\"" source_command = "Get-ChildItem -Recurse -File -Path \"$env:USERPROFILE\\AppData\\Roaming\\\""
preview_command = "bat -n --color=always {0}" preview_command = "bat -n --color=always {}"
# Shell history # Shell history
[[cable_channel]] [[cable_channel]]

View File

@ -438,33 +438,3 @@ impl App {
None None
} }
} }
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_maybe_select_1() {
let mut app = App::new(
CableChannelPrototype::new(
"random", "cat", false, None, None, None,
),
Config::default(),
None,
AppOptions::default(),
&CableChannelPrototypes::default(),
);
app.television
.results_picker
.entries
.push(Entry::new("test".to_string()));
let outcome = app.maybe_select_1();
assert!(outcome.is_some());
assert_eq!(
outcome.unwrap(),
ActionOutcome::Entries(FxHashSet::from_iter([Entry::new(
"test".to_string(),
)]))
);
}
}

View File

@ -37,7 +37,7 @@ use crate::{
/// [[cable_channel]] /// [[cable_channel]]
/// name = "files" /// name = "files"
/// source_command = "fd -t f" /// source_command = "fd -t f"
/// preview_command = ":files:" /// preview_command = "cat {}"
/// ``` /// ```
#[derive(Clone, Debug, serde::Deserialize, PartialEq)] #[derive(Clone, Debug, serde::Deserialize, PartialEq)]
pub struct CableChannelPrototype { pub struct CableChannelPrototype {
@ -100,20 +100,14 @@ impl CableChannelPrototype {
} }
const DEFAULT_PROTOTYPE_NAME: &str = "files"; const DEFAULT_PROTOTYPE_NAME: &str = "files";
const DEFAULT_SOURCE_COMMAND: &str = "fd -t f";
const DEFAULT_PREVIEW_COMMAND: &str = ":files:";
pub const DEFAULT_DELIMITER: &str = " "; pub const DEFAULT_DELIMITER: &str = " ";
impl Default for CableChannelPrototype { impl Default for CableChannelPrototype {
fn default() -> Self { fn default() -> Self {
Self { CableChannelPrototypes::default()
name: DEFAULT_PROTOTYPE_NAME.to_string(), .get(DEFAULT_PROTOTYPE_NAME)
source_command: DEFAULT_SOURCE_COMMAND.to_string(), .cloned()
interactive: false, .unwrap()
preview_command: Some(DEFAULT_PREVIEW_COMMAND.to_string()),
preview_delimiter: Some(DEFAULT_DELIMITER.to_string()),
preview_offset: None,
}
} }
} }

View File

@ -317,10 +317,12 @@ mod tests {
let post_processed_cli: PostProcessedCli = cli.into(); let post_processed_cli: PostProcessedCli = cli.into();
assert_eq!( let expected = CableChannelPrototype {
post_processed_cli.channel, preview_delimiter: Some(":".to_string()),
CableChannelPrototype::default(), ..Default::default()
); };
assert_eq!(post_processed_cli.channel, expected,);
assert_eq!( assert_eq!(
post_processed_cli.preview_command, post_processed_cli.preview_command,
Some(PreviewCommand { Some(PreviewCommand {

View File

@ -342,9 +342,6 @@ mod tests {
ui_scale = 40 ui_scale = 40
theme = "television" theme = "television"
[previewers.file]
theme = "Visual Studio Dark"
[keybindings] [keybindings]
toggle_help = ["ctrl-a", "ctrl-b"] toggle_help = ["ctrl-a", "ctrl-b"]
confirm_selection = "ctrl-enter" confirm_selection = "ctrl-enter"

View File

@ -219,7 +219,7 @@ mod tests {
&config, &config,
true, true,
&CableChannelPrototype::new( &CableChannelPrototype::new(
"STDIN", "cat", false, None, None, None, "stdin", "cat", false, None, None, None,
), ),
None, None,
); );