Skip to content

Commit cd64367

Browse files
authored
chore(symbols): add tests for line symbols (#1186)
1 parent 07efde5 commit cd64367

File tree

2 files changed

+210
-121
lines changed

2 files changed

+210
-121
lines changed

src/symbols.rs

+2-121
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use strum::{Display, EnumString};
22

3+
pub mod line;
4+
35
pub mod block {
46
pub const FULL: &str = "█";
57
pub const SEVEN_EIGHTHS: &str = "▉";
@@ -114,127 +116,6 @@ pub mod bar {
114116
};
115117
}
116118

117-
pub mod line {
118-
pub const VERTICAL: &str = "│";
119-
pub const DOUBLE_VERTICAL: &str = "║";
120-
pub const THICK_VERTICAL: &str = "┃";
121-
122-
pub const HORIZONTAL: &str = "─";
123-
pub const DOUBLE_HORIZONTAL: &str = "═";
124-
pub const THICK_HORIZONTAL: &str = "━";
125-
126-
pub const TOP_RIGHT: &str = "┐";
127-
pub const ROUNDED_TOP_RIGHT: &str = "╮";
128-
pub const DOUBLE_TOP_RIGHT: &str = "╗";
129-
pub const THICK_TOP_RIGHT: &str = "┓";
130-
131-
pub const TOP_LEFT: &str = "┌";
132-
pub const ROUNDED_TOP_LEFT: &str = "╭";
133-
pub const DOUBLE_TOP_LEFT: &str = "╔";
134-
pub const THICK_TOP_LEFT: &str = "┏";
135-
136-
pub const BOTTOM_RIGHT: &str = "┘";
137-
pub const ROUNDED_BOTTOM_RIGHT: &str = "╯";
138-
pub const DOUBLE_BOTTOM_RIGHT: &str = "╝";
139-
pub const THICK_BOTTOM_RIGHT: &str = "┛";
140-
141-
pub const BOTTOM_LEFT: &str = "└";
142-
pub const ROUNDED_BOTTOM_LEFT: &str = "╰";
143-
pub const DOUBLE_BOTTOM_LEFT: &str = "╚";
144-
pub const THICK_BOTTOM_LEFT: &str = "┗";
145-
146-
pub const VERTICAL_LEFT: &str = "┤";
147-
pub const DOUBLE_VERTICAL_LEFT: &str = "╣";
148-
pub const THICK_VERTICAL_LEFT: &str = "┫";
149-
150-
pub const VERTICAL_RIGHT: &str = "├";
151-
pub const DOUBLE_VERTICAL_RIGHT: &str = "╠";
152-
pub const THICK_VERTICAL_RIGHT: &str = "┣";
153-
154-
pub const HORIZONTAL_DOWN: &str = "┬";
155-
pub const DOUBLE_HORIZONTAL_DOWN: &str = "╦";
156-
pub const THICK_HORIZONTAL_DOWN: &str = "┳";
157-
158-
pub const HORIZONTAL_UP: &str = "┴";
159-
pub const DOUBLE_HORIZONTAL_UP: &str = "╩";
160-
pub const THICK_HORIZONTAL_UP: &str = "┻";
161-
162-
pub const CROSS: &str = "┼";
163-
pub const DOUBLE_CROSS: &str = "╬";
164-
pub const THICK_CROSS: &str = "╋";
165-
166-
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
167-
pub struct Set {
168-
pub vertical: &'static str,
169-
pub horizontal: &'static str,
170-
pub top_right: &'static str,
171-
pub top_left: &'static str,
172-
pub bottom_right: &'static str,
173-
pub bottom_left: &'static str,
174-
pub vertical_left: &'static str,
175-
pub vertical_right: &'static str,
176-
pub horizontal_down: &'static str,
177-
pub horizontal_up: &'static str,
178-
pub cross: &'static str,
179-
}
180-
181-
impl Default for Set {
182-
fn default() -> Self {
183-
NORMAL
184-
}
185-
}
186-
187-
pub const NORMAL: Set = Set {
188-
vertical: VERTICAL,
189-
horizontal: HORIZONTAL,
190-
top_right: TOP_RIGHT,
191-
top_left: TOP_LEFT,
192-
bottom_right: BOTTOM_RIGHT,
193-
bottom_left: BOTTOM_LEFT,
194-
vertical_left: VERTICAL_LEFT,
195-
vertical_right: VERTICAL_RIGHT,
196-
horizontal_down: HORIZONTAL_DOWN,
197-
horizontal_up: HORIZONTAL_UP,
198-
cross: CROSS,
199-
};
200-
201-
pub const ROUNDED: Set = Set {
202-
top_right: ROUNDED_TOP_RIGHT,
203-
top_left: ROUNDED_TOP_LEFT,
204-
bottom_right: ROUNDED_BOTTOM_RIGHT,
205-
bottom_left: ROUNDED_BOTTOM_LEFT,
206-
..NORMAL
207-
};
208-
209-
pub const DOUBLE: Set = Set {
210-
vertical: DOUBLE_VERTICAL,
211-
horizontal: DOUBLE_HORIZONTAL,
212-
top_right: DOUBLE_TOP_RIGHT,
213-
top_left: DOUBLE_TOP_LEFT,
214-
bottom_right: DOUBLE_BOTTOM_RIGHT,
215-
bottom_left: DOUBLE_BOTTOM_LEFT,
216-
vertical_left: DOUBLE_VERTICAL_LEFT,
217-
vertical_right: DOUBLE_VERTICAL_RIGHT,
218-
horizontal_down: DOUBLE_HORIZONTAL_DOWN,
219-
horizontal_up: DOUBLE_HORIZONTAL_UP,
220-
cross: DOUBLE_CROSS,
221-
};
222-
223-
pub const THICK: Set = Set {
224-
vertical: THICK_VERTICAL,
225-
horizontal: THICK_HORIZONTAL,
226-
top_right: THICK_TOP_RIGHT,
227-
top_left: THICK_TOP_LEFT,
228-
bottom_right: THICK_BOTTOM_RIGHT,
229-
bottom_left: THICK_BOTTOM_LEFT,
230-
vertical_left: THICK_VERTICAL_LEFT,
231-
vertical_right: THICK_VERTICAL_RIGHT,
232-
horizontal_down: THICK_HORIZONTAL_DOWN,
233-
horizontal_up: THICK_HORIZONTAL_UP,
234-
cross: THICK_CROSS,
235-
};
236-
}
237-
238119
pub mod border {
239120
use super::line;
240121

src/symbols/line.rs

+208
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
pub const VERTICAL: &str = "│";
2+
pub const DOUBLE_VERTICAL: &str = "║";
3+
pub const THICK_VERTICAL: &str = "┃";
4+
5+
pub const HORIZONTAL: &str = "─";
6+
pub const DOUBLE_HORIZONTAL: &str = "═";
7+
pub const THICK_HORIZONTAL: &str = "━";
8+
9+
pub const TOP_RIGHT: &str = "┐";
10+
pub const ROUNDED_TOP_RIGHT: &str = "╮";
11+
pub const DOUBLE_TOP_RIGHT: &str = "╗";
12+
pub const THICK_TOP_RIGHT: &str = "┓";
13+
14+
pub const TOP_LEFT: &str = "┌";
15+
pub const ROUNDED_TOP_LEFT: &str = "╭";
16+
pub const DOUBLE_TOP_LEFT: &str = "╔";
17+
pub const THICK_TOP_LEFT: &str = "┏";
18+
19+
pub const BOTTOM_RIGHT: &str = "┘";
20+
pub const ROUNDED_BOTTOM_RIGHT: &str = "╯";
21+
pub const DOUBLE_BOTTOM_RIGHT: &str = "╝";
22+
pub const THICK_BOTTOM_RIGHT: &str = "┛";
23+
24+
pub const BOTTOM_LEFT: &str = "└";
25+
pub const ROUNDED_BOTTOM_LEFT: &str = "╰";
26+
pub const DOUBLE_BOTTOM_LEFT: &str = "╚";
27+
pub const THICK_BOTTOM_LEFT: &str = "┗";
28+
29+
pub const VERTICAL_LEFT: &str = "┤";
30+
pub const DOUBLE_VERTICAL_LEFT: &str = "╣";
31+
pub const THICK_VERTICAL_LEFT: &str = "┫";
32+
33+
pub const VERTICAL_RIGHT: &str = "├";
34+
pub const DOUBLE_VERTICAL_RIGHT: &str = "╠";
35+
pub const THICK_VERTICAL_RIGHT: &str = "┣";
36+
37+
pub const HORIZONTAL_DOWN: &str = "┬";
38+
pub const DOUBLE_HORIZONTAL_DOWN: &str = "╦";
39+
pub const THICK_HORIZONTAL_DOWN: &str = "┳";
40+
41+
pub const HORIZONTAL_UP: &str = "┴";
42+
pub const DOUBLE_HORIZONTAL_UP: &str = "╩";
43+
pub const THICK_HORIZONTAL_UP: &str = "┻";
44+
45+
pub const CROSS: &str = "┼";
46+
pub const DOUBLE_CROSS: &str = "╬";
47+
pub const THICK_CROSS: &str = "╋";
48+
49+
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
50+
pub struct Set {
51+
pub vertical: &'static str,
52+
pub horizontal: &'static str,
53+
pub top_right: &'static str,
54+
pub top_left: &'static str,
55+
pub bottom_right: &'static str,
56+
pub bottom_left: &'static str,
57+
pub vertical_left: &'static str,
58+
pub vertical_right: &'static str,
59+
pub horizontal_down: &'static str,
60+
pub horizontal_up: &'static str,
61+
pub cross: &'static str,
62+
}
63+
64+
impl Default for Set {
65+
fn default() -> Self {
66+
NORMAL
67+
}
68+
}
69+
70+
pub const NORMAL: Set = Set {
71+
vertical: VERTICAL,
72+
horizontal: HORIZONTAL,
73+
top_right: TOP_RIGHT,
74+
top_left: TOP_LEFT,
75+
bottom_right: BOTTOM_RIGHT,
76+
bottom_left: BOTTOM_LEFT,
77+
vertical_left: VERTICAL_LEFT,
78+
vertical_right: VERTICAL_RIGHT,
79+
horizontal_down: HORIZONTAL_DOWN,
80+
horizontal_up: HORIZONTAL_UP,
81+
cross: CROSS,
82+
};
83+
84+
pub const ROUNDED: Set = Set {
85+
top_right: ROUNDED_TOP_RIGHT,
86+
top_left: ROUNDED_TOP_LEFT,
87+
bottom_right: ROUNDED_BOTTOM_RIGHT,
88+
bottom_left: ROUNDED_BOTTOM_LEFT,
89+
..NORMAL
90+
};
91+
92+
pub const DOUBLE: Set = Set {
93+
vertical: DOUBLE_VERTICAL,
94+
horizontal: DOUBLE_HORIZONTAL,
95+
top_right: DOUBLE_TOP_RIGHT,
96+
top_left: DOUBLE_TOP_LEFT,
97+
bottom_right: DOUBLE_BOTTOM_RIGHT,
98+
bottom_left: DOUBLE_BOTTOM_LEFT,
99+
vertical_left: DOUBLE_VERTICAL_LEFT,
100+
vertical_right: DOUBLE_VERTICAL_RIGHT,
101+
horizontal_down: DOUBLE_HORIZONTAL_DOWN,
102+
horizontal_up: DOUBLE_HORIZONTAL_UP,
103+
cross: DOUBLE_CROSS,
104+
};
105+
106+
pub const THICK: Set = Set {
107+
vertical: THICK_VERTICAL,
108+
horizontal: THICK_HORIZONTAL,
109+
top_right: THICK_TOP_RIGHT,
110+
top_left: THICK_TOP_LEFT,
111+
bottom_right: THICK_BOTTOM_RIGHT,
112+
bottom_left: THICK_BOTTOM_LEFT,
113+
vertical_left: THICK_VERTICAL_LEFT,
114+
vertical_right: THICK_VERTICAL_RIGHT,
115+
horizontal_down: THICK_HORIZONTAL_DOWN,
116+
horizontal_up: THICK_HORIZONTAL_UP,
117+
cross: THICK_CROSS,
118+
};
119+
120+
#[cfg(test)]
121+
mod tests {
122+
use indoc::{formatdoc, indoc};
123+
124+
use super::*;
125+
126+
#[test]
127+
fn default() {
128+
assert_eq!(Set::default(), NORMAL);
129+
}
130+
131+
/// A helper function to render a set of symbols.
132+
fn render(set: Set) -> String {
133+
formatdoc!(
134+
"{}{}{}{}
135+
{}{}{}{}
136+
{}{}{}{}
137+
{}{}{}{}",
138+
set.top_left,
139+
set.horizontal,
140+
set.horizontal_down,
141+
set.top_right,
142+
set.vertical,
143+
" ",
144+
set.vertical,
145+
set.vertical,
146+
set.vertical_right,
147+
set.horizontal,
148+
set.cross,
149+
set.vertical_left,
150+
set.bottom_left,
151+
set.horizontal,
152+
set.horizontal_up,
153+
set.bottom_right
154+
)
155+
}
156+
157+
#[test]
158+
fn normal() {
159+
assert_eq!(
160+
render(NORMAL),
161+
indoc!(
162+
"┌─┬┐
163+
│ ││
164+
├─┼┤
165+
└─┴┘"
166+
)
167+
);
168+
}
169+
170+
#[test]
171+
fn rounded() {
172+
assert_eq!(
173+
render(ROUNDED),
174+
indoc!(
175+
"╭─┬╮
176+
│ ││
177+
├─┼┤
178+
╰─┴╯"
179+
)
180+
);
181+
}
182+
183+
#[test]
184+
fn double() {
185+
assert_eq!(
186+
render(DOUBLE),
187+
indoc!(
188+
"╔═╦╗
189+
║ ║║
190+
╠═╬╣
191+
╚═╩╝"
192+
)
193+
);
194+
}
195+
196+
#[test]
197+
fn thick() {
198+
assert_eq!(
199+
render(THICK),
200+
indoc!(
201+
"┏━┳┓
202+
┃ ┃┃
203+
┣━╋┫
204+
┗━┻┛"
205+
)
206+
);
207+
}
208+
}

0 commit comments

Comments
 (0)