langtools/test/jdk/jshell/KullaTesting.java
changeset 41865 3ef02797070d
parent 41858 5843b57ce3a6
child 42969 a48d4f74d322
equal deleted inserted replaced
41864:f7dbab23003a 41865:3ef02797070d
    70 import jdk.jshell.UnresolvedReferenceException;
    70 import jdk.jshell.UnresolvedReferenceException;
    71 import org.testng.annotations.AfterMethod;
    71 import org.testng.annotations.AfterMethod;
    72 import org.testng.annotations.BeforeMethod;
    72 import org.testng.annotations.BeforeMethod;
    73 
    73 
    74 import jdk.jshell.Diag;
    74 import jdk.jshell.Diag;
       
    75 
    75 import static java.util.stream.Collectors.toList;
    76 import static java.util.stream.Collectors.toList;
    76 import static java.util.stream.Collectors.toSet;
    77 import static java.util.stream.Collectors.toSet;
       
    78 
    77 import static jdk.jshell.Snippet.Status.*;
    79 import static jdk.jshell.Snippet.Status.*;
    78 import static org.testng.Assert.*;
    80 import static org.testng.Assert.*;
    79 import static jdk.jshell.Snippet.SubKind.METHOD_SUBKIND;
    81 import static jdk.jshell.Snippet.SubKind.METHOD_SUBKIND;
       
    82 import jdk.jshell.SourceCodeAnalysis.Documentation;
    80 
    83 
    81 public class KullaTesting {
    84 public class KullaTesting {
    82 
    85 
    83     public static final String IGNORE_VALUE = "<ignore-value>";
    86     public static final String IGNORE_VALUE = "<ignore-value>";
    84     public static final Class<? extends Throwable> IGNORE_EXCEPTION = (new Throwable() {}).getClass();
    87     public static final Class<? extends Throwable> IGNORE_EXCEPTION = (new Throwable() {}).getClass();
   944         } catch (Exception ex) {
   947         } catch (Exception ex) {
   945             throw new AssertionError("Cannot wait for indexing end.", ex);
   948             throw new AssertionError("Cannot wait for indexing end.", ex);
   946         }
   949         }
   947     }
   950     }
   948 
   951 
   949     public void assertDocumentation(String code, String... expected) {
   952     public void assertSignature(String code, String... expected) {
   950         int cursor =  code.indexOf('|');
   953         int cursor =  code.indexOf('|');
   951         code = code.replace("|", "");
   954         code = code.replace("|", "");
   952         assertTrue(cursor > -1, "'|' expected, but not found in: " + code);
   955         assertTrue(cursor > -1, "'|' expected, but not found in: " + code);
   953         String documentation = getAnalysis().documentation(code, cursor);
   956         List<Documentation> documentation = getAnalysis().documentation(code, cursor, false);
   954         Set<String> docSet = Stream.of(documentation.split("\r?\n")).collect(Collectors.toSet());
   957         Set<String> docSet = documentation.stream().map(doc -> doc.signature()).collect(Collectors.toSet());
       
   958         Set<String> expectedSet = Stream.of(expected).collect(Collectors.toSet());
       
   959         assertEquals(docSet, expectedSet, "Input: " + code);
       
   960     }
       
   961 
       
   962     public void assertJavadoc(String code, String... expected) {
       
   963         int cursor =  code.indexOf('|');
       
   964         code = code.replace("|", "");
       
   965         assertTrue(cursor > -1, "'|' expected, but not found in: " + code);
       
   966         List<Documentation> documentation = getAnalysis().documentation(code, cursor, true);
       
   967         Set<String> docSet = documentation.stream()
       
   968                                           .map(doc -> doc.signature() + "\n" + doc.javadoc())
       
   969                                           .collect(Collectors.toSet());
   955         Set<String> expectedSet = Stream.of(expected).collect(Collectors.toSet());
   970         Set<String> expectedSet = Stream.of(expected).collect(Collectors.toSet());
   956         assertEquals(docSet, expectedSet, "Input: " + code);
   971         assertEquals(docSet, expectedSet, "Input: " + code);
   957     }
   972     }
   958 
   973 
   959     public enum ClassType {
   974     public enum ClassType {