1 /* 2 * Copyright (C) 2023 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 package com.android.launcher3.tapl; 17 18 import static org.junit.Assert.assertFalse; 19 import static org.junit.Assert.assertTrue; 20 21 import org.junit.Test; 22 23 public class TaplUtilityTest { 24 25 @Test testMakeMultilinePattern()26 public void testMakeMultilinePattern() { 27 // Original title will match. 28 assertTrue(AppIcon.makeMultilinePattern("Play Store") 29 .matcher("Play Store").matches()); 30 assertTrue(AppIcon.makeMultilinePattern("PlayStore") 31 .matcher("PlayStore").matches()); 32 33 // Original title with whitespace added will match. 34 assertTrue(AppIcon.makeMultilinePattern("PlayStore") 35 .matcher("Play\nStore").matches()); 36 assertTrue(AppIcon.makeMultilinePattern("PlayStore") 37 .matcher("Play Store").matches()); 38 // Original title with whitespace removed will also match. 39 assertTrue(AppIcon.makeMultilinePattern("Play Store") 40 .matcher("PlayStore").matches()); 41 // Or whitespace replaced with a different kind of whitespace (both of above conditions). 42 assertTrue(AppIcon.makeMultilinePattern("Play Store") 43 .matcher("Play\nStore").matches()); 44 assertTrue(AppIcon.makeMultilinePattern("Play Store") 45 .matcher("Play \n Store").matches()); 46 47 // Any non-whitespace character added to the title will not match. 48 assertFalse(AppIcon.makeMultilinePattern("Play Store") 49 .matcher("Play Store has 7 notifications").matches()); 50 assertFalse(AppIcon.makeMultilinePattern("Play Store") 51 .matcher("Play Store!").matches()); 52 // Title is case-sensitive. 53 assertFalse(AppIcon.makeMultilinePattern("Play Store") 54 .matcher("play store").matches()); 55 assertFalse(AppIcon.makeMultilinePattern("Play Store") 56 .matcher("play store").matches()); 57 // Removing non whitespace characters will not match. 58 assertFalse(AppIcon.makeMultilinePattern("Play Store") 59 .matcher("").matches()); 60 assertFalse(AppIcon.makeMultilinePattern("Play Store") 61 .matcher("Play Stor").matches()); 62 assertFalse(AppIcon.makeMultilinePattern("Play Store") 63 .matcher("Play").matches()); 64 } 65 } 66