Skip to content

Commit

Permalink
(red) new red test for detecting bug in and' implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxWilson committed Jan 11, 2024
1 parent f31a319 commit 7bd0e8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Core/Menus.fs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type Op =
| Some (Level lvl) when lvl < levels.Length -> level lvl
| _ when levels.Length >= 1 -> // we are permissive in the input we accept, partly to make testing easier. Flag means "default to the lowest value", e.g. Rapier +5-+7 defaults to Rapier +5.
level 0
| _ -> shouldntHappen "A levelled option with no levels is nonsense"
| _ -> shouldntHappen "A leveled option with no levels is nonsense"
)

static member budget (budgetF, offers: 't ListOffer list) =
Expand Down Expand Up @@ -216,7 +216,7 @@ type Op =
Op.and'(config, offers |> List.map (fun o -> Op.promote o))
static member and' (config: 't OfferConfig, offers: 't ListOffer list) : 't ListOffer =
offer(
{ config.inner with explicitUnselectedLabel = match offers |> List.map _.config.label with | [Some lhs; Some rhs] -> Some $"{lhs} and {rhs}" | _ -> None }, // promote label in the simple case
{ config.inner with explicitUnselectedLabel = match offers |> List.map (_.config.explicitUnselectedLabel) with | [Some lhs; Some rhs] -> Some $"{lhs} and {rhs}" | _ -> None }, // promote label in the simple case
fun config input ->
let children = [
for o in offers do
Expand Down
9 changes: 6 additions & 3 deletions test/Chargen.Accept.fs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ let units = testList "Unit.Chargen" [
])
])
)
testCase "and' should have a key based on its children" <| fun() ->
let offer = and'([skill("Fast-Draw (Sword)", +1); skill("Fast-Draw (Dagger)", +1)])
test <@ offer.config.key.Value = "Fast-Draw (Sword) +1 and Fast-Draw (Dagger) +1" @>
]
[<Tests>]
let tests =
Expand Down Expand Up @@ -188,9 +191,9 @@ let tests =
false, key "Sword!-Shortsword", Leaf "Shortsword +5"
])
])
Either(None, [true, ["Fast-Draw (Sword) +2"], Leaf "Fast-Draw (Sword) +2"])
Either(None, [true, ["Fast-Draw (Sword) +1 and Fast-Draw (Dagger) +1"], Leaf "Fast-Draw (Sword) +1 and Fast-Draw (Dagger) +1"])
]
offers |> testFors ["Sword!"; "Fast/-Draw (Sword) +2"] expectedMenus // evaluate swash() with Sword! selected and compare it to expectedMenus. Escape Fast-Draw to prevent it from being interpreted by parseKey as Fast + Draw
offers |> testFors ["Sword!"; "Fast/-Draw (Sword) +1 and Fast/-Draw (Dagger) +1"] expectedMenus // evaluate swash() with Sword! selected and compare it to expectedMenus. Escape Fast-Draw to prevent it from being interpreted by parseKey as Fast + Draw
render pseudoReactApi expectedMenus // if that passes, render it to ReactElements and see if it looks right
let fail expect v = failwith $"Expected {expect} but got {v}\nContext: {pseudoActual}"
let (|Checked|) = function Checked(label, key, children) -> Checked(label, key, children) | v -> fail "Checked" v
Expand All @@ -212,7 +215,7 @@ let tests =
Unchecked(Expect "Broadsword +5", Expect ["Broadsword"; "Sword!"])
Unchecked(Expect "Shortsword +5", Expect ["Shortsword"; "Sword!"])
])
Checked(Expect "Fast-Draw (Sword) +2", Expect ["Fast-Draw (Sword) +2"], Expect [])
Checked(Expect "Fast-Draw (Sword) +1 and Fast-Draw (Dagger) +1", Expect ["Fast-Draw (Sword) +1 and Fast-Draw (Dagger) +1"], Expect [])
]) -> ()
| v -> matchfail v // maybe we got the wrong number of NumberInputs from the Unconditional or something. Would be nice to have the error message say exactly what went wrong,
// but Expect active pattern isn't valid as an input to Fragment/Unconditional/etc. so we can't just Expect a specific list of children. Although... maybe we can refactor
Expand Down

0 comments on commit 7bd0e8e

Please sign in to comment.