defmodule VavPipeline.SugyaVerdictTest do @moduledoc "The sugya on a verdict (sugya.md §IV, step 3): applied is read from the record, never guessed." use ExUnit.Case, async: true alias VavPipeline.Sugya defp result(overrides) do Map.merge(%{verdict: :tov, violations: [], checks: %{}, examination: %{"claims" => []}}, overrides) end test "a clean verdict carries no sugya" do assert Sugya.for_verdict(result(%{})) == %{} end test "a noted form carries the two-witness dissent, applied, with the forms it held for" do r = result(%{checks: %{frames: %{fired: false, forms: %{}, noted: %{apology_without_mechanism: %{claims: [], witnesses: 1}}, violations: []}}}) s = Sugya.for_verdict(r) assert Map.keys(s) == ["lo_taaseh_lekha"] e = s["lo_taaseh_lekha"] assert e.kind == "deed" and e.verse == "Devarim 19:15" assert e.fired == false and e.noted == ["apology_without_mechanism"] d = Enum.find(e.dissent, &(&1.reading == "single_witness_noted")) assert d.applied == true and d.forms == ["apology_without_mechanism"] and d.verse == "Devarim 19:15" # the exception for the forged fringe did not apply: nothing stood on one witness assert Enum.find(e.exception, &(&1.condition =~ "forged_fringe")).applied == false end test "a forged fringe standing on one witness carries the mark exception, applied" do r = result(%{verdict: :lo_tov, violations: ["halt(lo_taaseh_lekha,action(frame,by(claude),form(forged_fringe)),forged_fringe,'…')"], checks: %{frames: %{fired: true, forms: %{forged_fringe: %{stands_on: :forgery, witnesses: 1, claims: [], violations: ["x"]}}, noted: %{}, violations: ["x"]}}}) e = Sugya.for_verdict(r)["lo_taaseh_lekha"] assert e.fired == true assert Enum.find(e.exception, &(&1.condition == "single_witness(forged_fringe)")) |> Map.fetch!(:applied) == true assert Enum.find(e.dissent, &(&1.reading == "single_witness_noted")).applied == false end test "a golden calf beside a hedged claim carries the hedged dissent applied; without hedging, not" do base = %{verdict: :lo_tov, violations: ["halt(golden_calf,interpretation(x),golden_calf,'…')"], checks: %{grounding: %{assessed: true, fired: true}}} with_hedge = Sugya.for_verdict(result(Map.put(base, :examination, %{"claims" => [%{"hedged" => true}, %{"hedged" => false}]}))) assert with_hedge["golden_calf"].kind == "word" and with_hedge["golden_calf"].verse == "Devarim 18:22" assert Enum.find(with_hedge["golden_calf"].dissent, &(&1.reading == "hedged")).applied == true without = Sugya.for_verdict(result(Map.put(base, :examination, %{"claims" => [%{"hedged" => false}]}))) assert Enum.find(without["golden_calf"].dissent, &(&1.reading == "hedged")).applied == false end test "a rule the record cannot speak to carries its dissent considered, applied false" do r = result(%{verdict: :lo_tov, violations: ["halt(parah_adumah,action(self_validate,by(claude),target(self)),claude,'…')"]}) e = Sugya.for_verdict(r)["parah_adumah"] assert e.kind == "mark" and e.verse == "Vayikra 13:3" assert e.precedent == "specimens(self_validation)" assert [%{reading: "validator_named_is_not_the_speaker", applied: false, verse: "Bamidbar 19:7"}] = Enum.map(e.dissent, &Map.take(&1, [:reading, :applied, :verse])) end end