• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TEST(UnicodeTest,IsXidStart)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 
TEST(UnicodeTest,IsXidContinue)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 
TEST(UnicodeTest,IsJavaIdentifier)44 TEST(UnicodeTest, IsJavaIdentifier) {
45   EXPECT_TRUE(IsJavaIdentifier("FøøBar_12"));
46   EXPECT_TRUE(IsJavaIdentifier("Føø$Bar"));
47 
48   EXPECT_FALSE(IsJavaIdentifier("12FøøBar"));
49   EXPECT_FALSE(IsJavaIdentifier("_FøøBar"));
50   EXPECT_FALSE(IsJavaIdentifier("$Føø$Bar"));
51 }
52 
TEST(UnicodeTest,IsValidResourceEntryName)53 TEST(UnicodeTest, IsValidResourceEntryName) {
54   EXPECT_TRUE(IsJavaIdentifier("FøøBar"));
55   EXPECT_TRUE(IsValidResourceEntryName("FøøBar_12"));
56   EXPECT_TRUE(IsValidResourceEntryName("Føø.Bar"));
57   EXPECT_TRUE(IsValidResourceEntryName("Føø-Bar"));
58   EXPECT_TRUE(IsValidResourceEntryName("_FøøBar"));
59 
60   EXPECT_FALSE(IsValidResourceEntryName("12FøøBar"));
61   EXPECT_FALSE(IsValidResourceEntryName("Føø$Bar"));
62   EXPECT_FALSE(IsValidResourceEntryName("Føø/Bar"));
63   EXPECT_FALSE(IsValidResourceEntryName("Føø:Bar"));
64   EXPECT_FALSE(IsValidResourceEntryName("Føø;Bar"));
65 }
66 
67 }  // namespace text
68 }  // namespace aapt
69