Skip to content

Commit

Permalink
Merge branch 'release/v1.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
i-vovk committed May 2, 2021
2 parents ff6f3e6 + c1e7bbc commit 221a137
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 11 deletions.
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Bug report
about: Create a report to help us improve
title: "[Bug] "
labels: bug
assignees: i-vovk

---

**Describe the bug**
Short description of what the bug is.

**Steps to Reproduce**
Steps to reproduce the behavior.

**Expected behavior**
Description of what you expected to happen.

**Observed behavior**
Description of what really happened.

**Environment**
- OS (include version): [e.g. macosx 10.15.3]
- Compiler (include version): [e.g. Apple clang version 11.0.0]
- Boost version: [e.g. 1.66.0]
- Cmake version: [e.g. 3.16.4]

**Additional info**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[Feature] "
labels: enhancement
assignees: i-vovk

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
41 changes: 39 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# macOS folder view
**/.DS_Store

# toolchain env
.idea/
.gradle/
build/
.DS_Store
coverage-build/
Testing/
coverage.txt
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.1.2 (2021-05-02)

### Misc

* Fix gcc 10 doesn't imply `<stdexcept>` header
* Fix testing expanded dicts related to params order


## 1.1.1 (2021-03-02)

### Features
Expand All @@ -8,6 +16,7 @@

* Update README


# 1.1.0 (2021-02-26)

### Features
Expand All @@ -18,13 +27,15 @@

* Style-related fixes


## 1.0.1 (2020-11-06)

### Features

* Implement operator==/!= for Literal, Expression, Variable
* Implement unit tests


# 1.0.0 (2020-10-07)

- initial release
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

set(URITEMPLATE_VERSION_MAJOR "1")
set(URITEMPLATE_VERSION_MINOR "1")
set(URITEMPLATE_VERSION_RELEASE "1")
set(URITEMPLATE_VERSION_RELEASE "2")
set(URITEMPLATE_VERSION_STRING "${URITEMPLATE_VERSION_MAJOR}.${URITEMPLATE_VERSION_MINOR}.${URITEMPLATE_VERSION_RELEASE}")
set(URITEMPLATE_LIB_VERSION ${URITEMPLATE_VERSION_STRING})
set(URITEMPLATE_LIB_SOVERSION "${URITEMPLATE_VERSION_MAJOR}")
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
[![Language C++](https://img.shields.io/badge/language-c++-blue.svg)](https://isocpp.org)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

This library implements [URI Template](https://tools.ietf.org/html/rfc6570) with full support up to Level 4 providing **expansion** and **match** capabilities. It requires c++17 compiler support and have no dependencies.
This library implements [URI Template](https://tools.ietf.org/html/rfc6570) with full support up to Level 4 providing **expansion** and **match** capabilities. It requires c++17 compiler support and has no dependencies.

## What?

URI templates are convenient way to describe a range of possible URI by making some parts of it variable. For example, variety of resources:
URI templates are a convenient way to describe a range of possible URI by making some parts of it variable. For example, a variety of resources:
* `http://example.com/~fred/`
* `http://example.com/~mark/`
* `http://example.com/~admin/`
Expand All @@ -24,7 +24,7 @@ Could be described by – `http://example.com/search{?q,lang}`.

A template is transformed into a URI by replacing each delimited expression with its value as defined by expansion rules and the values of variables.

URI Templates can also be used in reverse for the purpose of variable matching: comparing the template to a fully formed URI in order to extract the variables. It only works well if the template expressions are delimited by the beginning or end of the URI or by characters that cannot be part of the expansion, otherwise some ambiguity is present. For example, a template `http://example.com/{foo}{bar}` matches `http://example.com/foobar`, but is is impossible to distinguish if:
URI Templates can also be used in reverse for the purpose of variable matching: comparing the template to a fully formed URI in order to extract the variables. It only works well if the template expressions are delimited by the beginning or end of the URI or by characters that cannot be part of the expansion, otherwise, some ambiguity is present. For example, a template `http://example.com/{foo}{bar}` matches `http://example.com/foobar`, but is is impossible to distinguish if:
* `foo='foobar'` and `bar` is undefined; or
* `foo` is undefined and `bar='foobar'`

Expand All @@ -41,7 +41,7 @@ URI Templates are presented as instances of `URI::Template::Template` class. It

classes.

From there you can provide values for template variables with `URI::Template::VarValue` objects and expand it, or use `URI::Template::MatchURI()` to test if some URI matches a template, i.e. if it can be expanded from a template if correct values are provided.
From there you can provide values for template variables with `URI::Template::VarValue` objects and expand it, or use `URI::Template::MatchURI()` to test if some URI matches a template, i.e. if it can be expanded from a template with correct values provided.

### Example

Expand Down
2 changes: 2 additions & 0 deletions src/Modifier.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "uri-template/Modifier.h"

#include <stdexcept>

URI::Template::ModifierType URI::Template::ModNoop::Type() const
{
return ModifierType::NONE;
Expand Down
2 changes: 2 additions & 0 deletions src/Operator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "uri-template/Operator.h"

#include <stdexcept>

const char URI::Template::Operator::kNoCharacter = '\0';

URI::Template::OperatorType URI::Template::OpNoop::Type() const
Expand Down
33 changes: 29 additions & 4 deletions test/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
#include "uri-template/uri-template.h"
#include "gtest/gtest.h"

namespace {
bool ExpandedEqual(const std::string& str1, const std::string& str2) {
if (str1 == str2) {
return true;
}
// DICT VarValue (std::unordered_map) may be expanded with any order
// Compare length and set of characteds
if (str1.length() != str2.length()) {
return false;
}

std::unordered_set<char> uri_characters;
for (const auto& c : str2) {
uri_characters.insert(c);
}
for (const auto& c : str1) {
if (uri_characters.count(c) == 0) {
return false;
}
}

return true;
}
}

struct TestParams
{
std::string uri_template_str;
Expand Down Expand Up @@ -78,9 +103,9 @@ class TemplateMatch: public testing::TestWithParam<TestParams>
return ::testing::AssertionFailure() << "'" << test_param.uri_template_str << "' is not expanded";
}

if (expanded_str != test_param.uri_str) {
if (!ExpandedEqual(expanded_str, test_param.uri_str)) {
return ::testing::AssertionFailure()
<< "expanded '" << expanded_str << "' != '" << test_param.uri_str << "'";
<< "expanded '" << expanded_str << "' != expected '" << test_param.uri_str << "'";
}
return ::testing::AssertionSuccess();
}
Expand Down Expand Up @@ -125,9 +150,9 @@ class TemplateExpand: public testing::TestWithParam<TestParams>
return ::testing::AssertionFailure() << "'" << test_param.uri_template_str << "' is not expanded";
}

if (expanded_str != test_param.uri_str) {
if (!ExpandedEqual(expanded_str, test_param.uri_str)) {
return ::testing::AssertionFailure()
<< "expanded '" << expanded_str << "' != '" << test_param.uri_str << "'";
<< "expanded '" << expanded_str << "' != expected '" << test_param.uri_str << "'";
}
return ::testing::AssertionSuccess();
}
Expand Down

0 comments on commit 221a137

Please sign in to comment.