Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

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

Support constrained JSON data

+11 -2
+6 -2
lib/literal/types.rb
··· 258 258 end 259 259 260 260 # Ensures the value is valid JSON data (i.e. it came from JSON.parse). 261 - def _JSONData 262 - JSONDataType::Instance 261 + def _JSONData(*a, **k) 262 + if a.length > 0 || k.length > 0 263 + _Constraint(JSONDataType::Instance, *a, **k) 264 + else 265 + JSONDataType::Instance 266 + end 263 267 end 264 268 265 269 # Nilable version of `_JSONData`
+5
test/types/_json_data.test.rb
··· 25 25 refute _JSONData === [{ "key" => :value }, [1, 2, 3], "string"] 26 26 end 27 27 28 + test "with params" do 29 + assert _JSONData(Array) === [1, 2, 3] 30 + refute _JSONData(Array) === ["a", 1, 2] 31 + end 32 + 28 33 test "hierarchy" do 29 34 assert_subtype _JSONData, _JSONData 30 35