blob: 16bc2e84224a19f137a10e376204706476bcfcd5 [file] [log] [blame]
Adam Lesinski66ea8402017-06-28 11:44:11 -07001/*
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
21using ::testing::Each;
22using ::testing::Eq;
23using ::testing::ResultOf;
24
25namespace aapt {
26namespace text {
27
28TEST(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
36TEST(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
44TEST(UnicodeTest, IsJavaIdentifier) {
45 EXPECT_TRUE(IsJavaIdentifier("FøøBar_12"));
46 EXPECT_TRUE(IsJavaIdentifier("Føø$Bar"));
Adam Lesinski96ea08f2017-11-06 10:44:46 -080047 EXPECT_TRUE(IsJavaIdentifier("_FøøBar"));
48 EXPECT_TRUE(IsJavaIdentifier("$Føø$Bar"));
Adam Lesinski66ea8402017-06-28 11:44:11 -070049
50 EXPECT_FALSE(IsJavaIdentifier("12FøøBar"));
Adam Lesinski96ea08f2017-11-06 10:44:46 -080051 EXPECT_FALSE(IsJavaIdentifier(".Hello"));
Adam Lesinski66ea8402017-06-28 11:44:11 -070052}
53
54TEST(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 Nicholsonb0643302017-12-01 15:29:03 -080066 EXPECT_FALSE(IsValidResourceEntryName("0_resource_name_obfuscated"));
Adam Lesinski66ea8402017-06-28 11:44:11 -070067}
68
69} // namespace text
70} // namespace aapt