Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathMap spec #2

Closed
wants to merge 4 commits into from
Closed

PathMap spec #2

wants to merge 4 commits into from

Conversation

chris-martin
Copy link

(In progress)

Comment on lines +42 to +49
it "case 3" $
property $
forAll (arbitrary `suchThat` (/= "a")) $ \segment ->
let result =
PathMap.lookup
(renderPath $ Path [segment])
(PathMap.fromList [("/{}", False), ("/a", True)])
in counterexample ("result = " <> show result) (isNothing result)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The funky case as described in #1 (comment) - the spec written here describes what the code presently does, not what it should do.

src/Network/Wai/Middleware/OpenApi/PathMap.hs Show resolved Hide resolved
@@ -17,17 +19,21 @@ import Data.OpenApi (OpenApi, PathItem)
import Data.OpenApi qualified as OpenApi
import System.FilePath.Posix qualified as Posix

newtype PathMap = PathMap
{ unwrap :: Map TemplatedPath PathItem
newtype PathMap a = PathMap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this polymorphism just to make the tests easier to write?

FWIW, I find the property-based testing hard to follow and not very good at documenting the behaviors you uncovered. I think things would be clearer if you gave yourself a helper to create concrete PathItems and test against fixed scenarios with them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this polymorphism just to make the tests easier to write?

Yeah, it means you don't actually have to construct PathItems, since that's not relevant to what's being tested, which is only how the keys match. But we could give the polymorphic type a different name and alias type PathMap = Something PathItem to avoid complicating the user API.

I find the property-based testing hard to follow

Yeah, I just started down that road because I was suspecting that I needed quickcheck to generate some larger maps for me to find the problem cases. If wonky Ords are a problem I don't necessarily expect to be able to find it with small examples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If wonky Ords are a problem I don't necessarily expect to be able to find it with small examples

Well, you gave three cases here. I feel like one it for each of those would be sufficient.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

means you don't actually have to construct PathItems

Well, you have to define something you can distinguish. I don't really see mempty & summary ?~ "foo" that much more difficult than some other non-PathItem type (that can be distinguished). And for test that needn't distinguish (like an isNothing assertion), then mempty is about as simple as it gets.

src/Network/Wai/Middleware/OpenApi/Schema.hs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants