• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Libphonenumber Authors
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 package com.google.i18n.phonenumbers;
18 
19 import junit.framework.TestCase;
20 
21 /**
22  * Unittests for LRU Cache for compiled regular expressions used by the libphonenumbers libary.
23  *
24  * @author Shaopeng Jia
25  */
26 
27 public class RegexCacheTest extends TestCase {
28   private RegexCache regexCache;
29 
RegexCacheTest()30   public RegexCacheTest() {
31     regexCache = new RegexCache(2);
32   }
33 
testRegexInsertion()34   public void testRegexInsertion() {
35     final String regex1 = "[1-5]";
36     final String regex2 = "(?:12|34)";
37     final String regex3 = "[1-3][58]";
38 
39     regexCache.getPatternForRegex(regex1);
40     assertTrue(regexCache.containsRegex(regex1));
41 
42     regexCache.getPatternForRegex(regex2);
43     assertTrue(regexCache.containsRegex(regex2));
44     assertTrue(regexCache.containsRegex(regex1));
45 
46     regexCache.getPatternForRegex(regex1);
47     assertTrue(regexCache.containsRegex(regex1));
48 
49     regexCache.getPatternForRegex(regex3);
50     assertTrue(regexCache.containsRegex(regex3));
51 
52     assertFalse(regexCache.containsRegex(regex2));
53     assertTrue(regexCache.containsRegex(regex1));
54   }
55 }
56