Skip to content

Commit

Permalink
Merge pull request #52 from grover-ws-2/master
Browse files Browse the repository at this point in the history
DD,VM: Add more tests for `UriTemplate` Fixes #50
  • Loading branch information
danielbodart authored Nov 27, 2016
2 parents aece5ab + f289a1e commit bf358b5
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/com/googlecode/utterlyidle/UriTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@ public void canExtractEntireEndSectionOfPath() {
assertThat(uriTemplate.extract("/value/end/123/456").getValue("end"), is("123/456"));
}

@Test
public void canCaptureSingleElementFromStartOfPath() {
UriTemplate uriTemplate = uriTemplate("{name}");
assertTrue(uriTemplate.matches("/value/end/123/456"));
assertThat(uriTemplate.extract("/value/end/123/456").getValue("name"), is("value"));
}

@Test
public void canCaptureWholePathWithStartSlashStripped() {
UriTemplate uriTemplate = uriTemplate("{name:.*}");
assertTrue(uriTemplate.matches("/value/end/123/456"));
assertThat(uriTemplate.extract("/value/end/123/456").getValue("name"), is("value/end/123/456"));
}

@Test
public void canCaptureWholePathWithStartAndEndSlashStripped() {
UriTemplate uriTemplate = uriTemplate("{name:.*}");
assertTrue(uriTemplate.matches("/value/end/123/456/"));
assertThat(uriTemplate.extract("/value/end/123/456/").getValue("name"), is("value/end/123/456"));
}

@Test
public void canCaptureRestOfPathWithStartSlashIncludedAndEndDropped() {
UriTemplate uriTemplate = uriTemplate("/foo/bar{subpath:.*}");
assertTrue(uriTemplate.matches("/foo/bar/bob/jim/"));
assertThat(uriTemplate.extract("/foo/bar/bob/jim/").getValue("subpath"), is("/bob/jim"));
}

@Test
public void ignoresPathVariablesContainingSlashes() throws Exception {
assertThat(uriTemplate("properties/{name:foo/order}").segments(), is(2));
Expand Down

0 comments on commit bf358b5

Please sign in to comment.