diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..a634640 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -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. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..a687763 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -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. diff --git a/.gitignore b/.gitignore index dd7e2de..97ad899 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a142e1..6dd88ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 1.1.2 (2021-05-02) + +### Misc + +* Fix gcc 10 doesn't imply `` header +* Fix testing expanded dicts related to params order + + ## 1.1.1 (2021-03-02) ### Features @@ -8,6 +16,7 @@ * Update README + # 1.1.0 (2021-02-26) ### Features @@ -18,6 +27,7 @@ * Style-related fixes + ## 1.0.1 (2020-11-06) ### Features @@ -25,6 +35,7 @@ * Implement operator==/!= for Literal, Expression, Variable * Implement unit tests + # 1.0.0 (2020-10-07) - initial release diff --git a/CMakeLists.txt b/CMakeLists.txt index a14b781..65bfab2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}") diff --git a/README.md b/README.md index fa995bb..081fce9 100644 --- a/README.md +++ b/README.md @@ -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/` @@ -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'` @@ -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 diff --git a/src/Modifier.cpp b/src/Modifier.cpp index fb84be7..6aed614 100644 --- a/src/Modifier.cpp +++ b/src/Modifier.cpp @@ -1,5 +1,7 @@ #include "uri-template/Modifier.h" +#include + URI::Template::ModifierType URI::Template::ModNoop::Type() const { return ModifierType::NONE; diff --git a/src/Operator.cpp b/src/Operator.cpp index 59306d1..7b7316c 100644 --- a/src/Operator.cpp +++ b/src/Operator.cpp @@ -1,5 +1,7 @@ #include "uri-template/Operator.h" +#include + const char URI::Template::Operator::kNoCharacter = '\0'; URI::Template::OperatorType URI::Template::OpNoop::Type() const diff --git a/test/fixtures.h b/test/fixtures.h index 5c12658..51e80cd 100644 --- a/test/fixtures.h +++ b/test/fixtures.h @@ -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 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; @@ -78,9 +103,9 @@ class TemplateMatch: public testing::TestWithParam 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(); } @@ -125,9 +150,9 @@ class TemplateExpand: public testing::TestWithParam 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(); }