@@ -526,3 +526,64 @@ func TestExtractJSONPathFromStringLocation(t *testing.T) {
526526 })
527527 }
528528}
529+
530+ func TestConvertStringLocationToPathSegments (t * testing.T ) {
531+ testCases := []struct {
532+ name string
533+ instancePath string
534+ expected []string
535+ }{
536+ {
537+ name : "Empty string" ,
538+ instancePath : "" ,
539+ expected : []string {},
540+ },
541+ {
542+ name : "Root path only" ,
543+ instancePath : "/" ,
544+ expected : []string {},
545+ },
546+ {
547+ name : "Single field" ,
548+ instancePath : "/name" ,
549+ expected : []string {"name" },
550+ },
551+ {
552+ name : "Multiple fields" ,
553+ instancePath : "/user/profile/email" ,
554+ expected : []string {"user" , "profile" , "email" },
555+ },
556+ {
557+ name : "Array index" ,
558+ instancePath : "/users/0/name" ,
559+ expected : []string {"users" , "0" , "name" },
560+ },
561+ {
562+ name : "Multiple array indices" ,
563+ instancePath : "/matrix/0/1/value" ,
564+ expected : []string {"matrix" , "0" , "1" , "value" },
565+ },
566+ {
567+ name : "Field with special characters" ,
568+ instancePath : "/user/email-address" ,
569+ expected : []string {"user" , "email-address" },
570+ },
571+ {
572+ name : "Complex nested path" ,
573+ instancePath : "/data/items/1/properties/field-name" ,
574+ expected : []string {"data" , "items" , "1" , "properties" , "field-name" },
575+ },
576+ {
577+ name : "Leading and trailing slashes" ,
578+ instancePath : "///user/name///" ,
579+ expected : []string {"user" , "name" },
580+ },
581+ }
582+
583+ for _ , tc := range testCases {
584+ t .Run (tc .name , func (t * testing.T ) {
585+ result := ConvertStringLocationToPathSegments (tc .instancePath )
586+ assert .Equal (t , tc .expected , result )
587+ })
588+ }
589+ }
0 commit comments