Created
October 8, 2013 06:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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