@@ -414,3 +414,86 @@ import Testing
414414 dict [ . string( " key " ) ] = " value "
415415 #expect( dict [ . string( " key " ) ] == " value " )
416416}
417+
418+ @Test func testJSONValueIsCompatible( ) {
419+ // Test object compatibility
420+ let objectValue : JSONValue = . object( [ " key " : . string( " value " ) ] )
421+ #expect( objectValue. isCompatible ( with: . object) )
422+ #expect( !objectValue. isCompatible ( with: . array) )
423+ #expect( !objectValue. isCompatible ( with: . string) )
424+ #expect( !objectValue. isCompatible ( with: . number) )
425+ #expect( !objectValue. isCompatible ( with: . integer) )
426+ #expect( !objectValue. isCompatible ( with: . boolean) )
427+ #expect( !objectValue. isCompatible ( with: . null) )
428+
429+ // Test array compatibility
430+ let arrayValue : JSONValue = . array( [ . int( 1 ) , . string( " test " ) ] )
431+ #expect( !arrayValue. isCompatible ( with: . object) )
432+ #expect( arrayValue. isCompatible ( with: . array) )
433+ #expect( !arrayValue. isCompatible ( with: . string) )
434+ #expect( !arrayValue. isCompatible ( with: . number) )
435+ #expect( !arrayValue. isCompatible ( with: . integer) )
436+ #expect( !arrayValue. isCompatible ( with: . boolean) )
437+ #expect( !arrayValue. isCompatible ( with: . null) )
438+
439+ // Test string compatibility
440+ let stringValue : JSONValue = . string( " test " )
441+ #expect( !stringValue. isCompatible ( with: . object) )
442+ #expect( !stringValue. isCompatible ( with: . array) )
443+ #expect( stringValue. isCompatible ( with: . string) )
444+ #expect( !stringValue. isCompatible ( with: . number) )
445+ #expect( !stringValue. isCompatible ( with: . integer) )
446+ #expect( !stringValue. isCompatible ( with: . boolean) )
447+ #expect( !stringValue. isCompatible ( with: . null) )
448+
449+ // Test number compatibility
450+ let doubleValue : JSONValue = . double( 3.14 )
451+ #expect( !doubleValue. isCompatible ( with: . object) )
452+ #expect( !doubleValue. isCompatible ( with: . array) )
453+ #expect( !doubleValue. isCompatible ( with: . string) )
454+ #expect( doubleValue. isCompatible ( with: . number) )
455+ #expect( !doubleValue. isCompatible ( with: . integer) )
456+ #expect( !doubleValue. isCompatible ( with: . boolean) )
457+ #expect( !doubleValue. isCompatible ( with: . null) )
458+
459+ // Test integer compatibility
460+ let intValue : JSONValue = . int( 42 )
461+ #expect( !intValue. isCompatible ( with: . object) )
462+ #expect( !intValue. isCompatible ( with: . array) )
463+ #expect( !intValue. isCompatible ( with: . string) )
464+ #expect( intValue. isCompatible ( with: . number, strict: false ) )
465+ #expect( !intValue. isCompatible ( with: . number, strict: true ) )
466+ #expect( intValue. isCompatible ( with: . integer) )
467+ #expect( !intValue. isCompatible ( with: . boolean) )
468+ #expect( !intValue. isCompatible ( with: . null) )
469+
470+ // Test boolean compatibility
471+ let boolValue : JSONValue = . bool( true )
472+ #expect( !boolValue. isCompatible ( with: . object) )
473+ #expect( !boolValue. isCompatible ( with: . array) )
474+ #expect( !boolValue. isCompatible ( with: . string) )
475+ #expect( !boolValue. isCompatible ( with: . number) )
476+ #expect( !boolValue. isCompatible ( with: . integer) )
477+ #expect( boolValue. isCompatible ( with: . boolean) )
478+ #expect( !boolValue. isCompatible ( with: . null) )
479+
480+ // Test null compatibility
481+ let nullValue : JSONValue = . null
482+ #expect( !nullValue. isCompatible ( with: . object) )
483+ #expect( !nullValue. isCompatible ( with: . array) )
484+ #expect( !nullValue. isCompatible ( with: . string) )
485+ #expect( !nullValue. isCompatible ( with: . number) )
486+ #expect( !nullValue. isCompatible ( with: . integer) )
487+ #expect( !nullValue. isCompatible ( with: . boolean) )
488+ #expect( nullValue. isCompatible ( with: . null) )
489+
490+ // Test composite schema types (should always return true)
491+ let anyValue : JSONValue = . string( " any " )
492+ #expect( anyValue. isCompatible ( with: . reference( " $ref " ) ) )
493+ #expect( anyValue. isCompatible ( with: . anyOf( [ ] ) ) )
494+ #expect( anyValue. isCompatible ( with: . allOf( [ ] ) ) )
495+ #expect( anyValue. isCompatible ( with: . oneOf( [ ] ) ) )
496+ #expect( anyValue. isCompatible ( with: . not( . string) ) )
497+ #expect( anyValue. isCompatible ( with: . empty) )
498+ #expect( anyValue. isCompatible ( with: . any) )
499+ }
0 commit comments