patternMatchTest.cpp 2.0 KB
Newer Older
H
hjxilinx 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#include <gtest/gtest.h>
#include <sys/time.h>
#include <cassert>
#include <iostream>

#include "tsqlfunction.h"

TEST(testCase, patternMatchTest) {
  SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER;

  const char* str = "abcdef";
  int32_t ret = patternMatch("a%b%", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "tm01";
  ret = patternMatch("tm__", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "tkm1";
  ret = patternMatch("t%m1", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "tkm1";
  ret = patternMatch("%m1", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "";
  ret = patternMatch("%_", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH);

  str = "1";
  ret = patternMatch("%__", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH);

  str = "";
  ret = patternMatch("%", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = " ";
  ret = patternMatch("_", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "!";
  ret = patternMatch("%_", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "abcdefg";
  ret = patternMatch("abc%fg", str, strlen(str), &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "abcdefgabcdeju";
  ret = patternMatch("abc%fg", str, 7, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "abcdefgabcdeju";
  ret = patternMatch("abc%f_", str, 6, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH);

  str = "abcdefgabcdeju";
  ret = patternMatch("abc%f_", str, 1, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_NOMATCH);

  str = "abcdefgabcdeju";
  ret = patternMatch("ab", str, 2, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "abcdefgabcdeju";
  ret = patternMatch("a%", str, 2, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_MATCH);

  str = "abcdefgabcdeju";
  ret = patternMatch("a__", str, 2, &info);
  EXPECT_EQ(ret, TSDB_PATTERN_NOMATCH);
}