Adam Lesinski | 66ea840 | 2017-06-28 11:44:11 -0700 | [diff] [blame] | 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("FøøBar_12")); |
| 46 | EXPECT_TRUE(IsJavaIdentifier("Føø$Bar")); |
Adam Lesinski | 96ea08f | 2017-11-06 10:44:46 -0800 | [diff] [blame] | 47 | EXPECT_TRUE(IsJavaIdentifier("_FøøBar")); |
| 48 | EXPECT_TRUE(IsJavaIdentifier("$Føø$Bar")); |
Adam Lesinski | 66ea840 | 2017-06-28 11:44:11 -0700 | [diff] [blame] | 49 | |
| 50 | EXPECT_FALSE(IsJavaIdentifier("12FøøBar")); |
Adam Lesinski | 96ea08f | 2017-11-06 10:44:46 -0800 | [diff] [blame] | 51 | EXPECT_FALSE(IsJavaIdentifier(".Hello")); |
Adam Lesinski | 66ea840 | 2017-06-28 11:44:11 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | TEST(UnicodeTest, IsValidResourceEntryName) { |
| 55 | EXPECT_TRUE(IsJavaIdentifier("FøøBar")); |
| 56 | EXPECT_TRUE(IsValidResourceEntryName("FøøBar_12")); |
| 57 | EXPECT_TRUE(IsValidResourceEntryName("Føø.Bar")); |
| 58 | EXPECT_TRUE(IsValidResourceEntryName("Føø-Bar")); |
| 59 | EXPECT_TRUE(IsValidResourceEntryName("_FøøBar")); |
| 60 | |
| 61 | EXPECT_FALSE(IsValidResourceEntryName("12FøøBar")); |
| 62 | EXPECT_FALSE(IsValidResourceEntryName("Føø$Bar")); |
| 63 | EXPECT_FALSE(IsValidResourceEntryName("Føø/Bar")); |
| 64 | EXPECT_FALSE(IsValidResourceEntryName("Føø:Bar")); |
| 65 | EXPECT_FALSE(IsValidResourceEntryName("Føø;Bar")); |
Luke Nicholson | b064330 | 2017-12-01 15:29:03 -0800 | [diff] [blame] | 66 | EXPECT_FALSE(IsValidResourceEntryName("0_resource_name_obfuscated")); |
Adam Lesinski | 66ea840 | 2017-06-28 11:44:11 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | } // namespace text |
| 70 | } // namespace aapt |