Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Support constraints as subtypes of their parameters

+21
+2
lib/literal.rb
··· 117 117 ::Array >= supertype 118 118 when ::Hash 119 119 ::Hash >= supertype 120 + when Literal::Type 121 + subtype <= supertype 120 122 else 121 123 false 122 124 end
+9
lib/literal/type.rb
··· 4 4 def >=(other) 5 5 self == other 6 6 end 7 + 8 + def <=(other) 9 + case other 10 + when Literal::Type 11 + other >= self 12 + else 13 + false 14 + end 15 + end 7 16 end
+7
lib/literal/types/constraint_type.rb
··· 69 69 end 70 70 end 71 71 72 + def <=(other) 73 + case other 74 + when Module 75 + @object_constraints.any? { |constraint| Literal.subtype?(other, constraint) } 76 + end 77 + end 78 + 72 79 def record_literal_type_errors(context) 73 80 @object_constraints.each do |constraint| 74 81 next if constraint === context.actual
+3
test/types/_constraint.test.rb
··· 21 21 22 22 refute_subtype _Constraint(Array, size: 1..3), _Constraint(Array, size: 1..2) 23 23 refute_subtype _Constraint(String, size: 1), _Constraint(String, size: 4) 24 + 25 + assert_subtype _Constraint(Integer, 1..), Integer 26 + refute_subtype _Constraint(Integer, 1..), Float 24 27 end 25 28 26 29 test "error message with object constraints" do