// Path: src/main/java/de/thetaphi/forbiddenapis/AsmUtils.java
// public static Pattern glob2Pattern(String... globs) {
//   final StringBuilder regex = new StringBuilder();
//   boolean needOr = false;
//   for (String glob : globs) {
//     if (needOr) {
//       regex.append('|');
//     }
//     int i = 0, len = glob.length();
//     while (i < len) {
//       char c = glob.charAt(i++);
//       switch (c) {
//         case '*':
//           if (i < len && glob.charAt(i) == '*') {
//             // crosses package boundaries
//             regex.append(".*");
//             i++;
//           } else {
//             // do not cross package boundaries
//             regex.append("[^.]*");
//           }
//           break;
//             
//         case '?':
//           // do not cross package boundaries
//           regex.append("[^.]");
//           break;
//           
//         default:
//           if (isRegexMeta(c)) {
//             regex.append('\\');
//           }
//           regex.append(c);
//       }
//     }
//     needOr = true;
//   }
//   return Pattern.compile(regex.toString(), 0);
// }
// 
// Path: src/main/java/de/thetaphi/forbiddenapis/AsmUtils.java
// public static boolean isGlob(String s) {
//   return s.indexOf('*') >= 0 || s.indexOf('?') >= 0;
// }
// 
// Path: src/main/java/de/thetaphi/forbiddenapis/AsmUtils.java
// public static boolean isPortableRuntimeClass(String className) {
//   return PORTABLE_RUNTIME_PACKAGE_PATTERN.matcher(className).matches();
// }
// 
// Path: src/main/java/de/thetaphi/forbiddenapis/AsmUtils.java
// public static boolean isRuntimeModule(String module) {
//   return module != null && RUNTIME_MODULES_PATTERN.matcher(module).matches();
// }


import static de.thetaphi.forbiddenapis.AsmUtils.glob2Pattern;
import static de.thetaphi.forbiddenapis.AsmUtils.isGlob;
import static de.thetaphi.forbiddenapis.AsmUtils.isPortableRuntimeClass;
import static de.thetaphi.forbiddenapis.AsmUtils.isRuntimeModule;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.regex.Pattern;
import org.junit.Test;
/*
 * (C) Copyright Uwe Schindler (Generics Policeman) and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.thetaphi.forbiddenapis;




public final class AsmUtilsTest {

  @Test
  public void testIsGlob() {
    assertTrue(isGlob("a.b.c.*"));
    assertTrue(isGlob("sun.**"));
    assertTrue(isGlob("a?bc.x"));
    assertFalse(isGlob(Object.class.getName()));
    assertFalse(isGlob(getClass().getName()));
    assertFalse(isGlob("sun.misc.Unsafe$1"));
  }

  @Test
  public void testGlob() {
    Pattern pat = glob2Pattern("a.b.c.*");
    assertTrue(pat.matcher("a.b.c.d").matches());
    assertTrue(pat.matcher("a.b.c.def").matches());
    assertFalse(pat.matcher("a.b.c").matches());
    assertFalse(pat.matcher("a.b.c.d.e").matches());
    
    pat = glob2Pattern("a.b.c.**");
    assertTrue(pat.matcher("a.b.c.d").matches());
    assertTrue(pat.matcher("a.b.c.def").matches());
// Path: src/main/java/de/thetaphi/forbiddenapis/AsmUtils.java
// public static Pattern glob2Pattern(String... globs) {
//   final StringBuilder regex = new StringBuilder();
//   boolean needOr = false;
//   for (String glob : globs) {
//     if (needOr) {
//       regex.append('|');
//     }
//     int i = 0, len = glob.length();
//     while (i < len) {
//       char c = glob.charAt(i++);
//       switch (c) {
//         case '*':
//           if (i < len && glob.charAt(i) == '*') {
//             // crosses package boundaries
//             regex.append(".*");
//             i++;
//           } else {
//             // do not cross package boundaries
//             regex.append("[^.]*");
//           }
//           break;
//             
//         case '?':
//           // do not cross package boundaries
//           regex.append("[^.]");
//           break;
//           
//         default:
//           if (isRegexMeta(c)) {
//             regex.append('\\');
//           }
//           regex.append(c);
//       }
//     }
//     needOr = true;
//   }
//   return Pattern.compile(regex.toString(), 0);
// }
// 
// Path: src/main/java/de/thetaphi/forbiddenapis/AsmUtils.java
// public static boolean isGlob(String s) {
//   return s.indexOf('*') >= 0 || s.indexOf('?') >= 0;
// }
// 
// Path: src/main/java/de/thetaphi/forbiddenapis/AsmUtils.java
// public static boolean isPortableRuntimeClass(String className) {
//   return PORTABLE_RUNTIME_PACKAGE_PATTERN.matcher(className).matches();
// }
// 
// Path: src/main/java/de/thetaphi/forbiddenapis/AsmUtils.java
// public static boolean isRuntimeModule(String module) {
//   return module != null && RUNTIME_MODULES_PATTERN.matcher(module).matches();
// }


// Path: src/test/java/de/thetaphi/forbiddenapis/AsmUtilsTest.java
import static de.thetaphi.forbiddenapis.AsmUtils.glob2Pattern;
import static de.thetaphi.forbiddenapis.AsmUtils.isGlob;
import static de.thetaphi.forbiddenapis.AsmUtils.isPortableRuntimeClass;
import static de.thetaphi.forbiddenapis.AsmUtils.isRuntimeModule;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.regex.Pattern;
import org.junit.Test;

/*
 * (C) Copyright Uwe Schindler (Generics Policeman) and others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.thetaphi.forbiddenapis;




public final class AsmUtilsTest {

  @Test
  public void testIsGlob() {
    assertTrue(isGlob("a.b.c.*"));
    assertTrue(isGlob("sun.**"));
    assertTrue(isGlob("a?bc.x"));
    assertFalse(isGlob(Object.class.getName()));
    assertFalse(isGlob(getClass().getName()));
    assertFalse(isGlob("sun.misc.Unsafe$1"));
  }

  @Test
  public void testGlob() {
    Pattern pat = glob2Pattern("a.b.c.*");
    assertTrue(pat.matcher("a.b.c.d").matches());
    assertTrue(pat.matcher("a.b.c.def").matches());
    assertFalse(pat.matcher("a.b.c").matches());
    assertFalse(pat.matcher("a.b.c.d.e").matches());
    
    pat = glob2Pattern("a.b.c.**");
    assertTrue(pat.matcher("a.b.c.d").matches());
    assertTrue(pat.matcher("a.b.c.def").matches());
    assertTrue(pat.matcher("a.b.c.d.e").matches());