generated from finos/software-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce compiler api to get generic type of a Lambda (#3300)
- Loading branch information
Showing
6 changed files
with
136 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...e-compiler/src/test/java/org/finos/legend/engine/language/pure/compiler/CompilerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 Goldman Sachs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package org.finos.legend.engine.language.pure.compiler; | ||
|
||
import java.util.stream.Collectors; | ||
import org.eclipse.collections.api.factory.Lists; | ||
import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; | ||
import org.finos.legend.engine.language.pure.grammar.from.PureGrammarParser; | ||
import org.finos.legend.engine.protocol.pure.v1.model.type.GenericType; | ||
import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType; | ||
import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class CompilerTest | ||
{ | ||
@Test | ||
public void getLambdaReturnGenericTypeForPrimitive() | ||
{ | ||
Lambda lambda = PureGrammarParser.newInstance().parseLambda("|1234"); | ||
GenericType genericType = Compiler.getLambdaReturnGenericType(lambda, PureModel.getCorePureModel()); | ||
Assert.assertTrue(genericType.rawType instanceof PackageableType); | ||
Assert.assertEquals("Integer", ((PackageableType) genericType.rawType).fullPath); | ||
} | ||
|
||
@Test | ||
public void getLambdaReturnGenericTypeWithTypeArguments() | ||
{ | ||
Lambda lambda = PureGrammarParser.newInstance().parseLambda("|pair(1, '2')"); | ||
GenericType genericType = Compiler.getLambdaReturnGenericType(lambda, PureModel.getCorePureModel()); | ||
Assert.assertTrue(genericType.rawType instanceof PackageableType); | ||
Assert.assertEquals("meta::pure::functions::collection::Pair", ((PackageableType) genericType.rawType).fullPath); | ||
Assert.assertEquals(Lists.mutable.with("Integer", "String"), genericType.typeArguments.stream().map(x -> ((PackageableType) x.rawType).fullPath).collect(Collectors.toList())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters