File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,28 @@ fn println_error(err: &str) {
142142 warn ! ( "{}" , err) ;
143143}
144144
145+ #[ cfg( test) ]
146+ mod tests {
147+ use super :: * ;
148+
149+ #[ test]
150+ fn truncate_short_string ( ) {
151+ assert_eq ! ( truncate( "hello" , 10 ) , "hello" ) ;
152+ }
153+
154+ #[ test]
155+ fn truncate_long_string ( ) {
156+ assert_eq ! ( truncate( "hello world" , 5 ) , "hello..." ) ;
157+ }
158+
159+ #[ test]
160+ fn parse_voice_and_voice_to_str_roundtrip ( ) {
161+ let voice = parse_voice ( "Alloy" ) . expect ( "voice should parse" ) ;
162+ assert_eq ! ( voice_to_str( & voice) , "alloy" ) ;
163+ assert ! ( parse_voice( "doesnotexist" ) . is_none( ) ) ;
164+ }
165+ }
166+
145167/// Creates a temporary file from a byte slice and returns the path to the file.
146168fn create_temp_file_from_bytes ( bytes : & [ u8 ] , extension : & str ) -> NamedTempFile {
147169 let temp_file = Builder :: new ( )
Original file line number Diff line number Diff line change @@ -227,3 +227,31 @@ impl AudibleTimers {
227227 self . audio_stop_tx . send ( ( ) ) . unwrap ( ) ;
228228 }
229229}
230+
231+ #[ cfg( test) ]
232+ mod tests {
233+ use super :: * ;
234+ use tempfile:: tempdir;
235+ use chrono:: { Local , Duration } ;
236+ use std:: env;
237+
238+ #[ test]
239+ fn set_get_delete_timer ( ) {
240+ let tmp = tempdir ( ) . unwrap ( ) ;
241+ env:: set_var ( "XDG_CACHE_HOME" , tmp. path ( ) ) ;
242+ std:: fs:: create_dir_all ( tmp. path ( ) . join ( "quick-assistant" ) ) . unwrap ( ) ;
243+
244+ // Ensure no timers initially
245+ assert ! ( get_timers( ) . is_empty( ) ) ;
246+
247+ let t = Local :: now ( ) + Duration :: seconds ( 1 ) ;
248+ set_timer ( "test" . to_string ( ) , t) . unwrap ( ) ;
249+
250+ let timers = get_timers ( ) ;
251+ assert_eq ! ( timers. len( ) , 1 ) ;
252+ assert_eq ! ( timers[ 0 ] . 1 , "test" ) ;
253+
254+ delete_timer ( timers[ 0 ] . 0 ) . unwrap ( ) ;
255+ assert ! ( get_timers( ) . is_empty( ) ) ;
256+ }
257+ }
You can’t perform that action at this time.
0 commit comments