@@ -87,3 +87,48 @@ def test_composite_primitive(
8787 result = caster_factory (schema ).cast (value )
8888
8989 assert result == expected
90+
91+ @pytest .mark .parametrize (
92+ "schemas,value,expected" ,
93+ [
94+ # If string is evaluated first, it succeeds and returns string
95+ ([{"type" : "string" }, {"type" : "integer" }], "123" , "123" ),
96+ # If integer is evaluated first, it succeeds and returns int
97+ ([{"type" : "integer" }, {"type" : "string" }], "123" , 123 ),
98+ ],
99+ )
100+ def test_oneof_greedy_casting_edge_case (
101+ self , caster_factory , schemas , value , expected
102+ ):
103+ """
104+ Documents the edge case that AnyCaster's oneOf/anyOf logic is greedy.
105+ It returns the first successfully casted value based on the order in the list.
106+ """
107+ spec = {
108+ "oneOf" : schemas ,
109+ }
110+ schema = SchemaPath .from_dict (spec )
111+
112+ result = caster_factory (schema ).cast (value )
113+
114+ assert result == expected
115+ # Ensure exact type matches to prevent 123 == "123" test bypass issues
116+ assert type (result ) is type (expected )
117+
118+ def test_allof_sequential_mutation_edge_case (self , caster_factory ):
119+ """
120+ Documents the edge case that AnyCaster's allOf logic sequentially mutates the value.
121+ The first schema casts "2" to an int (2). The second schema (number)
122+ receives the int 2, casts it to float (2.0), and returns the float.
123+ """
124+ spec = {
125+ "allOf" : [{"type" : "integer" }, {"type" : "number" }],
126+ }
127+ schema = SchemaPath .from_dict (spec )
128+ value = "2"
129+
130+ result = caster_factory (schema ).cast (value )
131+
132+ # "2" -> int(2) -> float(2.0)
133+ assert result == 2.0
134+ assert type (result ) is float
0 commit comments