summaryrefslogblamecommitdiff
path: root/src/common/extract_test.cpp
blob: d8e9ebe15b384c85f49d6d08b1f991a00aaf47ad (plain) (tree)






























































































































































































































































































































                                                                  
#include "extract.hpp"

#include <gtest/gtest.h>

TEST(extract, record_int)
{
    int x, y, z;
    x = y = z = 0;
    EXPECT_FALSE(extract("1 2 3 4 ", record<' '>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(3, z);
    x = y = z = 0;
    EXPECT_FALSE(extract("1 2 3 4", record<' '>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(3, z);
    x = y = z = 0;
    EXPECT_TRUE(extract("1 2 3 ", record<' '>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(3, z);
    x = y = z = 0;
    EXPECT_TRUE(extract("1 2 3", record<' '>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(3, z);
    x = y = z = 0;
    EXPECT_FALSE(extract("1 2 ", record<' '>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_FALSE(extract("1 2", record<' '>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_FALSE(extract("1 ", record<' '>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(0, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_FALSE(extract("1", record<' '>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(0, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_FALSE(extract(" ", record<' '>(&x, &y, &z)));
    EXPECT_EQ(0, x);
    EXPECT_EQ(0, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_FALSE(extract("", record<' '>(&x, &y, &z)));
    EXPECT_EQ(0, x);
    EXPECT_EQ(0, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;

    EXPECT_FALSE(extract("1 2 3 4 ", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(3, z);
    x = y = z = 0;
    EXPECT_FALSE(extract("1 2 3 4", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(3, z);
    x = y = z = 0;
    EXPECT_TRUE(extract("1 2 3 ", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(3, z);
    x = y = z = 0;
    EXPECT_TRUE(extract("1 2 3", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(3, z);
    x = y = z = 0;
    EXPECT_TRUE(extract("1 2 ", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_TRUE(extract("1 2", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_FALSE(extract("1 ", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(0, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_FALSE(extract("1", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(0, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_FALSE(extract(" ", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ(0, x);
    EXPECT_EQ(0, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_FALSE(extract("", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ(0, x);
    EXPECT_EQ(0, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;

    EXPECT_FALSE(extract("1 2 3 4 ", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(3, z);
    x = y = z = 0;
    EXPECT_FALSE(extract("1 2 3 4", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(3, z);
    x = y = z = 0;
    EXPECT_TRUE(extract("1 2 3 ", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(3, z);
    x = y = z = 0;
    EXPECT_TRUE(extract("1 2 3", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(3, z);
    x = y = z = 0;
    EXPECT_TRUE(extract("1 2 ", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_TRUE(extract("1 2", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(2, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_TRUE(extract("1 ", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(0, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_TRUE(extract("1", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ(1, x);
    EXPECT_EQ(0, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_FALSE(extract(" ", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ(0, x);
    EXPECT_EQ(0, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
    EXPECT_FALSE(extract("", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ(0, x);
    EXPECT_EQ(0, y);
    EXPECT_EQ(0, z);
    x = y = z = 0;
}

TEST(extract, record_str)
{
    XString x, y, z;
    x = y = z = "";
    EXPECT_FALSE(extract("1 2 3 4 ", record<' '>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("3", z);
    x = y = z = "";
    EXPECT_FALSE(extract("1 2 3 4", record<' '>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("3", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 2 3 ", record<' '>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("3", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 2 3", record<' '>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("3", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 2 ", record<' '>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_FALSE(extract("1 2", record<' '>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_FALSE(extract("1 ", record<' '>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_FALSE(extract("1", record<' '>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_FALSE(extract(" ", record<' '>(&x, &y, &z)));
    EXPECT_EQ("", x);
    EXPECT_EQ("", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_FALSE(extract("", record<' '>(&x, &y, &z)));
    EXPECT_EQ("", x);
    EXPECT_EQ("", y);
    EXPECT_EQ("", z);
    x = y = z = "";

    EXPECT_FALSE(extract("1 2 3 4 ", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("3", z);
    x = y = z = "";
    EXPECT_FALSE(extract("1 2 3 4", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("3", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 2 3 ", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("3", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 2 3", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("3", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 2 ", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 2", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 ", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_FALSE(extract("1", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_TRUE(extract(" ", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ("", x);
    EXPECT_EQ("", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_FALSE(extract("", record<' ', 2>(&x, &y, &z)));
    EXPECT_EQ("", x);
    EXPECT_EQ("", y);
    EXPECT_EQ("", z);
    x = y = z = "";

    EXPECT_FALSE(extract("1 2 3 4 ", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("3", z);
    x = y = z = "";
    EXPECT_FALSE(extract("1 2 3 4", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("3", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 2 3 ", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("3", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 2 3", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("3", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 2 ", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 2", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("2", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1 ", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_TRUE(extract("1", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ("1", x);
    EXPECT_EQ("", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_TRUE(extract(" ", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ("", x);
    EXPECT_EQ("", y);
    EXPECT_EQ("", z);
    x = y = z = "";
    EXPECT_TRUE(extract("", record<' ', 1>(&x, &y, &z)));
    EXPECT_EQ("", x);
    EXPECT_EQ("", y);
    EXPECT_EQ("", z);
    x = y = z = "";
}