From 48520060e16bc78d37b0e630c6ba48834bc09541 Mon Sep 17 00:00:00 2001 From: Paul Irwin Date: Fri, 14 Aug 2026 15:23:54 -0600 Subject: [PATCH] Add regression tests for numeric literal visitors (#128) Issue #128 reported a FormatException converting binary int constants such as `0b10`. That crash was already fixed by 9957153 ("Support binary literals, #83"), which landed after the 3.0.0 build the reporter used. The binary literal path only had indirect coverage via the BinaryLiterals.java integration test, and only for local variables. Add direct unit tests for IntegerLiteralExpressionVisitor and LongLiteralExpressionVisitor covering binary (including uppercase 0B and underscore separators), hex, octal, and decimal literals, so the regression stays covered at the visitor level. Co-Authored-By: Claude Opus 5 (1M context) --- .../VisitLiteralExpressionTests.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/JavaToCSharp.Tests/VisitLiteralExpressionTests.cs b/JavaToCSharp.Tests/VisitLiteralExpressionTests.cs index c5d04c57..cf5aaa6f 100644 --- a/JavaToCSharp.Tests/VisitLiteralExpressionTests.cs +++ b/JavaToCSharp.Tests/VisitLiteralExpressionTests.cs @@ -18,5 +18,30 @@ public void VisitLiteralExpression_String() var expr = ExpressionVisitor.VisitExpression(new ConversionContext(new JavaConversionOptions()), new StringLiteralExpr(@"\\r")); Assert.Equal("\\r", expr?.GetFirstToken().ValueText); } + + [Theory] + [InlineData("0b10", 2)] + [InlineData("0b100", 4)] + [InlineData("0B1010", 10)] + [InlineData("0b1_0000", 16)] + [InlineData("0x1F", 31)] + [InlineData("010", 8)] + [InlineData("42", 42)] + public void VisitLiteralExpression_Integer(string javaLiteral, int expected) + { + var expr = ExpressionVisitor.VisitExpression(new ConversionContext(new JavaConversionOptions()), new IntegerLiteralExpr(javaLiteral)); + Assert.Equal(expected, expr?.GetFirstToken().Value); + } + + [Theory] + [InlineData("0b10L", 2L)] + [InlineData("0B1010L", 10L)] + [InlineData("0x1FL", 31L)] + [InlineData("010L", 8L)] + public void VisitLiteralExpression_Long(string javaLiteral, long expected) + { + var expr = ExpressionVisitor.VisitExpression(new ConversionContext(new JavaConversionOptions()), new LongLiteralExpr(javaLiteral)); + Assert.Equal(expected, expr?.GetFirstToken().Value); + } }