From f58db37fc82f2f3d1f3382402d77f496041135fa Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 4 Dec 2026 16:48:48 +0000 Subject: Handle constant numbers as binary operation args --- .../TypeCheckerBinaryOperationTests.java | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/test/java/org') diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerBinaryOperationTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerBinaryOperationTests.java index 7cd7d40..3f1e7de 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerBinaryOperationTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerBinaryOperationTests.java @@ -1,6 +1,9 @@ package org.zwobble.hobgoblin.compiler.typechecker; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.zwobble.hobgoblin.compiler.ast.typed.TypedBinaryOperator; import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode; import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperator; @@ -9,8 +12,12 @@ import org.zwobble.hobgoblin.compiler.builtins.NativeTypes; import org.zwobble.hobgoblin.compiler.sources.NullSource; import org.zwobble.hobgoblin.compiler.typechecker.errors.UnsupportedBinaryOperationError; import org.zwobble.hobgoblin.compiler.types.NamespaceName; +import org.zwobble.hobgoblin.compiler.types.Type; +import org.zwobble.hobgoblin.compiler.types.Types; +import java.math.BigDecimal; import java.util.Optional; +import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.zwobble.hobgoblin.compiler.ast.typed.TypedBinaryOperationNodeMatcher.isTypedBinaryOperationNode; @@ -19,8 +26,20 @@ import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.equalTo; public class TypeCheckerBinaryOperationTests { - @Test - public void whenLeftAndRightOperandsAreNumbersThenEqualityOperationTypeChecks() { + private static Stream whenLeftAndRightOperandsAreNumbersThenEqualityOperationTypeChecksOperands() { + return Stream.of( + Arguments.of(NativeTypes.INT_32, NativeTypes.INT_32), + Arguments.of(Types.constantNumber(BigDecimal.ZERO), NativeTypes.INT_32), + Arguments.of(NativeTypes.INT_32, Types.constantNumber(BigDecimal.ZERO)) + ); + } + + @ParameterizedTest + @MethodSource("whenLeftAndRightOperandsAreNumbersThenEqualityOperationTypeChecksOperands") + public void whenLeftAndRightOperandsAreNumbersThenEqualityOperationTypeChecks( + Type leftType, + Type rightType + ) { var untyped = UntypedBinaryOperationNode.arbitrary() .withOperator(UntypedBinaryOperator.EQUALS) .withLeft(UntypedReferenceNode.arbitrary().withName("a")) @@ -29,8 +48,8 @@ public class TypeCheckerBinaryOperationTests { var globalContext = TypeCheckerContextArb.globalContext(); var namespaceName = NamespaceName.of("App"); var namespaceContext = globalContext.enterNamespace(namespaceName) - .define("a", NativeTypes.INT_32, NullSource.INSTANCE) - .define("b", NativeTypes.INT_32, NullSource.INSTANCE) + .define("a", leftType, NullSource.INSTANCE) + .define("b", rightType, NullSource.INSTANCE) .endDeclarations(); var typed = TypeChecker.typeCheckExpression(untyped, Optional.empty(), namespaceContext); -- cgit v1.2.3