1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "text/Unicode.h" 18 19 #include "test/Test.h" 20 21 using ::testing::Each; 22 using ::testing::Eq; 23 using ::testing::ResultOf; 24 25 namespace aapt { 26 namespace text { 27 28 TEST(UnicodeTest, IsXidStart) { 29 std::u32string valid_input = U"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 30 EXPECT_THAT(valid_input, Each(ResultOf(IsXidStart, Eq(true)))); 31 32 std::u32string invalid_input = U"$;\'/<>+=-.{}[]()\\|?@#%^&*!~`\",1234567890_"; 33 EXPECT_THAT(invalid_input, Each(ResultOf(IsXidStart, Eq(false)))); 34 } 35 36 TEST(UnicodeTest, IsXidContinue) { 37 std::u32string valid_input = U"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"; 38 EXPECT_THAT(valid_input, Each(ResultOf(IsXidContinue, Eq(true)))); 39 40 std::u32string invalid_input = U"$;\'/<>+=-.{}[]()\\|?@#%^&*!~`\","; 41 EXPECT_THAT(invalid_input, Each(ResultOf(IsXidContinue, Eq(false)))); 42 } 43 44 TEST(UnicodeTest, IsJavaIdentifier) { 45 EXPECT_TRUE(IsJavaIdentifier("FBar_12")); 46 EXPECT_TRUE(IsJavaIdentifier("F$Bar")); 47 EXPECT_TRUE(IsJavaIdentifier("_FBar")); 48 EXPECT_TRUE(IsJavaIdentifier("$F$Bar")); 49 50 EXPECT_FALSE(IsJavaIdentifier("12FBar")); 51 EXPECT_FALSE(IsJavaIdentifier(".Hello")); 52 } 53 54 TEST(UnicodeTest, IsValidResourceEntryName) { 55 EXPECT_TRUE(IsJavaIdentifier("FBar")); 56 EXPECT_TRUE(IsValidResourceEntryName("FBar_12")); 57 EXPECT_TRUE(IsValidResourceEntryName("F.Bar")); 58 EXPECT_TRUE(IsValidResourceEntryName("F-Bar")); 59 EXPECT_TRUE(IsValidResourceEntryName("_FBar")); 60 61 EXPECT_FALSE(IsValidResourceEntryName("12FBar")); 62 EXPECT_FALSE(IsValidResourceEntryName("F$Bar")); 63 EXPECT_FALSE(IsValidResourceEntryName("F/Bar")); 64 EXPECT_FALSE(IsValidResourceEntryName("F:Bar")); 65 EXPECT_FALSE(IsValidResourceEntryName("F;Bar")); 66 EXPECT_FALSE(IsValidResourceEntryName("0_resource_name_obfuscated")); 67 } 68 69 } // namespace text 70 } // namespace aapt 71