1 Star 0 Fork 4

郭峻杞/pcre3

forked from openKylin/pcre3 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pcre_stringpiece_unittest.cc 3.52 KB
一键复制 编辑 原始数据 按行查看 历史
openKylinBot 提交于 2022-05-14 02:39 . Import Upstream version 8.39
// Copyright 2003 and onwards Google Inc.
// Author: Sanjay Ghemawat
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <map>
#include <algorithm> // for make_pair
#include "pcrecpp.h"
#include "pcre_stringpiece.h"
// CHECK dies with a fatal error if condition is not true. It is *not*
// controlled by NDEBUG, so the check will be executed regardless of
// compilation mode. Therefore, it is safe to do things like:
// CHECK(fp->Write(x) == 4)
#define CHECK(condition) do { \
if (!(condition)) { \
fprintf(stderr, "%s:%d: Check failed: %s\n", \
__FILE__, __LINE__, #condition); \
exit(1); \
} \
} while (0)
using pcrecpp::StringPiece;
static void CheckSTLComparator() {
string s1("foo");
string s2("bar");
string s3("baz");
StringPiece p1(s1);
StringPiece p2(s2);
StringPiece p3(s3);
typedef std::map<StringPiece, int> TestMap;
TestMap map;
map.insert(std::make_pair(p1, 0));
map.insert(std::make_pair(p2, 1));
map.insert(std::make_pair(p3, 2));
CHECK(map.size() == 3);
TestMap::const_iterator iter = map.begin();
CHECK(iter->second == 1);
++iter;
CHECK(iter->second == 2);
++iter;
CHECK(iter->second == 0);
++iter;
CHECK(iter == map.end());
TestMap::iterator new_iter = map.find("zot");
CHECK(new_iter == map.end());
new_iter = map.find("bar");
CHECK(new_iter != map.end());
map.erase(new_iter);
CHECK(map.size() == 2);
iter = map.begin();
CHECK(iter->second == 2);
++iter;
CHECK(iter->second == 0);
++iter;
CHECK(iter == map.end());
}
static void CheckComparisonOperators() {
#define CMP_Y(op, x, y) \
CHECK( (StringPiece((x)) op StringPiece((y)))); \
CHECK( (StringPiece((x)).compare(StringPiece((y))) op 0))
#define CMP_N(op, x, y) \
CHECK(!(StringPiece((x)) op StringPiece((y)))); \
CHECK(!(StringPiece((x)).compare(StringPiece((y))) op 0))
CMP_Y(==, "", "");
CMP_Y(==, "a", "a");
CMP_Y(==, "aa", "aa");
CMP_N(==, "a", "");
CMP_N(==, "", "a");
CMP_N(==, "a", "b");
CMP_N(==, "a", "aa");
CMP_N(==, "aa", "a");
CMP_N(!=, "", "");
CMP_N(!=, "a", "a");
CMP_N(!=, "aa", "aa");
CMP_Y(!=, "a", "");
CMP_Y(!=, "", "a");
CMP_Y(!=, "a", "b");
CMP_Y(!=, "a", "aa");
CMP_Y(!=, "aa", "a");
CMP_Y(<, "a", "b");
CMP_Y(<, "a", "aa");
CMP_Y(<, "aa", "b");
CMP_Y(<, "aa", "bb");
CMP_N(<, "a", "a");
CMP_N(<, "b", "a");
CMP_N(<, "aa", "a");
CMP_N(<, "b", "aa");
CMP_N(<, "bb", "aa");
CMP_Y(<=, "a", "a");
CMP_Y(<=, "a", "b");
CMP_Y(<=, "a", "aa");
CMP_Y(<=, "aa", "b");
CMP_Y(<=, "aa", "bb");
CMP_N(<=, "b", "a");
CMP_N(<=, "aa", "a");
CMP_N(<=, "b", "aa");
CMP_N(<=, "bb", "aa");
CMP_N(>=, "a", "b");
CMP_N(>=, "a", "aa");
CMP_N(>=, "aa", "b");
CMP_N(>=, "aa", "bb");
CMP_Y(>=, "a", "a");
CMP_Y(>=, "b", "a");
CMP_Y(>=, "aa", "a");
CMP_Y(>=, "b", "aa");
CMP_Y(>=, "bb", "aa");
CMP_N(>, "a", "a");
CMP_N(>, "a", "b");
CMP_N(>, "a", "aa");
CMP_N(>, "aa", "b");
CMP_N(>, "aa", "bb");
CMP_Y(>, "b", "a");
CMP_Y(>, "aa", "a");
CMP_Y(>, "b", "aa");
CMP_Y(>, "bb", "aa");
#undef CMP_Y
#undef CMP_N
}
int main(int argc, char** argv) {
(void)argc;
(void)argv;
CheckComparisonOperators();
CheckSTLComparator();
printf("OK\n");
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gjq0613/pcre3.git
git@gitee.com:gjq0613/pcre3.git
gjq0613
pcre3
pcre3
openkylin/yangtze

搜索帮助