|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | +#include <gtest/gtest.h> |
| 15 | + |
| 16 | +#include "presto_cpp/main/connectors/hive/functions/HiveFunctionRegistration.h" |
| 17 | +#include "velox/functions/prestosql/tests/utils/FunctionBaseTest.h" |
| 18 | + |
| 19 | +namespace facebook::presto::functions::test { |
| 20 | +class InitcapTest : public velox::functions::test::FunctionBaseTest { |
| 21 | + protected: |
| 22 | + static void SetUpTestCase() { |
| 23 | + velox::functions::test::FunctionBaseTest::SetUpTestCase(); |
| 24 | + facebook::presto::hive::functions::registerHiveNativeFunctions(); |
| 25 | + } |
| 26 | +}; |
| 27 | + |
| 28 | +TEST_F(InitcapTest, initcap) { |
| 29 | + const auto initcap = [&](const std::optional<std::string>& value) { |
| 30 | + return evaluateOnce<std::string>("\"hive.default.initcap\"(c0)", value); |
| 31 | + }; |
| 32 | + |
| 33 | + // Unicode only. |
| 34 | + EXPECT_EQ( |
| 35 | + initcap("àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ"), |
| 36 | + "Àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ"); |
| 37 | + EXPECT_EQ(initcap("αβγδεζηθικλμνξοπρςστυφχψ"), "Αβγδεζηθικλμνξοπρςστυφχψ"); |
| 38 | + // Mix of ascii and unicode. |
| 39 | + EXPECT_EQ(initcap("αβγδεζ world"), "Αβγδεζ World"); |
| 40 | + EXPECT_EQ(initcap("αfoo wβ"), "Αfoo Wβ"); |
| 41 | + // Ascii only. |
| 42 | + EXPECT_EQ(initcap("hello world"), "Hello World"); |
| 43 | + EXPECT_EQ(initcap("HELLO WORLD"), "Hello World"); |
| 44 | + EXPECT_EQ(initcap("1234"), "1234"); |
| 45 | + EXPECT_EQ(initcap("a b c d"), "A B C D"); |
| 46 | + EXPECT_EQ(initcap("abcd"), "Abcd"); |
| 47 | + // Numbers. |
| 48 | + EXPECT_EQ(initcap("123"), "123"); |
| 49 | + EXPECT_EQ(initcap("1abc"), "1abc"); |
| 50 | + // Edge cases. |
| 51 | + EXPECT_EQ(initcap(""), ""); |
| 52 | + EXPECT_EQ(initcap(std::nullopt), std::nullopt); |
| 53 | + |
| 54 | + // Test with various whitespace characters |
| 55 | + EXPECT_EQ(initcap("YQ\tY"), "Yq\tY"); |
| 56 | + EXPECT_EQ(initcap("YQ\nY"), "Yq\nY"); |
| 57 | + EXPECT_EQ(initcap("YQ\rY"), "Yq\rY"); |
| 58 | + EXPECT_EQ(initcap("hello\tworld\ntest"), "Hello\tWorld\nTest"); |
| 59 | + EXPECT_EQ(initcap("foo\r\nbar"), "Foo\r\nBar"); |
| 60 | + |
| 61 | + // Test with multiple consecutive whitespaces |
| 62 | + EXPECT_EQ(initcap("hello world"), "Hello World"); |
| 63 | + EXPECT_EQ(initcap("a b c"), "A B C"); |
| 64 | + EXPECT_EQ(initcap("test\t\tvalue"), "Test\t\tValue"); |
| 65 | + EXPECT_EQ(initcap("line\n\n\nbreak"), "Line\n\n\nBreak"); |
| 66 | + |
| 67 | + // Test with leading and trailing whitespaces |
| 68 | + EXPECT_EQ(initcap(" hello"), " Hello"); |
| 69 | + EXPECT_EQ(initcap("world "), "World "); |
| 70 | + EXPECT_EQ(initcap(" spaces "), " Spaces "); |
| 71 | + EXPECT_EQ(initcap("\thello"), "\tHello"); |
| 72 | + EXPECT_EQ(initcap("\nworld"), "\nWorld"); |
| 73 | + EXPECT_EQ(initcap("test\n"), "Test\n"); |
| 74 | + |
| 75 | + // Test with mixed whitespace types |
| 76 | + EXPECT_EQ(initcap("hello \t\nworld"), "Hello \t\nWorld"); |
| 77 | + EXPECT_EQ(initcap("a\tb\nc\rd"), "A\tB\nC\rD"); |
| 78 | + EXPECT_EQ(initcap(" \t\n "), " \t\n "); |
| 79 | +} |
| 80 | +} // namespace facebook::presto::functions::test |
0 commit comments