exploding-fish icon indicating copy to clipboard operation
exploding-fish copied to clipboard

Spec support

Open valerauko opened this issue 7 years ago • 5 comments

It'd be great if there was a way to validate/generate both EF and plain string URIs.

valerauko avatar Jun 23 '18 17:06 valerauko

@valerauko, you mean validate that the URI matches the RFC?

It's already possible to generate both. Calling str on an EF URI will convert it to a plain string URI. And you can call uri on a string URI to create an EF URI.

Additionally, all of the URI manipulation functions work on plain strings as well.

wtetzner avatar Jun 24 '18 21:06 wtetzner

Sorry, I meant more in the clojure.spec.alpha way.

I try to document my code with specs as much as possible and not being able to easily spec URLs is giving me trouble. I made a hacky spec/generator based on java.net.URI, but I can imagine it fitting in EF much better (and more complete)

valerauko avatar Jun 25 '18 15:06 valerauko

So, exploding-fish is pretty liberal in what it will parse, so it will parse almost anything into a URI. For example:

user> (into {} (uri "fred is cool"))
{:scheme-relative "fred is cool", :path "fred is cool"}

absolute? checks to see if there's an authority in the URI. For example:

user> (absolute? (uri "fred is cool"))
false
user> (absolute? (uri "http://bob.com/fred is cool"))
true

It probably only makes sense to have a predicate to check for absolute URIs.

Would it make sense to have different predicates for Uri and String, or just a single check that will be valid for both Uri and String (and java.net.URI)? The exploding-fish URI functions work on all of those representations.

If you wanted to ensure it was a string URI, I suppose you could just check that it's a URI and that it's a String.

wtetzner avatar Jun 29 '18 00:06 wtetzner

You're right, using your built-in predicates can solve some of my issues.

Do you plan to spec the library though?

valerauko avatar Jul 12 '18 14:07 valerauko

I do plan on it, I'm just not sure when I'll get to it.

wtetzner avatar Jul 12 '18 16:07 wtetzner