@@ -372,3 +372,98 @@ impl ClassBuilder {
372372 Ok ( ( ) )
373373 }
374374}
375+
376+ #[ cfg( test) ]
377+ mod tests {
378+ use crate :: test:: test_function;
379+
380+ use super :: * ;
381+
382+ #[ test]
383+ fn test_new ( ) {
384+ let class = ClassBuilder :: new ( "Foo" ) ;
385+ assert_eq ! ( class. name, "Foo" ) ;
386+ assert_eq ! ( class. extends, None ) ;
387+ assert_eq ! ( class. interfaces, vec![ ] ) ;
388+ assert_eq ! ( class. methods. len( ) , 0 ) ;
389+ assert_eq ! ( class. object_override, None ) ;
390+ assert_eq ! ( class. properties, vec![ ] ) ;
391+ assert_eq ! ( class. constants. len( ) , 0 ) ;
392+ assert_eq ! ( class. register, None ) ;
393+ assert_eq ! ( class. docs, & [ ] as DocComments ) ;
394+ }
395+
396+ #[ test]
397+ fn test_extends ( ) {
398+ let extends: ClassEntryInfo = ( || todo ! ( ) , "Bar" ) ;
399+ let class = ClassBuilder :: new ( "Foo" ) . extends ( extends) ;
400+ assert_eq ! ( class. extends, Some ( extends) ) ;
401+ }
402+
403+ #[ test]
404+ fn test_implements ( ) {
405+ let implements: ClassEntryInfo = ( || todo ! ( ) , "Bar" ) ;
406+ let class = ClassBuilder :: new ( "Foo" ) . implements ( implements) ;
407+ assert_eq ! ( class. interfaces, vec![ implements] ) ;
408+ }
409+
410+ #[ test]
411+ fn test_method ( ) {
412+ let method = FunctionBuilder :: new ( "foo" , test_function) ;
413+ let class = ClassBuilder :: new ( "Foo" ) . method ( method, MethodFlags :: Public ) ;
414+ assert_eq ! ( class. methods. len( ) , 1 ) ;
415+ }
416+
417+ #[ test]
418+ fn test_property ( ) {
419+ let class = ClassBuilder :: new ( "Foo" ) . property ( "bar" , PropertyFlags :: Public , & [ "Doc 1" ] ) ;
420+ assert_eq ! (
421+ class. properties,
422+ vec![ (
423+ "bar" . to_string( ) ,
424+ PropertyFlags :: Public ,
425+ & [ "Doc 1" ] as DocComments
426+ ) ]
427+ ) ;
428+ }
429+
430+ #[ test]
431+ fn test_constant ( ) {
432+ let class = ClassBuilder :: new ( "Foo" )
433+ . constant ( "bar" , 42 , & [ "Doc 1" ] )
434+ . expect ( "Failed to create constant" ) ;
435+ assert_eq ! ( class. constants. len( ) , 1 ) ;
436+ assert_eq ! ( class. constants[ 0 ] . 0 , "bar" ) ;
437+ assert_eq ! ( class. constants[ 0 ] . 2 , & [ "Doc 1" ] as DocComments ) ;
438+ }
439+
440+ #[ test]
441+ fn test_dyn_constant ( ) {
442+ let class = ClassBuilder :: new ( "Foo" )
443+ . dyn_constant ( "bar" , & 42 , & [ "Doc 1" ] )
444+ . expect ( "Failed to create constant" ) ;
445+ assert_eq ! ( class. constants. len( ) , 1 ) ;
446+ assert_eq ! ( class. constants[ 0 ] . 0 , "bar" ) ;
447+ assert_eq ! ( class. constants[ 0 ] . 2 , & [ "Doc 1" ] as DocComments ) ;
448+ }
449+
450+ #[ test]
451+ fn test_flags ( ) {
452+ let class = ClassBuilder :: new ( "Foo" ) . flags ( ClassFlags :: Abstract ) ;
453+ assert_eq ! ( class. ce. ce_flags, ClassFlags :: Abstract . bits( ) ) ;
454+ }
455+
456+ #[ test]
457+ fn test_registration ( ) {
458+ let class = ClassBuilder :: new ( "Foo" ) . registration ( |_| { } ) ;
459+ assert ! ( class. register. is_some( ) ) ;
460+ }
461+
462+ #[ test]
463+ fn test_docs ( ) {
464+ let class = ClassBuilder :: new ( "Foo" ) . docs ( & [ "Doc 1" ] ) ;
465+ assert_eq ! ( class. docs, & [ "Doc 1" ] as DocComments ) ;
466+ }
467+
468+ // TODO: Test the register function
469+ }
0 commit comments