blob: d47fb282bc0a3f8451bd3fe1f7d3cfb5f914eb36 [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"));
47
48 EXPECT_FALSE(IsJavaIdentifier("12FøøBar"));
49 EXPECT_FALSE(IsJavaIdentifier("_FøøBar"));
50 EXPECT_FALSE(IsJavaIdentifier("$Føø$Bar"));
51}
52
53TEST(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