Sha256: 4982a2da66ad84fb90996ea80f733633039f6e5d6815b217e88257306677e740
Contents?: true
Size: 973 Bytes
Versions: 1
Compression:
Stored size: 973 Bytes
Contents
# frozen_string_literal: true module Speculation # @private class NilableSpec < Spec include NamespacedSymbols S = Speculation def initialize(pred) @pred = pred @delayed_spec = Concurrent::Delay.new { S.send(:specize, pred) } end def conform(value) value.nil? ? value : @delayed_spec.value!.conform(value) end def explain(path, via, inn, value) return if S.pvalid?(@delayed_spec.value!, value) || value.nil? Utils.conj( S.explain1(@pred, Utils.conj(path, ns(S, :pred)), via, inn, value), :path => Utils.conj(path, ns(S, :nil)), :pred => [NilClass, [value]], :val => value, :via => via, :in => inn ) end def gen(overrides, path, rmap) return @gen if @gen ->(rantly) do rantly.freq([1, Gen.delay { Utils.constantly(nil) }], [9, Gen.delay { S.gensub(@pred, overrides, Utils.conj(path, ns(S, :pred)), rmap) }]) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
speculation-0.3.0 | lib/speculation/spec/nilable_spec.rb |