Browse Source

Merge pull request #10569 from ghalliday/issue18329

HPCC-18329 Only test chinese breakiterator semantics if ICU version >= 50

Reviewed-By: Attila Vamos <attila.vamos@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 7 years ago
parent
commit
eb6be86d71

+ 20 - 0
ecl/regress/icuversion.ecl

@@ -0,0 +1,20 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2017 HPCC Systems®.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+############################################################################## */
+
+import Std.Uni;
+Uni.version();
+(integer)Uni.Version();

+ 6 - 0
ecllibrary/std/Uni.ecl

@@ -462,4 +462,10 @@ EXPORT BOOLEAN StartsWith(unicode src, unicode pref, string form) :=
 EXPORT BOOLEAN EndsWith(unicode src, unicode suff, string form) :=
 	lib_unicodelib.UnicodeLib.UnicodeLocaleEndsWith(src, suff, form);
 
+/**
+ * Returns a string containing the version of icu being used to implement the unicode library.
+ */
+
+EXPORT STRING Version() := lib_unicodelib.UnicodeLib.UnicodeVersion();
+
 END;

+ 1 - 1
ecllibrary/teststd/uni/TestExcludeFirstWord.ecl

@@ -36,7 +36,7 @@ EXPORT TestExcludeFirstWord := MODULE
     EXPORT Test16 := ASSERT(Uni.ExcludeFirstWord(U'Cambió las niñas')+U'!' = U'las niñas!');
     //Check action on a string containing Chinese characters.
     //Translation: "I am a computer"
-    EXPORT Test17 := ASSERT(Uni.ExcludeFirstWord(U'我是電腦')+U'!' = U'電腦!');
+    EXPORT Test17 := ASSERT(((integer)Uni.Version() < 50) OR Uni.ExcludeFirstWord(U'我是電腦')+U'!' = U'電腦!'); // Chinese dictionary based iterators added in ICU 50
     //Check action on a string containing Modern Greek characters.
     //Translation: "Do you come here often?"
     EXPORT Test18 := ASSERT(Uni.ExcludeFirstWord(U' Έρχεσαι συχνά εδώ; ')+U'!' = U'συχνά εδώ; !');

+ 1 - 1
ecllibrary/teststd/uni/TestExcludeLastWord.ecl

@@ -36,7 +36,7 @@ EXPORT TestExcludeLastWord := MODULE
     EXPORT Test16 := ASSERT(Uni.ExcludeLastWord(U'El difunto cambió las niñas')+U'!' = U'El difunto cambió las !');
     //Check action on a string containing Chinese characters.
     //Translation: "I am a computer"
-    EXPORT Test17 := ASSERT(Uni.ExcludeLastWord(U'我是電腦')+U'!' = U'我是!');
+    EXPORT Test17 := ASSERT(((integer)Uni.Version() < 50) OR Uni.ExcludeLastWord(U'我是電腦')+U'!' = U'我是!'); // Chinese dictionary based iterators added in ICU 50
     //Check action on a string containing Modern Greek characters.
     //Translation: "Do you come here often?"
     EXPORT Test18 := ASSERT(Uni.ExcludeLastWord(U' Έρχεσαι συχνά εδώ; ')+U'!' = U' Έρχεσαι συχνά !');

+ 1 - 1
ecllibrary/teststd/uni/TestExcludeNthWord.ecl

@@ -74,7 +74,7 @@
     EXPORT Test42 := ASSERT(Uni.ExcludeNthWord(U'El difunto cambió las niñas',5)+U'!' = U'El difunto cambió las !');
     //Check action on a string containing Chinese characters.
     //Translation: "I am a computer" --> "I am"
-    EXPORT Test43 := ASSERT(Uni.ExcludeNthWord(U'我是電腦',2)+U'!' = U'我是!');
+    EXPORT Test43 := ASSERT(((integer)Uni.Version() < 50) OR Uni.ExcludeNthWord(U'我是電腦',2)+U'!' = U'我是!'); // Chinese dictionary based iterators added in ICU 50
     //Check action on a string containing Modern Greek characters.
     //Translation: "Do you come here often?" --> "come here often?"
     EXPORT Test44 := ASSERT(Uni.ExcludeNthWord(U' Έρχεσαι συχνά εδώ; ',1)+U'!' = U'συχνά εδώ; !');

+ 1 - 1
ecllibrary/teststd/uni/TestGetNthWord.ecl

