@@ -2,11 +2,11 @@ use serde::Deserialize;
2
2
use std:: { error, fs, path:: Path } ;
3
3
use toml:: { self } ;
4
4
5
- #[ derive( Clone , Deserialize , Debug ) ]
5
+ #[ derive( Clone , Deserialize , Debug , Default ) ]
6
6
pub struct Config {
7
7
pub theme : Option < Theme > ,
8
8
pub core : Option < Core > ,
9
- pub info : Info ,
9
+ pub info : Option < Info > ,
10
10
}
11
11
12
12
#[ derive( Clone , Deserialize , Debug ) ]
@@ -83,6 +83,17 @@ impl Default for Theme {
83
83
}
84
84
}
85
85
86
+ impl Default for Info {
87
+ fn default ( ) -> Self {
88
+ Self {
89
+ name : "Unknown" . to_owned ( ) ,
90
+ input_method : "Unknow" . to_owned ( ) ,
91
+ homepage : "Unknow" . to_owned ( ) ,
92
+ maintainors : vec ! [ "Unknow" . to_owned( ) ] ,
93
+ }
94
+ }
95
+ }
96
+
86
97
impl Config {
87
98
pub fn from_file ( filepath : & Path ) -> Result < Self , Box < dyn error:: Error > > {
88
99
let content = fs:: read_to_string ( filepath) ?;
@@ -99,18 +110,19 @@ mod tests {
99
110
use crate :: config:: Config ;
100
111
use std:: path:: Path ;
101
112
102
- let config = Config :: from_file ( Path :: new ( "./data/sample .toml" ) ) ;
113
+ let config = Config :: from_file ( Path :: new ( "./data/blank_sample .toml" ) ) ;
103
114
assert ! ( config. is_ok( ) ) ;
104
115
105
116
// Load default core and theme.
106
117
let config = config. unwrap ( ) ;
107
118
config. core . unwrap_or_default ( ) ;
108
119
config. theme . unwrap_or_default ( ) ;
120
+ config. info . unwrap_or_default ( ) ;
109
121
110
122
let config = Config :: from_file ( Path :: new ( "./data/full_sample.toml" ) ) ;
111
123
assert ! ( config. is_ok( ) ) ;
112
124
113
- let config = Config :: from_file ( Path :: new ( "./data/blank_sample .toml" ) ) ;
114
- assert ! ( config. is_err ( ) ) ;
125
+ let config = Config :: from_file ( Path :: new ( "./data/sample .toml" ) ) ;
126
+ assert ! ( config. is_ok ( ) ) ;
115
127
}
116
128
}
0 commit comments