diff --git a/monticore-grammar/src/test/java/de/monticore/symbols/library/StreamTypeTest.java b/monticore-grammar/src/test/java/de/monticore/symbols/library/StreamTypeTest.java index 65d73badd..29ef65366 100644 --- a/monticore-grammar/src/test/java/de/monticore/symbols/library/StreamTypeTest.java +++ b/monticore-grammar/src/test/java/de/monticore/symbols/library/StreamTypeTest.java @@ -10,6 +10,7 @@ import de.monticore.symbols.oosymbols._symboltable.*; import de.monticore.types.check.SymTypeExpression; import de.monticore.types.check.SymTypeOfGenerics; +import de.monticore.types.check.SymTypeOfTuple; import de.se_rwth.commons.logging.Log; import de.se_rwth.commons.logging.LogStub; import org.junit.jupiter.api.Assertions; @@ -21,6 +22,7 @@ import java.nio.file.Path; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; public class StreamTypeTest { @@ -38,7 +40,7 @@ public void init() throws URISyntaxException { } @Test - public void resolveStreamType() { + public void testStreamTypeResolution() { Optional streamOpt = OOSymbolsMill.globalScope() .resolveType("Stream"); Assertions.assertTrue(streamOpt.isPresent()); @@ -49,68 +51,90 @@ public void resolveStreamType() { } @Test - public void resolveStaticEmpty() { - MethodSymbol method = resolveMethod("Stream.emptyStream"); - Assertions.assertTrue(method.getParameterList().isEmpty()); + public void testStaticRepeat() { + MethodSymbol method = resolveMethod("Stream.repeat"); + Assertions.assertEquals(method.getParameterList().size(), 2); assertIsStreamWithTypeVar(method.getType()); Assertions.assertTrue(method.isIsStatic()); List typeVars = method.getSpannedScope().getLocalTypeVarSymbols(); Assertions.assertEquals(1, typeVars.size()); - Assertions.assertNotEquals(typeVars.get(0).getName(), "T"); + Assertions.assertNotEquals(typeVars.get(0).getName(), "S"); } @Test - public void resolveStreamMethodAppendFirst() { - MethodSymbol method = resolveMethod("Stream.appendFirst"); + public void testStaticProjection() { + MethodSymbol method = resolveMethod("Stream.projFst"); Assertions.assertTrue(method.isIsStatic()); - Assertions.assertEquals(2, method.getParameterList().size()); - Assertions.assertTrue(method.getParameterList().get(0).getType().isTypeVariable()); - assertIsStreamWithTypeVar(method.getParameterList().get(1).getType()); + Assertions.assertEquals(1, method.getParameterList().size()); assertIsStreamWithTypeVar(method.getType()); + assertIsStreamWithTupleOfTypeVars(method.getParameterList().get(0).getType()); } @Test - public void resolveStreamMethodLen() { + public void testStreamMethodLen() { MethodSymbol method = resolveMethod("Stream.len"); Assertions.assertEquals(0, method.getParameterList().size()); - Assertions.assertTrue(method.getEnclosingScope().getSpanningSymbol() instanceof TypeSymbol); + Assertions.assertInstanceOf(TypeSymbol.class, method.getEnclosingScope().getSpanningSymbol()); Assertions.assertEquals("Stream", method.getEnclosingScope().getSpanningSymbol().getName()); Assertions.assertEquals(BasicSymbolsMill.LONG, method.getType().getTypeInfo().getName()); } @Test - public void resolveStreamFunctions() { - resolveCommonMemberMethods("Stream"); + public void resolveStreamMethodsTest() { + resolveCommonMemberMethods("UntimedStream"); resolveCommonMemberMethods("EventStream"); resolveCommonMemberMethods("SyncStream"); resolveCommonMemberMethods("ToptStream"); } + @Test + public void testInterfaceMethodResolution() { + resolveStaticMethods("Stream"); + // methods such as "zip", "first", "nth" are not in the interface + // as the signatures do not match between implementations + resolveMethod("Stream.len"); + resolveMethod("Stream.hasInfiniteLen"); + resolveMethod("Stream.take"); + resolveMethod("Stream.dropFirst"); + resolveMethod("Stream.dropMultiple"); + resolveMethod("Stream.times"); + resolveMethod("Stream.infTimes"); + resolveMethod("Stream.map"); + resolveMethod("Stream.filter"); + resolveMethod("Stream.takeWhile"); + resolveMethod("Stream.dropWhile"); + resolveMethod("Stream.rcDups"); + resolveMethod("Stream.values"); + resolveMethod("Stream.scanl"); + } + protected void resolveStaticMethods(String streamType) { - resolveMethod(streamType + ".emptyStream"); - resolveMethod(streamType + ".appendFirst"); - resolveMethod(streamType + ".conc"); resolveMethod(streamType + ".repeat"); resolveMethod(streamType + ".iterate"); } protected void resolveCommonMemberMethods(String streamType) { resolveMethod(streamType + ".len"); + resolveMethod(streamType + ".hasInfiniteLen"); resolveMethod(streamType + ".first"); - resolveMethod(streamType + ".dropFirst"); resolveMethod(streamType + ".nth"); resolveMethod(streamType + ".take"); - resolveMethod(streamType + ".drop"); + resolveMethod(streamType + ".dropFirst"); + resolveMethod(streamType + ".dropMultiple"); resolveMethod(streamType + ".times"); + resolveMethod(streamType + ".infTimes"); resolveMethod(streamType + ".map"); resolveMethod(streamType + ".filter"); resolveMethod(streamType + ".takeWhile"); resolveMethod(streamType + ".dropWhile"); resolveMethod(streamType + ".rcDups"); + resolveMethod(streamType + ".zip"); + resolveMethod(streamType + ".values"); + resolveMethod(streamType + "scanl"); } @Test - public void resolveTimedStreamMethods() { + public void testTimedStreamMethodsResolution() { resolveMethod("EventStream.delay"); resolveMethod("EventStream.mapSlice"); resolveMethod("EventStream.rougherTime"); @@ -118,7 +142,7 @@ public void resolveTimedStreamMethods() { resolveMethod("EventStream.sync"); resolveMethod("EventStream.topt"); resolveMethod("EventStream.untimed"); - resolveMethod("ToptStream.sizeEps"); + resolveMethod("ToptStream.sizeEmptyTimeslices"); resolveMethod("SyncStream.event"); } @@ -135,6 +159,18 @@ protected void assertIsStreamWithTypeVar(SymTypeExpression type) { Assertions.assertTrue(((SymTypeOfGenerics) type).getArgument(0).isTypeVariable()); } + protected void assertIsStreamWithTupleOfTypeVars(SymTypeExpression type) { + Assertions.assertNotNull(type); + Assertions.assertTrue(type.isGenericType()); + Assertions.assertEquals("Stream", type.getTypeInfo().getName()); + Assertions.assertEquals(1, ((SymTypeOfGenerics) type).getArgumentList().size()); + Assertions.assertTrue(((SymTypeOfGenerics) type).getArgument(0).isTupleType()); + Assertions.assertEquals(2, ((SymTypeOfTuple)((SymTypeOfGenerics) type).getArgument(0)).getTypeList().size()); + List tuple = ((SymTypeOfTuple)((SymTypeOfGenerics) type).getArgument(0)).getTypeList(); + Assertions.assertTrue(tuple.get(0).isTypeVariable()); + Assertions.assertTrue(tuple.get(1).isTypeVariable()); + } + protected MethodSymbol resolveMethod(String name) { Optional emptyOpt = OOSymbolsMill.globalScope().resolveMethod(name); Assertions.assertTrue(emptyOpt.isPresent());