File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1572,6 +1572,37 @@ struct EncoderTests {
15721572 #expect( result == expected)
15731573 }
15741574
1575+ @Test func recursionLimitTriggersOnDeepEncoding( ) async throws {
1576+ indirect enum NestableValue : Codable , Equatable {
1577+ case int( Int )
1578+ case array( [ NestableValue ] )
1579+ }
1580+
1581+ struct Container : Codable , Equatable {
1582+ let value : NestableValue
1583+ }
1584+
1585+ func makeDeepNest( depth: Int ) -> NestableValue {
1586+ var value : NestableValue = . int( 1 )
1587+ for _ in 0 ..< depth {
1588+ value = . array( [ value] )
1589+ }
1590+ return value
1591+ }
1592+
1593+ let encoder = TOONEncoder ( )
1594+ encoder. recursionLimit = 10
1595+
1596+ do {
1597+ _ = try encoder. encode ( Container ( value: makeDeepNest ( depth: 20 ) ) )
1598+ #expect( Bool ( false ) )
1599+ } catch EncodingError . invalidValue( _, let context) {
1600+ #expect( context. debugDescription. contains ( " Recursion limit " ) )
1601+ } catch {
1602+ #expect( Bool ( false ) )
1603+ }
1604+ }
1605+
15751606 // MARK: - Collision Avoidance Tests (TOON 3.0)
15761607
15771608 @Test func keyFoldingCollisionAvoidance( ) async throws {
You can’t perform that action at this time.
0 commit comments