diff options
| author | zhengchao <[email protected]> | 2019-06-03 13:00:27 +0800 |
|---|---|---|
| committer | zhengchao <[email protected]> | 2019-06-03 13:00:27 +0800 |
| commit | 044d512184002cfaeaf12bd568e33d76beb99172 (patch) | |
| tree | 80326e292c86ec32424564510b79aaa416a3ba33 /plugin/business/pangu-http/src/test_pattern_replace.cpp | |
| parent | ace31ae24a9e484723d755b7a030c0598f1fabcb (diff) | |
修复pcre2_compile中参数顺序错误,支持utf8的替换,俄语不区分大小写测试通过。v4.0.0-20190603
Diffstat (limited to 'plugin/business/pangu-http/src/test_pattern_replace.cpp')
| -rw-r--r-- | plugin/business/pangu-http/src/test_pattern_replace.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/plugin/business/pangu-http/src/test_pattern_replace.cpp b/plugin/business/pangu-http/src/test_pattern_replace.cpp index 0672703..5017ee5 100644 --- a/plugin/business/pangu-http/src/test_pattern_replace.cpp +++ b/plugin/business/pangu-http/src/test_pattern_replace.cpp @@ -33,6 +33,10 @@ TEST(PatternReplace, Grouping2) simple_replace(find, replacement, input, strlen(input),&output, &output_sz); EXPECT_TRUE(output_sz>0); + EXPECT_TRUE(NULL==strstr(output, "中央空调")); + EXPECT_TRUE(NULL!=strstr(output, "中央Air conditioner")); + EXPECT_TRUE(NULL!=strstr(output, "家用立式空调")); + // EXPECT_STREQ(output, expect); printf("%s\n", output); free(output); @@ -112,6 +116,46 @@ TEST(PatternReplace, UTF8) free(output); return; } +TEST(PatternReplace, CaseInsensitive) +{ + const char* find="(?i)Abc(?-i)视频"; + const char* replacement="ABC短片"; + const char* input="欢迎来到 Facebook开始添加好友吧!他们的aBc视频、照片和帖子都会显示在这里。"; + char* output=NULL; + size_t output_sz=0; + + simple_replace(find, replacement, input, strlen(input),&output, &output_sz); + EXPECT_TRUE(output_sz>0); + EXPECT_TRUE(NULL==strstr(output, find)); + EXPECT_TRUE(NULL!=strstr(output, replacement)); + + printf("%s\n", output); + free(output); + return; +} + +TEST(PatternReplace, CaseInsensitiveRussian) +{ + const char* find="(?i)САМРУК-КАЗЫНА(?-i)"; + + const char* replacement="МММММММММ"; + const char* input="Как мы сообщали, 22 мая прошло заседание Совета по управлению Фондом национального \ + благосостояния \"Самрук-Казына\" под председательством Первого Президента Республики Казахстан – \ + Елбасы Нурсултана Назарбаева. Чуть более года назад была принята новая стратегия управления Фондом \ + на ближайшие десять лет, и председатель правления \"Самрук-Қазына\" Ахметжан Есимов докладывал Н. \ + Назарбаеву о том, как она выполняется. В распоряжении нашей редакции оказались некоторые детали,\ + о которых не сообщалось в СМИ ранее."; + char* output=NULL; + size_t output_sz=0; + + simple_replace(find, replacement, input, strlen(input),&output, &output_sz); + EXPECT_TRUE(output_sz>0); + EXPECT_TRUE(NULL==strstr(output, find)); + EXPECT_TRUE(NULL!=strstr(output, replacement)); + + free(output); + return; +} TEST(PatternInsert, CSS) { @@ -131,7 +175,7 @@ TEST(PatternInsert, CSS) free(input); } -TEST(PatternInsert, after_body) +TEST(PatternInsert, AfterBody) { const char* filename="./test_data/index_of__centos.html"; const char* custom = "var now=new Date();var year=now.getYear()+1900;var month=now.getMonth()+1;var date=now.getDate();var day=now.getDay();\ @@ -149,7 +193,7 @@ TEST(PatternInsert, after_body) free(output); } -TEST(PatternInsert, before_body) +TEST(PatternInsert, BeforeBody) { const char* filename="./test_data/index_of__centos.html"; const char* custom = "var now=new Date();var year=now.getYear()+1900;var month=now.getMonth()+1;var date=now.getDate();var day=now.getDay();\ |
