1#![crate_name = "string_sharp"]
5
6#![crate_type = "lib"]
7
8mod common;
9mod string_date;
10#[cfg(test)]
11mod tests {
12 use super::*;
13use common::*;
14use string_date::*;
15
16
17 #[test]
18 fn test_append() {
19 let s = "the quick brown fox jumps over the lazy dog".to_string();
20 let result = s.append(" and the cat".to_string());
21 assert_eq!(result, "the quick brown fox jumps over the lazy dog and the cat".to_string());
22 }
23 #[test]
24 fn test_left(){
25 let s = "the quick brown fox jumps over the lazy dog".to_string();
26 let left = s.left(3).clone();
27 assert_eq!(left, Ok("the".to_string()));
28 }
29 #[test]
30 fn test_right(){
31 let s = "the quick brown fox jumps over the lazy dog".to_string();
32 let right: Result<String, String> = s.right(3).clone();
33 assert_eq!(right, Ok("dog".to_string()));
34 }
35 #[test]
36 fn test_strip(){
37 let s = "the quick brown fox jumps over the lazy dog".to_string();
38 let result = s.strip("the");
39 assert_eq!(result, " quick brown fox jumps over lazy dog".to_string());
40 }
41 #[test]
42 fn test_strip_chars(){
43 let s = "the quick brown fox jumps over the lazy dog".to_string();
44 let result = s.strip_chars("the");
45 assert_eq!(result, " quick brown fox jumps ovr lazy dog".to_string());
46 }
47 #[test]
48 fn test_reverse(){
49 let s = "the quick brown fox jumps over the lazy dog".to_string();
50 let result = s.reverse();
51 assert_eq!(result, "god yzal eht revo spmuj xof nworb kciuq eht".to_string());
52 }
53
54 fn test_append_date() {
55 let s = "the quick brown fox jumps over the lazy dog".to_string();
56 let result = s.ymd();
57 assert_eq!(result, "the quick brown fox jumps over the lazy dog-2022-12-17".to_string());
58 }
59 #[test]
60 fn test_index_of(){
61 let s = "the quick brown fox jumps over the lazy dog".to_string();
62 let result = s.index_of("the");
63 assert_eq!(result, 0);
64 let s1 = "the quick brown fox jumps over the lazy dog".to_string();
65 let result2 = s1.index_of("biggy");
66 assert_eq!(result2, -1);
67 }
68 #[test]
69 fn test_indicies_of(){
70 let s = "the quick brown fox jumps over the lazy dog".to_string();
71 let result = s.indicies_of("the");
73 assert_eq!(result, 2);
74 let s1 = "the quick brown fox jumps over the lazy dog".to_string();
75 let result2 = s1.indicies_of("biggy");
76 assert_eq!(result2, 0);
77 }
78
79 #[test]
80 fn test_trim_end(){
81 let s = "the quick brown fox jumps over the lazy dog ".to_string();
82 let result = s.trim_end(' ');
83 assert_eq!(result, "the quick brown fox jumps over the lazy dog".to_string());
84 }
85 #[test]
86 fn test_trim_start(){
87 let s = " the quick brown fox jumps over the lazy dog".to_string();
88 let result = s.trim_start(' ');
89 assert_eq!(result, "the quick brown fox jumps over the lazy dog".to_string());
90 }
91
92 #[test]
93 fn test_to_upper(){
94 let s = "the quick brown fox jumps over the lazy dog".to_string();
95 let result = s.to_upper();
96 assert_eq!(result, "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG".to_string());
97 }
98 fn test_to_lower(){
99 let s = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG".to_string();
100 let result = s.to_lower();
101 assert_eq!(result, "the quick brown fox jumps over the lazy dog".to_string());
102 }
103}