mercredi 31 décembre 2014

Passing discriminated unions to InlineData attributes

I am trying to unit test a parser that parses a string and returns the corresponding abstract syntax tree (represented as a discriminated union). I figured it would be pretty compact to use Xunit.Extensions' attribute InlineData to stack all test cases on one another:



[<Theory>]
[<InlineData("1 +1 ", Binary(Literal(Number(1.0)), Add, Literal(Number(1.0))))>]
...
let ``parsed string matches the expected result`` () =


However, compiler complains that the second argument is not a literal (compile time constant if I understand it correctly).


Is there a workaround for this? If not, what would be the most sensible way to structure parser result tests while keeping every case as a separate unit test?


Aucun commentaire:

Enregistrer un commentaire