From 396d9418fe1eec694350f2f5a786879e7812fd20 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Tue, 30 Apr 2024 12:19:50 +0200 Subject: [PATCH] add initial input stream op tests --- test/Makefile | 2 +- test/input_stream_ops.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/input_stream_ops.cpp diff --git a/test/Makefile b/test/Makefile index 341bd08..2fbb83f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,7 +3,7 @@ CXXFLAGS += $(addprefix -I, $(INCLUDE)) TEST = test -_TESTS = example.cpp +_TESTS = example.cpp input_stream_ops.cpp TESTS = $(addprefix $(TEST)/, $(_TESTS)) OBJ = $(addprefix $(BIN)/, $(_TESTS:.cpp=)) diff --git a/test/input_stream_ops.cpp b/test/input_stream_ops.cpp new file mode 100644 index 0000000..dfa7b2b --- /dev/null +++ b/test/input_stream_ops.cpp @@ -0,0 +1,31 @@ +#include + +#include +#include + +TEST_START() + TEST("enum input stream operators work", + Countdown c = Countdown::NORMAL; + + std::stringstream ss("NONE"); + ss >> c; + assert(c == Countdown::NONE, "failed to parse enum"); + ) + + TEST("enum input stream operators ignore case", + Countdown c = Countdown::NORMAL; + + std::stringstream ss("none"); + ss >> c; + assert(c == Countdown::NONE, "failed to parse enum all lowercase"); + + ss = std::stringstream("nOnE"); + ss >> c; + assert(c == Countdown::NONE, "failed to parse enum mixed case #1"); + + ss = std::stringstream("NoNe"); + ss >> c; + assert(c == Countdown::NONE, "failed to parse enum mixed case #2"); + ) +TEST_FINISH() +