@@ -6,6 +6,7 @@ use crate::types::{
66#[ derive( Clone , Debug , Default ) ]
77pub struct ListBuilder {
88 items : Vec < ListItem > ,
9+ has_checkmarks : bool ,
910}
1011
1112impl ListBuilder {
@@ -18,17 +19,30 @@ impl ListBuilder {
1819 self
1920 }
2021
21- /// Adds a checkmark using checkmark::CheckmarkItem.
22+ /// Adds a checkmark using [ checkmark::CheckmarkItem] .
2223 pub fn checkmark ( mut self , item : impl Into < String > , checked : bool ) -> Self {
2324 self . items . push ( CheckmarkItem :: from ( item, checked) . into ( ) ) ;
25+ self . has_checkmarks = true ;
2426 self
2527 }
2628
2729 pub fn ordered ( self ) -> List {
30+ if self . items . is_empty ( ) {
31+ panic ! ( "Attempt to bulid list without contents" ) ;
32+ }
33+
34+ if self . has_checkmarks {
35+ panic ! ( "Attempt to build ordered list with checkboxes" )
36+ }
37+
2838 List :: ordered_with ( self . items )
2939 }
3040
3141 pub fn unordered ( self ) -> List {
42+ if self . items . is_empty ( ) {
43+ panic ! ( "Attempt to bulid list without contents" ) ;
44+ }
45+
3246 List :: unordered_with ( self . items )
3347 }
3448}
@@ -77,4 +91,25 @@ mod tests {
7791 "- [x] Eat spaghetti\n - [ ] Eat pizza\n - [x] Eat kebab\n "
7892 ) ;
7993 }
94+
95+ #[ test]
96+ #[ should_panic]
97+ fn test_list_builder_unordered_no_elements_panic ( ) {
98+ List :: builder ( ) . unordered ( ) ;
99+ }
100+
101+ #[ test]
102+ #[ should_panic]
103+ fn test_list_builder_ordered_no_elements_panic ( ) {
104+ List :: builder ( ) . ordered ( ) ;
105+ }
106+
107+ #[ test]
108+ #[ should_panic]
109+ fn test_list_builder_ordered_checkmark_panic ( ) {
110+ List :: builder ( )
111+ . checkmark ( "Hello world" , false )
112+ . checkmark ( "Checked" , true )
113+ . ordered ( ) ;
114+ }
80115}
0 commit comments