41 import java.nio.file.Path; 42 import java.nio.file.Paths; 43 import java.util.Collections; 44 import java.util.List; 45 import java.util.function.Predicate; 46 import java.util.stream.Collectors; 47 import java.util.stream.Stream; 48 49 import org.testng.annotations.Test; 50 51 @Test 52 public class CommandCompletionTest extends ReplToolTesting { 53 54 public void testCommand() { 55 assertCompletion("/deb|", false); 56 assertCompletion("/re|", false, "/reload ", "/reset ", "/retain "); 57 assertCompletion("/h|", false, "/help ", "/history "); 58 } 59 60 public void testList() { 61 test(false, new String[] {"-nostartup"}, 62 a -> assertCompletion(a, "/l|", false, "/list "), 63 a -> assertCompletion(a, "/list |", false, "-all ", "-history ", "-start "), 64 a -> assertCompletion(a, "/list -h|", false, "-history "), 65 a -> assertCompletion(a, "/list q|", false), 66 a -> assertVariable(a, "int", "xray"), 67 a -> assertCompletion(a, "/list |", false, "-all ", "-history ", "-start ", "1", "xray"), 68 a -> assertCompletion(a, "/list x|", false, "xray") 69 ); 70 } 71 72 public void testDrop() { 73 test(false, new String[] {"-nostartup"}, 74 a -> assertCompletion(a, "/d|", false, "/drop "), 75 a -> assertClass(a, "class cTest {}", "class", "cTest"), 76 a -> assertMethod(a, "int mTest() { return 0; }", "()I", "mTest"), 77 a -> assertVariable(a, "int", "fTest"), 78 a -> assertCompletion(a, "/drop |", false, "1", "2", "3", "cTest", "fTest", "mTest"), 79 a -> assertCompletion(a, "/drop f|", false, "fTest") 80 ); 81 } 82 83 public void testEdit() { 84 test(false, new String[]{"-nostartup"}, 85 a -> assertCompletion(a, "/e|", false, "/edit ", "/exit "), 86 a -> assertCompletion(a, "/ed|", false, "/edit "), 87 a -> assertClass(a, "class cTest {}", "class", "cTest"), 88 a -> assertMethod(a, "int mTest() { return 0; }", "()I", "mTest"), 89 a -> assertVariable(a, "int", "fTest"), 90 a -> assertCompletion(a, "/edit |", false, "1", "2", "3", "cTest", "fTest", "mTest"), 91 a -> assertCompletion(a, "/edit f|", false, "fTest") 92 ); 93 } 94 95 public void testOpen() throws IOException { 96 Compiler compiler = new Compiler(); 97 assertCompletion("/o|", false, "/open "); 98 List<String> p1 = listFiles(Paths.get("")); 99 FileSystems.getDefault().getRootDirectories().forEach(s -> p1.add(s.toString())); 100 Collections.sort(p1); 101 assertCompletion("/open |", false, p1.toArray(new String[p1.size()])); 102 Path classDir = compiler.getClassDir(); 103 List<String> p2 = listFiles(classDir); 104 assertCompletion("/open " + classDir + "/|", false, p2.toArray(new String[p2.size()])); | 41 import java.nio.file.Path; 42 import java.nio.file.Paths; 43 import java.util.Collections; 44 import java.util.List; 45 import java.util.function.Predicate; 46 import java.util.stream.Collectors; 47 import java.util.stream.Stream; 48 49 import org.testng.annotations.Test; 50 51 @Test 52 public class CommandCompletionTest extends ReplToolTesting { 53 54 public void testCommand() { 55 assertCompletion("/deb|", false); 56 assertCompletion("/re|", false, "/reload ", "/reset ", "/retain "); 57 assertCompletion("/h|", false, "/help ", "/history "); 58 } 59 60 public void testList() { 61 test(false, new String[] {"--no-startup"}, 62 a -> assertCompletion(a, "/l|", false, "/list "), 63 a -> assertCompletion(a, "/list |", false, "-all ", "-history ", "-start "), 64 a -> assertCompletion(a, "/list -h|", false, "-history "), 65 a -> assertCompletion(a, "/list q|", false), 66 a -> assertVariable(a, "int", "xray"), 67 a -> assertCompletion(a, "/list |", false, "-all ", "-history ", "-start ", "1", "xray"), 68 a -> assertCompletion(a, "/list x|", false, "xray") 69 ); 70 } 71 72 public void testDrop() { 73 test(false, new String[] {"--no-startup"}, 74 a -> assertCompletion(a, "/d|", false, "/drop "), 75 a -> assertClass(a, "class cTest {}", "class", "cTest"), 76 a -> assertMethod(a, "int mTest() { return 0; }", "()I", "mTest"), 77 a -> assertVariable(a, "int", "fTest"), 78 a -> assertCompletion(a, "/drop |", false, "1", "2", "3", "cTest", "fTest", "mTest"), 79 a -> assertCompletion(a, "/drop f|", false, "fTest") 80 ); 81 } 82 83 public void testEdit() { 84 test(false, new String[]{"--no-startup"}, 85 a -> assertCompletion(a, "/e|", false, "/edit ", "/exit "), 86 a -> assertCompletion(a, "/ed|", false, "/edit "), 87 a -> assertClass(a, "class cTest {}", "class", "cTest"), 88 a -> assertMethod(a, "int mTest() { return 0; }", "()I", "mTest"), 89 a -> assertVariable(a, "int", "fTest"), 90 a -> assertCompletion(a, "/edit |", false, "1", "2", "3", "cTest", "fTest", "mTest"), 91 a -> assertCompletion(a, "/edit f|", false, "fTest") 92 ); 93 } 94 95 public void testOpen() throws IOException { 96 Compiler compiler = new Compiler(); 97 assertCompletion("/o|", false, "/open "); 98 List<String> p1 = listFiles(Paths.get("")); 99 FileSystems.getDefault().getRootDirectories().forEach(s -> p1.add(s.toString())); 100 Collections.sort(p1); 101 assertCompletion("/open |", false, p1.toArray(new String[p1.size()])); 102 Path classDir = compiler.getClassDir(); 103 List<String> p2 = listFiles(classDir); 104 assertCompletion("/open " + classDir + "/|", false, p2.toArray(new String[p2.size()])); |