NET-A-PORTER / scala-uri

Simple scala library for building and parsing URIs
Other
261 stars 33 forks source link

DSL for v1 #117

Closed evanbennett closed 7 years ago

evanbennett commented 8 years ago

I am working on an updated DSL for my v1 proposal.

I need to know: What is the DSL intended to be used for?

My opinion would be: Yes; No; No. As this leads to a cleaner separation of functionality.

theon commented 8 years ago

I think those are fair assumptions. I personally have only used the DSL to create URIs. The current DSL can be used to modify existing URIs, but I have no idea how many people use it that way.

I'd be interested to scan over github repos to find how projects are currently using scala-uri. On 4 Jul 2016 04:21, "Evan Bennett" notifications@github.com wrote:

I am working on an updated DSL for my v1 proposal.

I need to know: What is the DSL intended to be used for?

Is the DSL only intended to be used to create a Uri? Is the DSL intended to be used to modify an existing Uri? Is the DSL intended to be used as a parser?

My opinion would be: Yes; No; No. As this leads to a cleaner separation of functionality.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

evanbennett commented 8 years ago

I will work with that assumption then.

I did a quick search on GitHub, but I do not really know what I am doing. I think it would be interesting though.

evanbennett commented 8 years ago

I thought I would post were I am up to with the DSL update (it is time for dinner), to see if anyone had any feedback.

This is some working pieces from the DslTests ("registeredName" could be something like "theon.github.com"), all the parentheses are currently required:

  it should "create a `Uri` with scheme only" in {
    val uri: Uri = "scheme" `:`;

  it should "create a `Uri` with scheme, registeredName and fragment" in {
    val uri = ("scheme" `://` ("registeredName")) `#` "fragment"

  it should "create a `Uri` with scheme, empty authority and fragment" in {
    val uri = "scheme" `://#` "fragment"

  it should "create a `Uri` with scheme and fragment" in {
    val uri = "scheme" :# "fragment"

  it should "create a `Uri` with registeredName and single query parameter" in {
    val uri: Uri = `//` ("registeredName") `?` ("queryKey" `=` "queryValue")

  it should "create a `Uri` with absolute path with multiple string segments" in {
    val uri: Uri = / ("pathSegment1") / "pathSegment2" / "pathSegment3"

  it should "create a `Uri` with multiple query parameters" in {
    val uri: Uri = ? ("queryKey1" `=` "queryValue1") & ("queryKey2" `=` "queryValue2") & ("queryKey3" `=` "queryValue3")

  it should "create a `Uri` with multiple query parameters and fragment" in {
    val uri: Uri = (? ("queryKey1" `=` "queryValue1") & ("queryKey2" `=` "queryValue2") & ("queryKey3" `=` "queryValue3")) `#` ("fragment")

  it should "create a `Uri` with fragment only" in {
    val uri = `#` ("fragment")

  it should "create a `Uri` with scheme, registeredName, multiple segements, multiple query parameters and fragment" in {
    val uri = ((("scheme" `://` ("registeredName")) / "pathSegment1" / "pathSegment2" `;` ("matrixKey1" `=` "matrixValue1") `;` ("matrixKey2" `=` "matrixValue2")) ? ("queryKey1" `=` "queryValue1") & ("queryKey2" `=` "queryValue2")) `#` "fragment"