uri-templates/uritemplate-test

"Reversible" sub-set of tests?

Closed this issue · 3 comments

I wrote a JavaScript library (GitHub repo) that as well as expanding templates, can also guess values from URIs:

var template = uriTemplate("{/id*}{?fields,token}");
var guessedValues = template.fromUri("/person/albums?fields=id,name,picture&token=12345");
/* {
       id: ["person", 'albums"],
       fields: ["id", "name", "picture"],
       token: "12345"
   } */
var reconstructed = template.fillFromObject(guessedValues);

I'm currently testing it using this test suite, by checking that the guessed values will reconstruct the original URI.

However, I can't actually check that the calculated values are "correct". Most of them I could probably handle with a fuzzy comparison against the entries in variables, but that doesn't work for some cases, e.g.:

  • "?{x,undef,y}" => "?1024,768"
  • "{var1}{var2}" => "string1string2"

(Note that the second case is OK when var2 has a prefix, like "{var1}{?var2}")

Would it be possible to assemble a sub-set of the tests where the original data should be recoverable? If I assembled such a subset, would you be open to including it in this repo?

Hi there

I'm already doing that in ruby by checking if the extracted variables are a valid subset of the original and if you can expand the template with extracted variables and get the same result. This works pretty well for all templates.

Alles Gute
Hannes

This is likely out of scope for the test suite and RCF6570 in general. I'm also working on reverse matching in my implementation but I'm keeping these tests separate from those in the uritemplate-text expansion test suite.

Regarding the tests, since RFC6570 makes no statement about ordering, we had to account for it by including all possible results. See issue #1 for more background. This of course makes it bit more challenging to to handle reverse matching.

But given that RFC6570 does not cover reverse matching, you're likely free to to take some liberties here. For example, Handy-URI-Templates does maintain ordering so I have been creating my of set of tests from the URI template tests with the knowledge that my implementation maintains order. Using the uritemplate-tests to validate the reverse matching use cases is a lot of extra work IMHO.

Fair enough - it's not mentioned at all in the spec, so I can see why it wouldn't be included in this repo.

@hannesg: "expand the template with extracted variables and get the same result" is what I've got currently. I'll have a look at how you're doing your "subset" checking.

@damnhandy: I'm likely making similar assumptions to you about ordering. I might write my own test cases as well - it's just that this test suite is a pretty comprehensive sampling of different ways the standard might be used.

Thanks for taking the time to comment. :)