@@ -66,3 +66,69 @@ def test_array_invalid_value(self, value, caster_factory):
6666 CastError, match=f"Failed to cast value to array type: {value}"
6767 ):
6868 caster_factory(schema).cast(value)
69+
70+ @pytest.mark.parametrize(
71+ "composite_type,schema_type,value,expected",
72+ [
73+ ("allOf", "integer", "2", 2),
74+ ("anyOf", "number", "3.14", 3.14),
75+ ("oneOf", "boolean", "false", False),
76+ ("oneOf", "boolean", "true", True),
77+ ],
78+ )
79+ def test_composite_primitive(
80+ self, caster_factory, composite_type, schema_type, value, expected
81+ ):
82+ spec = {
83+ composite_type: [{"type": schema_type}],
84+ }
85+ schema = SchemaPath.from_dict(spec)
86+
87+ result = caster_factory(schema).cast(value)
88+
89+ 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