@@ -351,10 +351,11 @@ pub(super) fn render_model(
351351 for c in & table. constraints {
352352 if let TableConstraint :: Index { name, columns } = c {
353353 let cols = columns. join ( ", " ) ;
354- if let Some ( n) = name {
355- lines. push ( format ! ( " @@index([{cols}], map: \" {n}\" )" ) ) ;
356- } else {
357- lines. push ( format ! ( " @@index([{cols}])" ) ) ;
354+ // `match` instead of `if let Some`: LLVM coverage attributes match
355+ // arms reliably where this if/else was misattributed as uncovered.
356+ match name {
357+ Some ( n) => lines. push ( format ! ( " @@index([{cols}], map: \" {n}\" )" ) ) ,
358+ None => lines. push ( format ! ( " @@index([{cols}])" ) ) ,
358359 }
359360 }
360361 }
@@ -467,10 +468,65 @@ fn infer_relation_field_name(fk_col: &str) -> String {
467468#[ cfg( test) ]
468469mod tests {
469470 use rstest:: rstest;
470- use vespertide_core:: schema:: column:: SimpleColumnType ;
471+ use vespertide_core:: schema:: column:: { NumValue , SimpleColumnType } ;
471472
472473 use super :: * ;
473474
475+ #[ rstest]
476+ #[ case:: cascade( ReferenceAction :: Cascade , "Cascade" ) ]
477+ #[ case:: restrict( ReferenceAction :: Restrict , "Restrict" ) ]
478+ #[ case:: set_null( ReferenceAction :: SetNull , "SetNull" ) ]
479+ #[ case:: set_default( ReferenceAction :: SetDefault , "SetDefault" ) ]
480+ #[ case:: no_action( ReferenceAction :: NoAction , "NoAction" ) ]
481+ fn reference_actions_map_to_prisma ( #[ case] action : ReferenceAction , #[ case] expected : & str ) {
482+ assert_eq ! ( reference_action_to_prisma( & action) , expected) ;
483+ }
484+
485+ #[ test]
486+ fn integer_enum_default_resolves_numeric_value_to_variant_name ( ) {
487+ let ty = ColumnType :: Complex ( ComplexColumnType :: Enum {
488+ name : "priority" . into ( ) ,
489+ values : EnumValues :: Integer ( vec ! [
490+ NumValue {
491+ name: "low" . into( ) ,
492+ value: 100 ,
493+ } ,
494+ NumValue {
495+ name: "high" . into( ) ,
496+ value: 200 ,
497+ } ,
498+ ] ) ,
499+ } ) ;
500+ assert_eq ! (
501+ prisma_default_attr( "100" , & ty, PrismaProvider :: Postgres ) ,
502+ "@default(LOW)"
503+ ) ;
504+ }
505+
506+ #[ test]
507+ fn fk_on_update_action_is_rendered ( ) {
508+ let mut table = crate :: tests:: fixtures:: table_with_fk ( ) ;
509+ for c in & mut table. constraints {
510+ if let TableConstraint :: ForeignKey { on_update, .. } = c {
511+ * on_update = Some ( ReferenceAction :: Cascade ) ;
512+ }
513+ }
514+ let rendered = render_model (
515+ & table,
516+ std:: slice:: from_ref ( & table) ,
517+ PrismaProvider :: default ( ) ,
518+ ) ;
519+ assert ! ( rendered. contains( "onUpdate: Cascade" ) ) ;
520+ }
521+
522+ #[ test]
523+ fn named_index_is_rendered_with_map ( ) {
524+ let table = crate :: tests:: fixtures:: table_with_indexes ( ) ;
525+ let rendered = render_model ( & table, & [ ] , PrismaProvider :: default ( ) ) ;
526+ assert ! ( rendered. contains( "@@index([created_at], map: \" idx_articles_created_at\" )" ) ) ;
527+ assert ! ( rendered. contains( "@@index([title])" ) ) ;
528+ }
529+
474530 #[ rstest]
475531 #[ case:: postgres( PrismaProvider :: Postgres , "@default(uuid())" ) ]
476532 #[ case:: mysql( PrismaProvider :: MySql , "@default(dbgenerated(\" (uuid())\" ))" ) ]
0 commit comments