Skip to content

Instantly share code, notes, and snippets.

@ptrelford
Created October 8, 2013 06:47
Show Gist options
  • Save ptrelford/6880545 to your computer and use it in GitHub Desktop.
Save ptrelford/6880545 to your computer and use it in GitHub Desktop.
TickSpec bullet points example with Active Pattern to convert string array to points
Feature: As a writer I like to use bullet points
Scenario: Writing lists with bullets
Given a list of bullet points:
* 1,2
* 2,3
* 3,4
module BulletsSteps
type BulletsFixture () = inherit TickSpec.NUnit.FeatureFixture("Bullets.feature")
open TickSpec
open NUnit.Framework
let (|Int|_|) x =
match System.Int32.TryParse(x) with
| true, n -> Some n
| false, _ -> None
let (|Points|) (bullets:string[]) =
bullets |> Array.map (fun bullet ->
let values = bullet.Split(',')
match values with
| [|Int x; Int y|] -> (x,y)
| _ -> invalidOp "Expecting point"
)
let [<Given>] ``a list of bullets points:`` (Points points) =
for (x,y) in points do
printf "%d %d" x y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment