137 return state; |
137 return state; |
138 } |
138 } |
139 |
139 |
140 public List<Snippet> getActiveKeys() { |
140 public List<Snippet> getActiveKeys() { |
141 return allSnippets.stream() |
141 return allSnippets.stream() |
142 .filter(k -> getState().status(k).isActive) |
142 .filter(k -> getState().status(k).isActive()) |
143 .collect(Collectors.toList()); |
143 .collect(Collectors.toList()); |
144 } |
144 } |
145 |
145 |
146 public void addToClasspath(String path) { |
146 public void addToClasspath(String path) { |
147 classpath.add(path); |
147 classpath.add(path); |
613 Snippet key = key(events); |
613 Snippet key = key(events); |
614 assertTrue(key instanceof ImportSnippet, "Expected a ImportKey, got: " + key); |
614 assertTrue(key instanceof ImportSnippet, "Expected a ImportKey, got: " + key); |
615 return (ImportSnippet) key; |
615 return (ImportSnippet) key; |
616 } |
616 } |
617 |
617 |
618 private Snippet key(List<SnippetEvent> events) { |
618 public Snippet key(List<SnippetEvent> events) { |
619 assertTrue(events.size() >= 1, "Expected at least one event, got none."); |
619 assertTrue(events.size() >= 1, "Expected at least one event, got none."); |
620 return events.get(0).snippet(); |
620 return events.get(0).snippet(); |
621 } |
621 } |
622 |
622 |
623 public void assertVarValue(Snippet key, String expected) { |
623 public void assertVarValue(Snippet key, String expected) { |
755 assertAnalyze(input, status, source, null, null); |
755 assertAnalyze(input, status, source, null, null); |
756 } |
756 } |
757 |
757 |
758 public void assertAnalyze(String input, Completeness status, String source, String remaining, Boolean isComplete) { |
758 public void assertAnalyze(String input, Completeness status, String source, String remaining, Boolean isComplete) { |
759 CompletionInfo ci = getAnalysis().analyzeCompletion(input); |
759 CompletionInfo ci = getAnalysis().analyzeCompletion(input); |
760 if (status != null) assertEquals(ci.completeness, status, "Input : " + input + ", status: "); |
760 if (status != null) assertEquals(ci.completeness(), status, "Input : " + input + ", status: "); |
761 if (source != null) assertEquals(ci.source, source, "Input : " + input + ", source: "); |
761 if (source != null) assertEquals(ci.source(), source, "Input : " + input + ", source: "); |
762 if (remaining != null) assertEquals(ci.remaining, remaining, "Input : " + input + ", remaining: "); |
762 if (remaining != null) assertEquals(ci.remaining(), remaining, "Input : " + input + ", remaining: "); |
763 if (isComplete != null) { |
763 if (isComplete != null) { |
764 boolean isExpectedComplete = isComplete; |
764 boolean isExpectedComplete = isComplete; |
765 assertEquals(ci.completeness.isComplete, isExpectedComplete, "Input : " + input + ", isComplete: "); |
765 assertEquals(ci.completeness().isComplete(), isExpectedComplete, "Input : " + input + ", isComplete: "); |
766 } |
766 } |
767 } |
767 } |
768 |
768 |
769 public void assertNumberOfActiveVariables(int cnt) { |
769 public void assertNumberOfActiveVariables(int cnt) { |
770 Collection<VarSnippet> variables = getState().variables(); |
770 Collection<VarSnippet> variables = getState().variables(); |
792 public void assertKeys(MemberInfo... expected) { |
792 public void assertKeys(MemberInfo... expected) { |
793 int index = 0; |
793 int index = 0; |
794 List<Snippet> snippets = getState().snippets(); |
794 List<Snippet> snippets = getState().snippets(); |
795 assertEquals(allSnippets.size(), snippets.size()); |
795 assertEquals(allSnippets.size(), snippets.size()); |
796 for (Snippet sn : snippets) { |
796 for (Snippet sn : snippets) { |
797 if (sn.kind().isPersistent && getState().status(sn).isActive) { |
797 if (sn.kind().isPersistent() && getState().status(sn).isActive()) { |
798 MemberInfo actual = getMemberInfo(sn); |
798 MemberInfo actual = getMemberInfo(sn); |
799 MemberInfo exp = expected[index]; |
799 MemberInfo exp = expected[index]; |
800 assertEquals(actual, exp, String.format("Difference in #%d. Expected: %s, actual: %s", |
800 assertEquals(actual, exp, String.format("Difference in #%d. Expected: %s, actual: %s", |
801 index, exp, actual)); |
801 index, exp, actual)); |
802 ++index; |
802 ++index; |
810 } |
810 } |
811 |
811 |
812 public void assertActiveKeys(Snippet... expected) { |
812 public void assertActiveKeys(Snippet... expected) { |
813 int index = 0; |
813 int index = 0; |
814 for (Snippet key : getState().snippets()) { |
814 for (Snippet key : getState().snippets()) { |
815 if (state.status(key).isActive) { |
815 if (state.status(key).isActive()) { |
816 assertEquals(expected[index], key, String.format("Difference in #%d. Expected: %s, actual: %s", index, key, expected[index])); |
816 assertEquals(expected[index], key, String.format("Difference in #%d. Expected: %s, actual: %s", index, key, expected[index])); |
817 ++index; |
817 ++index; |
818 } |
818 } |
819 } |
819 } |
820 } |
820 } |
886 code = code.replace("|", ""); |
886 code = code.replace("|", ""); |
887 assertTrue(cursor > -1, "'|' expected, but not found in: " + code); |
887 assertTrue(cursor > -1, "'|' expected, but not found in: " + code); |
888 List<Suggestion> completions = |
888 List<Suggestion> completions = |
889 getAnalysis().completionSuggestions(code, cursor, new int[1]); //XXX: ignoring anchor for now |
889 getAnalysis().completionSuggestions(code, cursor, new int[1]); //XXX: ignoring anchor for now |
890 return completions.stream() |
890 return completions.stream() |
891 .filter(s -> isSmart == null || isSmart == s.isSmart) |
891 .filter(s -> isSmart == null || isSmart == s.matchesType()) |
892 .map(s -> s.continuation) |
892 .map(s -> s.continuation()) |
893 .distinct() |
893 .distinct() |
894 .collect(Collectors.toList()); |
894 .collect(Collectors.toList()); |
895 } |
895 } |
896 |
896 |
897 public void assertInferredType(String code, String expectedType) { |
897 public void assertInferredType(String code, String expectedType) { |
1069 Boolean isSignatureChange, Snippet causeKey) { |
1069 Boolean isSignatureChange, Snippet causeKey) { |
1070 return new STEInfo(key, previousStatus, status, isSignatureChange, causeKey); |
1070 return new STEInfo(key, previousStatus, status, isSignatureChange, causeKey); |
1071 } |
1071 } |
1072 |
1072 |
1073 public static STEInfo added(Status status) { |
1073 public static STEInfo added(Status status) { |
1074 return new STEInfo(MAIN_SNIPPET, NONEXISTENT, status, status.isDefined, null); |
1074 return new STEInfo(MAIN_SNIPPET, NONEXISTENT, status, status.isDefined(), null); |
1075 } |
1075 } |
1076 |
1076 |
1077 public static class EventChain { |
1077 public static class EventChain { |
1078 public final STEInfo mainInfo; |
1078 public final STEInfo mainInfo; |
1079 public final STEInfo[] updates; |
1079 public final STEInfo[] updates; |