1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
use ansi_term::Color;
use git2::Repository;
use starship::segment::Segment;
use std::fs;
use std::io;
use std::path::Path;
use tempfile::TempDir;
mod common;
#[test]
fn home_directory() -> io::Result<()> {
let dir = Path::new("~");
let expected = Segment::new("dir")
.set_value("~")
.set_style(Color::Cyan.bold())
.output();
let actual = common::render_segment("dir", &dir);
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn directory_in_home() -> io::Result<()> {
let dir = Path::new("~/starship/engine");
let expected = Segment::new("dir")
.set_value("~/starship/engine")
.set_style(Color::Cyan.bold())
.output();
let actual = common::render_segment("dir", &dir);
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn truncated_directory_in_home() -> io::Result<()> {
let dir = Path::new("~/starship/engine/schematics");
let expected = Segment::new("dir")
.set_value("starship/engine/schematics")
.set_style(Color::Cyan.bold())
.output();
let actual = common::render_segment("dir", &dir);
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn root_directory() -> io::Result<()> {
let dir = Path::new("/");
let expected = Segment::new("dir")
.set_value("/")
.set_style(Color::Cyan.bold())
.output();
let actual = common::render_segment("dir", &dir);
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn directory_in_root() -> io::Result<()> {
let dir = Path::new("/private");
let expected = Segment::new("dir")
.set_value("/private")
.set_style(Color::Cyan.bold())
.output();
let actual = common::render_segment("dir", &dir);
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn truncated_directory_in_root() -> io::Result<()> {
let dir = Path::new("/private/var/folders/3s");
let expected = Segment::new("dir")
.set_value("var/folders/3s")
.set_style(Color::Cyan.bold())
.output();
let actual = common::render_segment("dir", &dir);
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn git_repo_root() -> io::Result<()> {
let tmp_dir = TempDir::new()?;
let repo_dir = tmp_dir.path().join("rocket-controls");
fs::create_dir(&repo_dir)?;
Repository::init(&repo_dir).unwrap();
let expected = Segment::new("dir")
.set_value("rocket-controls")
.set_style(Color::Cyan.bold())
.output();
let actual = common::render_segment("dir", &repo_dir);
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn directory_in_git_repo() -> io::Result<()> {
let tmp_dir = TempDir::new()?;
let repo_dir = tmp_dir.path().join("rocket-controls");
let dir = repo_dir.join("src");
fs::create_dir_all(&dir)?;
Repository::init(&repo_dir).unwrap();
let expected = Segment::new("dir")
.set_value("rocket-controls/src")
.set_style(Color::Cyan.bold())
.output();
let actual = common::render_segment("dir", &dir);
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn truncated_directory_in_git_repo() -> io::Result<()> {
let tmp_dir = TempDir::new()?;
let repo_dir = tmp_dir.path().join("rocket-controls");
let dir = repo_dir.join("src/meters/fuel-gauge");
fs::create_dir_all(&dir)?;
Repository::init(&repo_dir).unwrap();
let expected = Segment::new("dir")
.set_value("src/meters/fuel-gauge")
.set_style(Color::Cyan.bold())
.output();
let actual = common::render_segment("dir", &dir);
assert_eq!(expected, actual);
Ok(())
}
|