diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-01-12 21:25:32 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-01-12 21:25:32 +0000 |
| commit | 6f554d8e265ad2664c97d9d8d6efef2f53e9eb5f (patch) | |
| tree | 8d2453bd70ce1143be425448a16c4a93d8767461 /src/test/java/org/shedlang/compiler/parser | |
| parent | eef0470389d88de6169a6962f14a9d422175e4c2 (diff) | |
Parse native function declarations
Diffstat (limited to 'src/test/java/org/shedlang/compiler/parser')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/parser/ParserNativeFunctionDeclarationTests.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/parser/ParserNativeFunctionDeclarationTests.java b/src/test/java/org/shedlang/compiler/parser/ParserNativeFunctionDeclarationTests.java new file mode 100644 index 00000000..f11a673c --- /dev/null +++ b/src/test/java/org/shedlang/compiler/parser/ParserNativeFunctionDeclarationTests.java @@ -0,0 +1,60 @@ +package org.shedlang.compiler.parser; + +import org.junit.jupiter.api.Test; +import org.shedlang.compiler.types.Visibility; + +import static org.shedlang.compiler.ast.untyped.UntypedNodeMatchers.*; +import static org.shedlang.compiler.parser.ParserTesting.parseString; +import static org.zwobble.precisely.AssertThat.assertThat; +import static org.zwobble.precisely.Matchers.isOptionalEmpty; +import static org.zwobble.precisely.Matchers.isSequence; + +public class ParserNativeFunctionDeclarationTests { + @Test + public void canParseMinimalFunction() { + var source = """ + native fun f() -> Unit;"""; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedNativeFunctionDeclarationNode() + .withName("f") + .withSignature( + isUntypedFunctionSignatureNode() + .withParams(isUntypedParamsNode(isSequence(), isSequence())) + .withEffect(isOptionalEmpty()) + .withReturnType(isUntypedTypeLevelReferenceNode("Unit")) + ) + ); + } + + @Test + public void defaultVisibilityIsPrivate() { + var source = """ + native fun f() -> Unit;"""; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedNativeFunctionDeclarationNode() + .withVisibility(Visibility.PRIVATE) + ); + } + + @Test + public void whenFunIsPrefixedWithPubThenVisibilityIsPublic() { + var source = """ + pub native fun f() -> Unit;"""; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedNativeFunctionDeclarationNode() + .withVisibility(Visibility.PUBLIC) + ); + } +} |
