• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

veeso / termscp / 4926442260

pending completion
4926442260

push

github

veeso
rustfmt.toml

5042 of 5376 relevant lines covered (93.79%)

15.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.96
/src/explorer/builder.rs
1
//! ## Builder
2
//!
3
//! `builder` is the module which provides a builder for FileExplorer
4

5
// Locals
6
// Ext
7
use std::collections::VecDeque;
8

9
use super::formatter::Formatter;
10
use super::{ExplorerOpts, FileExplorer, FileSorting, GroupDirs};
11

12
/// Struct used to create a `FileExplorer`
13
pub struct FileExplorerBuilder {
14
    explorer: Option<FileExplorer>,
15
}
16

17
impl FileExplorerBuilder {
18
    /// Build a new `FileExplorerBuilder`
19
    pub fn new() -> Self {
2✔
20
        FileExplorerBuilder {
2✔
21
            explorer: Some(FileExplorer::default()),
2✔
22
        }
23
    }
2✔
24

25
    /// Take FileExplorer out of builder
26
    pub fn build(&mut self) -> FileExplorer {
2✔
27
        self.explorer.take().unwrap()
2✔
28
    }
2✔
29

30
    /// Enable HIDDEN_FILES option
31
    pub fn with_hidden_files(&mut self, val: bool) -> &mut FileExplorerBuilder {
1✔
32
        if let Some(e) = self.explorer.as_mut() {
1✔
33
            match val {
1✔
34
                true => e.opts.insert(ExplorerOpts::SHOW_HIDDEN_FILES),
1✔
35
                false => e.opts.remove(ExplorerOpts::SHOW_HIDDEN_FILES),
×
36
            }
37
        }
38
        self
39
    }
1✔
40

41
    /// Set sorting method
42
    pub fn with_file_sorting(&mut self, sorting: FileSorting) -> &mut FileExplorerBuilder {
1✔
43
        if let Some(e) = self.explorer.as_mut() {
1✔
44
            e.sort_by(sorting);
1✔
45
        }
46
        self
47
    }
1✔
48

49
    /// Enable DIRS_FIRST option
50
    pub fn with_group_dirs(&mut self, group_dirs: Option<GroupDirs>) -> &mut FileExplorerBuilder {
1✔
51
        if let Some(e) = self.explorer.as_mut() {
1✔
52
            e.group_dirs_by(group_dirs);
1✔
53
        }
54
        self
55
    }
1✔
56

57
    /// Set stack size for FileExplorer
58
    pub fn with_stack_size(&mut self, sz: usize) -> &mut FileExplorerBuilder {
1✔
59
        if let Some(e) = self.explorer.as_mut() {
1✔
60
            e.stack_size = sz;
1✔
61
            e.dirstack = VecDeque::with_capacity(sz);
1✔
62
        }
63
        self
64
    }
1✔
65

66
    /// Set formatter for FileExplorer
67
    pub fn with_formatter(&mut self, fmt_str: Option<&str>) -> &mut FileExplorerBuilder {
1✔
68
        if let Some(e) = self.explorer.as_mut() {
1✔
69
            if let Some(fmt_str) = fmt_str {
1✔
70
                e.fmt = Formatter::new(fmt_str);
1✔
71
            }
72
        }
73
        self
74
    }
1✔
75
}
76

77
#[cfg(test)]
78
mod tests {
79

80
    use pretty_assertions::assert_eq;
81

82
    use super::*;
83

84
    #[test]
85
    fn test_fs_explorer_builder_new_default() {
2✔
86
        let explorer: FileExplorer = FileExplorerBuilder::new().build();
1✔
87
        // Verify
88
        assert!(!explorer.opts.intersects(ExplorerOpts::SHOW_HIDDEN_FILES));
1✔
89
        assert_eq!(explorer.file_sorting, FileSorting::Name); // Default
1✔
90
        assert_eq!(explorer.group_dirs, None);
1✔
91
        assert_eq!(explorer.stack_size, 16);
1✔
92
    }
2✔
93

94
    #[test]
95
    fn test_fs_explorer_builder_new_all() {
2✔
96
        let explorer: FileExplorer = FileExplorerBuilder::new()
4✔
97
            .with_file_sorting(FileSorting::ModifyTime)
1✔
98
            .with_group_dirs(Some(GroupDirs::First))
1✔
99
            .with_hidden_files(true)
100
            .with_stack_size(24)
101
            .with_formatter(Some("{NAME}"))
1✔
102
            .build();
1✔
103
        // Verify
104
        assert!(explorer.opts.intersects(ExplorerOpts::SHOW_HIDDEN_FILES));
1✔
105
        assert_eq!(explorer.file_sorting, FileSorting::ModifyTime); // Default
1✔
106
        assert_eq!(explorer.group_dirs, Some(GroupDirs::First));
1✔
107
        assert_eq!(explorer.stack_size, 24);
1✔
108
    }
2✔
109
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc