@@ -855,6 +855,88 @@ Ontology(
855855 assert ! ( has_label_comment) ;
856856 }
857857
858+ // ── set_ontology_iri ──────────────────────────────────────────────────────
859+
860+ #[ test]
861+ fn set_ontology_iri_on_empty_ontology ( ) {
862+ let f = empty_ofn ( ) ;
863+ let mut api = OwlApi :: load ( f. path ( ) , false , false ) . unwrap ( ) ;
864+ let msg = api
865+ . set_ontology_iri ( Some ( "http://example.org/my-onto" ) , None )
866+ . unwrap ( ) ;
867+ assert ! ( msg. contains( "IRI set to" ) ) ;
868+ let meta = api. ontology_metadata ( ) ;
869+ let joined = meta. join ( " " ) ;
870+ assert ! ( joined. contains( "http://example.org/my-onto" ) ) ;
871+ }
872+
873+ #[ test]
874+ fn set_ontology_iri_with_version ( ) {
875+ let f = empty_ofn ( ) ;
876+ let mut api = OwlApi :: load ( f. path ( ) , false , false ) . unwrap ( ) ;
877+ let msg = api
878+ . set_ontology_iri (
879+ Some ( "http://example.org/onto" ) ,
880+ Some ( "http://example.org/onto/1.0" ) ,
881+ )
882+ . unwrap ( ) ;
883+ assert ! ( msg. contains( "IRI set to" ) ) ;
884+ assert ! ( msg. contains( "version IRI set to" ) ) ;
885+ let meta = api. ontology_metadata ( ) ;
886+ let joined = meta. join ( " " ) ;
887+ assert ! ( joined. contains( "http://example.org/onto" ) ) ;
888+ assert ! ( joined. contains( "http://example.org/onto/1.0" ) ) ;
889+ }
890+
891+ #[ test]
892+ fn set_ontology_iri_replaces_existing ( ) {
893+ let content = "Ontology(<http://old.example.org/onto>)\n " ;
894+ let f = ofn_with_content ( content) ;
895+ let mut api = OwlApi :: load ( f. path ( ) , false , false ) . unwrap ( ) ;
896+ let meta_before = api. ontology_metadata ( ) ;
897+ assert ! ( meta_before. iter( ) . any( |s| s. contains( "old.example.org" ) ) ) ;
898+
899+ api. set_ontology_iri ( Some ( "http://new.example.org/onto" ) , None )
900+ . unwrap ( ) ;
901+ let meta_after = api. ontology_metadata ( ) ;
902+ assert ! ( !meta_after. iter( ) . any( |s| s. contains( "old.example.org" ) ) ) ;
903+ assert ! ( meta_after. iter( ) . any( |s| s. contains( "new.example.org" ) ) ) ;
904+ }
905+
906+ #[ test]
907+ fn set_ontology_iri_persists_across_reload ( ) {
908+ let f = empty_ofn ( ) ;
909+ {
910+ let mut api = OwlApi :: load ( f. path ( ) , false , false ) . unwrap ( ) ;
911+ api. set_ontology_iri ( Some ( "http://example.org/persisted" ) , None )
912+ . unwrap ( ) ;
913+ }
914+ let api2 = OwlApi :: load ( f. path ( ) , false , false ) . unwrap ( ) ;
915+ let meta = api2. ontology_metadata ( ) ;
916+ assert ! ( meta
917+ . iter( )
918+ . any( |s| s. contains( "http://example.org/persisted" ) ) ) ;
919+ }
920+
921+ #[ test]
922+ fn set_ontology_iri_clear ( ) {
923+ let content = "Ontology(<http://example.org/will-clear>)\n " ;
924+ let f = ofn_with_content ( content) ;
925+ let mut api = OwlApi :: load ( f. path ( ) , false , false ) . unwrap ( ) ;
926+ let msg = api. set_ontology_iri ( None , None ) . unwrap ( ) ;
927+ assert ! ( msg. contains( "cleared" ) ) ;
928+ let meta = api. ontology_metadata ( ) ;
929+ assert ! ( !meta. iter( ) . any( |s| s. contains( "will-clear" ) ) ) ;
930+ }
931+
932+ #[ test]
933+ fn set_ontology_iri_readonly_returns_error ( ) {
934+ let f = empty_ofn ( ) ;
935+ let mut api = OwlApi :: load ( f. path ( ) , true , false ) . unwrap ( ) ;
936+ let result = api. set_ontology_iri ( Some ( "http://example.org/x" ) , None ) ;
937+ assert ! ( matches!( result, Err ( OwlApiError :: ReadOnly ) ) ) ;
938+ }
939+
858940 // ── expand_curie ─────────────────────────────────────────────────────────
859941
860942 #[ test]
0 commit comments