Comments (3)
+1 on this.
Here is a simple repro:
let someFn x =
match x with
| 42 -> []
| _ -> [1;x]
[<Test>]
let ``someFn should return empty list when given 42``() =
someFn 42
|> should equal []
The test fails and error message cryptically states that Expected: [], was: []
from fsunit.
+1. It would be useful to support statically typed matchers in other cases too. I am currently trying the following (not tested yet, please point out errors):
let inline equalWithin t x =
let isInRange y = y <= x+t && y>= x-t
NHamcrest.CustomMatcher<_>(sprintf "%s with a tolerance of %s" (string x) (string t), fun v -> isInRange v)
let inline should' m expected actual = Xunit.Assert.That(actual, m expected)
This has the advantage of equalWithin
working on any comparable type that supports -
, +
(including DateTime
with TimeSpan
tolerance). The current equalWithin
only works with objects whose string representations parse as doubles.
from fsunit.
Released in v2.2.0-beta1
from fsunit.
Related Issues (20)
- Method not found: 'Void Xunit.Sdk.AssertActualExpectedException..ctor HOT 2
- Pipelines are not correctly failing HOT 3
- Inconsistent behaviour of `should equal` in NUnit vs XUnit HOT 1
- Update docs site HOT 7
- error FS0074: The type referenced through 'NHamcrest.IMatcher`1' is defined in an assembly that is not referenced. HOT 2
- Using `should throw` does not show the raised exception, only the string version of the lambda HOT 5
- [Feature request] Creating custom constraints HOT 4
- Using 'should throw' or 'should throwWithMessage' never succeeds unless function returns unit HOT 15
- Deep equality for C# types HOT 5
- Comparing sequences fails HOT 13
- New Year's ToDos HOT 1
- Is FSharp.Core 6.0.7 really the lowest dependency for FsUnit? HOT 3
- `MatchException` does not exist anymore in 2.5.0 HOT 4
- Do not use an upper bound on dependencies, unless you have to HOT 5
- Method not found error on NUnit 4 HOT 6
- FsUnit vNext HOT 8
- Build problems HOT 1
- Testing lists for equality gives unpleasant failure report HOT 4
- Cannot upgrade to 6.0.0 when using .NET Framework 4.8 HOT 6
- [NUnit] Non provided generics is inferred to `obj` making test fails HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fsunit.