11use super :: util:: Client ;
22use crate :: io:: { Io , PrintColor } ;
3- use tmc_langs:: Course ;
43
54/// Lists available courses from clients organization
65pub fn list_courses ( io : & mut dyn Io , client : & mut dyn Client ) -> anyhow:: Result < ( ) > {
7- let course_list = client. list_courses ( ) ?;
8- print_courses ( io, & course_list) ?;
9- Ok ( ( ) )
10- }
11-
12- /// Prints course names
13- fn print_courses ( io : & mut dyn Io , course_list : & [ Course ] ) -> anyhow:: Result < ( ) > {
6+ let mut course_list = client. list_courses ( ) ?;
7+ course_list. sort_unstable_by ( |l, r| l. name . cmp ( & r. name ) ) ;
148 io. println ( "" , PrintColor :: Normal ) ?;
159 for course in course_list {
1610 io. println ( & course. name , PrintColor :: Normal ) ?;
@@ -24,7 +18,7 @@ mod tests {
2418 use reqwest:: Url ;
2519 use std:: { path:: Path , slice:: Iter } ;
2620 use tmc_langs:: {
27- ClientError , CourseDetails , CourseExercise , DownloadOrUpdateCourseExercisesResult ,
21+ ClientError , Course , CourseDetails , CourseExercise , DownloadOrUpdateCourseExercisesResult ,
2822 DownloadResult , ExercisesDetails , LangsError , Language , NewSubmission , Organization ,
2923 SubmissionFinished , SubmissionStatus ,
3024 } ;
@@ -205,52 +199,6 @@ mod tests {
205199 mod tests {
206200 use super :: * ;
207201
208- #[ test]
209- fn list_courses_test ( ) {
210- let mut v: Vec < String > = Vec :: new ( ) ;
211- let input = vec ! [ ] ;
212- let mut input = input. iter ( ) ;
213-
214- let mut io = IoTest {
215- list : & mut v,
216- input : & mut input,
217- } ;
218-
219- let courses = [
220- Course {
221- id : 0 ,
222- name : "name" . to_string ( ) ,
223- title : "" . to_string ( ) ,
224- description : None ,
225- details_url : "" . to_string ( ) ,
226- unlock_url : "" . to_string ( ) ,
227- reviews_url : "" . to_string ( ) ,
228- comet_url : "" . to_string ( ) ,
229- spyware_urls : vec ! [ ] ,
230- } ,
231- Course {
232- id : 10 ,
233- name : "course of sorts" . to_string ( ) ,
234- title : "" . to_string ( ) ,
235- description : None ,
236- details_url : "" . to_string ( ) ,
237- unlock_url : "" . to_string ( ) ,
238- reviews_url : "" . to_string ( ) ,
239- comet_url : "" . to_string ( ) ,
240- spyware_urls : vec ! [ ] ,
241- } ,
242- ] ;
243- print_courses ( & mut io, & courses) . unwrap ( ) ;
244-
245- assert ! ( io. list[ 0 ] . eq( "" ) ) ;
246- assert ! ( io. list[ 1 ] . eq( "name" ) , "Expected 'name', got {}" , io. list[ 1 ] ) ;
247- assert ! (
248- io. list[ 2 ] . eq( "course of sorts" ) ,
249- "Expected 'course of sorts', got {}" ,
250- io. list[ 2 ]
251- ) ;
252- }
253-
254202 #[ test]
255203 fn list_courses_with_client_test ( ) {
256204 let mut v: Vec < String > = Vec :: new ( ) ;
0 commit comments