// Path: instrumenter/src/main/java/com/offbynull/coroutines/instrumenter/asm/SearchUtils.java
// public static List<AbstractInsnNode> searchForOpcodes(InsnList insnList, int ... opcodes) {
//     Validate.notNull(insnList);
//     Validate.notNull(opcodes);
//     Validate.isTrue(opcodes.length > 0);
//         
//     List<AbstractInsnNode> ret = new LinkedList<>();
//         
//     Set<Integer> opcodeSet = new HashSet<>();
//     Arrays.stream(opcodes).forEach((x) -> opcodeSet.add(x));
//         
//     Iterator<AbstractInsnNode> it = insnList.iterator();
//     while (it.hasNext()) {
//         AbstractInsnNode insnNode = it.next();
//         if (opcodeSet.contains(insnNode.getOpcode())) {
//             ret.add(insnNode);
//         }
//     }
//         
//     return ret;
// }
// 
// Path: instrumenter/src/test/java/com/offbynull/coroutines/instrumenter/testhelpers/TestUtils.java
// public static Map<String, byte[]> readZipFromResource(String path) throws IOException {
//     ClassLoader cl = ClassLoader.getSystemClassLoader();
//     URL url = cl.getResource(path);
//     Validate.isTrue(url != null);
//         
//     Map<String, byte[]> ret = new LinkedHashMap<>();
//         
//     try (InputStream is = url.openStream();
//             ZipArchiveInputStream zais = new ZipArchiveInputStream(is)) {
//         ZipArchiveEntry entry;
//         while ((entry = zais.getNextZipEntry()) != null) {
//             ret.put(entry.getName(), IOUtils.toByteArray(zais));
//         }
//     }
//         
//     return ret;
// }


import static com.offbynull.coroutines.instrumenter.asm.SearchUtils.searchForOpcodes;
import static com.offbynull.coroutines.instrumenter.testhelpers.TestUtils.readZipFromResource;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
package com.offbynull.coroutines.instrumenter.asm;


public class SimpleClassNodeTest {

    @Test
    public void mustNotFindAnyJsrInstructions() throws Exception {
        byte[] input = readZipFromResource("JsrExceptionSuspendTest.zip").get("JsrExceptionSuspendTest.class");
        
        ClassReader cr = new ClassReader(input);
        ClassNode classNode = new SimpleClassNode();
        cr.accept(classNode, 0);
        
        for (MethodNode methodNode : classNode.methods) {
// Path: instrumenter/src/main/java/com/offbynull/coroutines/instrumenter/asm/SearchUtils.java
// public static List<AbstractInsnNode> searchForOpcodes(InsnList insnList, int ... opcodes) {
//     Validate.notNull(insnList);
//     Validate.notNull(opcodes);
//     Validate.isTrue(opcodes.length > 0);
//         
//     List<AbstractInsnNode> ret = new LinkedList<>();
//         
//     Set<Integer> opcodeSet = new HashSet<>();
//     Arrays.stream(opcodes).forEach((x) -> opcodeSet.add(x));
//         
//     Iterator<AbstractInsnNode> it = insnList.iterator();
//     while (it.hasNext()) {
//         AbstractInsnNode insnNode = it.next();
//         if (opcodeSet.contains(insnNode.getOpcode())) {
//             ret.add(insnNode);
//         }
//     }
//         
//     return ret;
// }
// 
// Path: instrumenter/src/test/java/com/offbynull/coroutines/instrumenter/testhelpers/TestUtils.java
// public static Map<String, byte[]> readZipFromResource(String path) throws IOException {
//     ClassLoader cl = ClassLoader.getSystemClassLoader();
//     URL url = cl.getResource(path);
//     Validate.isTrue(url != null);
//         
//     Map<String, byte[]> ret = new LinkedHashMap<>();
//         
//     try (InputStream is = url.openStream();
//             ZipArchiveInputStream zais = new ZipArchiveInputStream(is)) {
//         ZipArchiveEntry entry;
//         while ((entry = zais.getNextZipEntry()) != null) {
//             ret.put(entry.getName(), IOUtils.toByteArray(zais));
//         }
//     }
//         
//     return ret;
// }


// Path: instrumenter/src/test/java/com/offbynull/coroutines/instrumenter/asm/SimpleClassNodeTest.java
import static com.offbynull.coroutines.instrumenter.asm.SearchUtils.searchForOpcodes;
import static com.offbynull.coroutines.instrumenter.testhelpers.TestUtils.readZipFromResource;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;

package com.offbynull.coroutines.instrumenter.asm;


public class SimpleClassNodeTest {

    @Test
    public void mustNotFindAnyJsrInstructions() throws Exception {
        byte[] input = readZipFromResource("JsrExceptionSuspendTest.zip").get("JsrExceptionSuspendTest.class");
        
        ClassReader cr = new ClassReader(input);
        ClassNode classNode = new SimpleClassNode();
        cr.accept(classNode, 0);
        
        for (MethodNode methodNode : classNode.methods) {
            assertTrue(searchForOpcodes(methodNode.instructions, Opcodes.JSR).isEmpty());