From ce8a34cb5b63aa5a88a276293bd63e9bdacb5a36 Mon Sep 17 00:00:00 2001 From: Aaron Bedra Date: Sat, 14 Aug 2021 14:31:27 -0500 Subject: [PATCH] Add logical_or --- simple_http.hpp | 7 +++++++ test/unit_tests.cpp | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/simple_http.hpp b/simple_http.hpp index ec89b1b..eeef791 100644 --- a/simple_http.hpp +++ b/simple_http.hpp @@ -287,6 +287,13 @@ Predicate between_inclusive(const A &a, const A &b) { }; } +template +Predicate logical_or(const A &a, const A &b) { + return [a, b](const A &other) { + return other == a || other == b; + }; +} + // Information Responses inline static HttpStatusCode CONTINUE = HttpStatusCode{100}; inline static HttpStatusCode SWITCHING_PROTOCOL = HttpStatusCode{101}; diff --git a/test/unit_tests.cpp b/test/unit_tests.cpp index 728fe96..a0e9d76 100644 --- a/test/unit_tests.cpp +++ b/test/unit_tests.cpp @@ -22,6 +22,17 @@ TEST_CASE("Predicates") CHECK(!subject(11)); } + SECTION("logical_or") + { + SimpleHttp::Predicate subject = SimpleHttp::logical_or(1, 2); + + CHECK(subject(1)); + CHECK(subject(2)); + CHECK(!subject(3)); + CHECK(!subject(-1)); + CHECK(!subject(-2)); + } + SECTION("informational") { SimpleHttp::Predicate informational = SimpleHttp::informational();