@@ -65,7 +65,7 @@ EXPORT TestGetNthWord := MODULE
     EXPORT Test42 := ASSERT(Uni.GetNthWord(U'El difunto cambió las niñas',5)+U'!' = U'niñas!');
     //Check action on a string containing Chinese characters
     //Translation: "I am a computer" --> "computer"
-    EXPORT Test43 := ASSERT(Uni.GetNthWord(U'我是電腦',2)+U'!' = U'電腦!');
+    EXPORT Test43 := ASSERT(((integer)Uni.Version() < 50) OR Uni.GetNthWord(U'我是電腦',2)+U'!' = U'電腦!'); // Chinese dictionary based iterators added in ICU 50
     //Check action on a string containing Modern Greek characters
     //Translation: "Do you come here often?" --> "often"
     EXPORT Test44 := ASSERT(Uni.GetNthWord(U' Έρχεσαι συχνά εδώ; ',2)+U'!' = U'συχνά!');

+ 1 - 1
ecllibrary/teststd/uni/TestWordCount.ecl

@@ -36,7 +36,7 @@ EXPORT TestWordCount := MODULE
     EXPORT Test16 := ASSERT(Uni.WordCount(U'El difunto cambió las niñas') = 5);
     //Check action on a string containing Chinese characters.
     //Translation: "I am a computer"
-    EXPORT Test17 := ASSERT(Uni.WordCount(U'我是電腦') = 2);
+    EXPORT Test17 := ASSERT(((integer)Uni.Version() < 50) OR Uni.WordCount(U'我是電腦') = 2); // Chinese dictionary based iterators added in ICU 50
     //Check action on a string containing Modern Greek characters.
     //Translation: "Do you come here often?"
     EXPORT Test18 := ASSERT(Uni.WordCount(U' Έρχεσαι συχνά εδώ; ') = 3);

+ 12 - 0
plugins/unicodelib/unicodelib.cpp

@@ -87,6 +87,7 @@ static const char * EclDefinition =
 "  unicode UnicodeLocaleTranslate(const unicode text, unicode sear, unicode repl) :c,pure,entrypoint='ulUnicodeLocaleTranslate';\n"
 "  boolean UnicodeLocaleStartsWith(const unicode src, unicode pref, string form) :c,pure,entrypoint='ulUnicodeLocaleStartsWith';\n"
 "  boolean UnicodeLocaleEndsWith(const unicode src, const unicode suff, const string form) :c,pure,entrypoint='ulUnicodeLocaleEndsWith';\n"
+"  string UnicodeVersion():c,pure,entrypoint='ulUnicodeVersion';\n"
 "END;\n";
 
 static const char * compatibleVersions[] = {
@@ -1695,3 +1696,14 @@ UNICODELIB_API bool UNICODELIB_CALL ulUnicodeLocaleEndsWith(unsigned srcLen, UCh
     }
     return endsWith(pro, suf);
 }
+
+UNICODELIB_API void UNICODELIB_CALL ulUnicodeVersion(unsigned & tgtLen, char * & tgt)
+{
+    char version[U_MAX_VERSION_STRING_LENGTH];
+    UVersionInfo versionInfo;
+    u_getVersion(versionInfo);
+    u_versionToString(versionInfo, version);
+    tgtLen = strlen(version);
+    tgt = (char *)CTXMALLOC(parentCtx, tgtLen);
+    memcpy(tgt, version, tgtLen);
+}

+ 1 - 0
plugins/unicodelib/unicodelib.hpp

@@ -106,6 +106,7 @@ UNICODELIB_API void UNICODELIB_CALL ulUnicodeLocaleExcludeLastWord(unsigned & tg
 UNICODELIB_API void UNICODELIB_CALL ulUnicodeLocaleTranslate(unsigned & tgtLen, UChar * & tgt, unsigned textLen, UChar const * text, unsigned searLen, UChar const * sear, unsigned replLen, UChar * repl);
 UNICODELIB_API bool UNICODELIB_CALL ulUnicodeLocaleStartsWith(unsigned srcLen, UChar const * src, unsigned prefLen, UChar const * pref, unsigned formLen, char const * form);
 UNICODELIB_API bool UNICODELIB_CALL ulUnicodeLocaleEndsWith(unsigned srcLen, UChar const * src, unsigned suffLen, UChar const * suff, unsigned formLen, char const * form);
+UNICODELIB_API void UNICODELIB_CALL ulUnicodeVersion(unsigned & tgtLen, char * & tgt);
 }
 
 #endif