···11+#!/usr/bin/env ruby
22+# frozen_string_literal: true
33+44+# NOTE: This is not a quickdraw test becuase it needs to be run in a single thread.
55+66+require "literal"
77+include Literal::Types
88+99+def count_allocations
1010+ x = GC.stat(:total_allocated_objects)
1111+ yield
1212+ GC.stat(:total_allocated_objects) - x
1313+end
1414+1515+def count_warm_allocations(&)
1616+ count_allocations(&)
1717+ count_allocations(&)
1818+end
1919+2020+def no_allocations(type, thing)
2121+ count_warm_allocations do
2222+ type === thing
2323+ end => 0
2424+end
2525+2626+no_allocations(_Any, "anything")
2727+no_allocations(_Any, false)
2828+2929+no_allocations(_Array(String), [])
3030+no_allocations(_Array(String), ["a", "b"])
3131+no_allocations(_Array(String), ["a", "b", 1])
3232+3333+no_allocations(_Boolean, true)
3434+no_allocations(_Boolean, false)
3535+no_allocations(_Boolean, nil)
3636+no_allocations(_Boolean, 1)