From 033baed9306a5352303fad1ba8e7ec21fc0956e1 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sun, 6 Jul 2014 12:02:51 -0700 Subject: [PATCH] Add simple tests for agi::Split --- tests/tests/split.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/tests/split.cpp diff --git a/tests/tests/split.cpp b/tests/tests/split.cpp new file mode 100644 index 000000000..9ab5ea2e8 --- /dev/null +++ b/tests/tests/split.cpp @@ -0,0 +1,47 @@ +// Copyright (c) 2014, Thomas Goyne +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// Aegisub Project http://www.aegisub.org/ + +#include +#include + +#include + +TEST(lagi_split, delim_not_present) { + std::string str("hello"); + for (auto tok : agi::Split(str, ',')) + EXPECT_EQ("hello", agi::str(tok)); +} + +TEST(lagi_split, delim_present) { + std::string str("a,b,c,"); + std::string expected[] = {"a", "b", "c", ""}; + size_t i = 0; + for (auto tok : agi::Split(str, ',')) + EXPECT_EQ(expected[i++], agi::str(tok)); +} + +TEST(lagi_split, does_not_copy_input) { + std::string str("hello"); + for (auto tok : agi::Split(str, ',')) { + EXPECT_EQ(str.begin(), tok.begin()); + EXPECT_EQ(str.end(), tok.end()); + } + + auto rng = agi::Split(str, 'e'); + EXPECT_EQ(str.begin(), rng->begin()); + EXPECT_EQ(str.end(), std::next(rng)->end()); +} +