|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+extern crate task2;
|
|
|
2
|
+use task2::Config;
|
|
|
3
|
+
|
|
|
4
|
+
|
|
|
5
|
+#[test]
|
|
|
6
|
+fn test_parse_config_1() {
|
|
|
7
|
+ let a = vec!["Not interested".to_string(), "e".to_string(), "Numero Due".to_string()];
|
|
|
8
|
+ let c = Config {
|
|
|
9
|
+ search: 'e',
|
|
|
10
|
+ line: "Numero Due".to_string(),
|
|
|
11
|
+ };
|
|
|
12
|
+ assert_eq!(Config::new(&a), Ok(c));
|
|
|
13
|
+}
|
|
|
14
|
+
|
|
|
15
|
+#[test]
|
|
|
16
|
+#[should_panic]
|
|
|
17
|
+fn test_parse_config_2() {
|
|
|
18
|
+ let a = vec!["Not interested".to_string(), "x".to_string(), "Numero Due".to_string()];
|
|
|
19
|
+ let c = Config {
|
|
|
20
|
+ search: 'e',
|
|
|
21
|
+ line: "Numero Due".to_string(),
|
|
|
22
|
+ };
|
|
|
23
|
+ assert_eq!(Config::new(&a), Ok(c));
|
|
|
24
|
+}
|
|
|
25
|
+
|
|
|
26
|
+#[test]
|
|
|
27
|
+fn test_parse_config_3() {
|
|
|
28
|
+ let a = vec!["Not interested".to_string(), "0".to_string(), "0".to_string()];
|
|
|
29
|
+ let c = Config {
|
|
|
30
|
+ search: '0',
|
|
|
31
|
+ line: "0".to_string(),
|
|
|
32
|
+ };
|
|
|
33
|
+ assert_eq!(Config::new(&a), Ok(c));
|
|
|
34
|
+}
|
|
|
35
|
+
|
|
|
36
|
+#[test]
|
|
|
37
|
+fn test_parse_config_err_1() {
|
|
|
38
|
+ let a = vec!["Not interested".to_string(), "e".to_string()];
|
|
|
39
|
+ assert_eq!(Config::new(&a), Err("not enough arguments"));
|
|
|
40
|
+}
|
|
|
41
|
+
|
|
|
42
|
+#[test]
|
|
|
43
|
+fn test_parse_config_err_2() {
|
|
|
44
|
+ let a = vec!["Not interested".to_string()];
|
|
|
45
|
+ assert_eq!(Config::new(&a), Err("not enough arguments"));
|
|
|
46
|
+}
|
|
|
47
|
+
|
|
|
48
|
+#[test]
|
|
|
49
|
+fn test_run_1() {
|
|
|
50
|
+ let c = Config {
|
|
|
51
|
+ search: 'e',
|
|
|
52
|
+ line: "Numero Due".to_string(),
|
|
|
53
|
+ };
|
|
|
54
|
+ assert_eq!(task2::run(&c), 2);
|
|
|
55
|
+}
|
|
|
56
|
+
|
|
|
57
|
+#[test]
|
|
|
58
|
+fn test_run_2() {
|
|
|
59
|
+ let c = Config {
|
|
|
60
|
+ search: '♥',
|
|
|
61
|
+ line: "♥ The quick brown fox jumps over the lazy dog. ♥".to_string(),
|
|
|
62
|
+ };
|
|
|
63
|
+ assert_eq!(task2::run(&c), 2);
|
|
|
64
|
+}
|
|
|
65
|
+
|
|
|
66
|
+#[test]
|
|
|
67
|
+#[should_panic]
|
|
|
68
|
+fn test_run_3() {
|
|
|
69
|
+ let c = Config {
|
|
|
70
|
+ search: 'q',
|
|
|
71
|
+ line: "♥ The quick brown fox jumps over the lazy dog. ♥".to_string(),
|
|
|
72
|
+ };
|
|
|
73
|
+ assert_eq!(task2::run(&c), 2);
|
|
|
74
|
+}
|
|
|
75
|
+
|
|
|
76
|
+#[test]
|
|
|
77
|
+fn test_run_4() {
|
|
|
78
|
+ let c = Config {
|
|
|
79
|
+ search: '!',
|
|
|
80
|
+ line: "♥ The quick brown fox jumps over the lazy dog. ♥".to_string(),
|
|
|
81
|
+ };
|
|
|
82
|
+ assert_eq!(task2::run(&c), 0);
|
|
|
83
|
+}
|