Skip to content

Commit c2c1259

Browse files
paulirwinclaude
andauthored
Add regression tests for numeric literal visitors (#128) (#158)
## Summary Issue #128 reported a `System.FormatException` when converting binary int constants such as `0b10`. **That crash is already fixed on master** — commit 9957153 ("Support binary literals, #83") landed after the 3.0.0 build the reporter was using. Verified with the reporter's exact snippet through the CLI: ```java static final int FLAG_LONG_FRAME = 0b10; static final int FLAG_COMMAND_FRAME = 0b100; ``` converts cleanly to: ```csharp static readonly int FLAG_LONG_FRAME = 0b10; static readonly int FLAG_COMMAND_FRAME = 0b100; ``` ## Why this PR The binary literal path only had indirect coverage via the `BinaryLiterals.java` integration test, and only for local variables — never for fields, and never at the visitor level. `IntegerLiteralExpressionVisitor` and `LongLiteralExpressionVisitor` had no direct unit tests at all. This adds two theories covering both visitors across every base they handle: - binary, including uppercase `0B` and underscore separators (`0b1_0000`) - hex (`0x1F`) - octal (`010`) - decimal No production code changes. This PR is test-only coverage; #128 can be closed as already fixed. ## Test plan - [x] `dotnet test` — 284 passed, 0 failed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 30b0894 commit c2c1259

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎JavaToCSharp.Tests/VisitLiteralExpressionTests.cs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,30 @@ public void VisitLiteralExpression_String()
1818
var expr = ExpressionVisitor.VisitExpression(new ConversionContext(new JavaConversionOptions()), new StringLiteralExpr(@"\\r"));
1919
Assert.Equal("\\r", expr?.GetFirstToken().ValueText);
2020
}
21+
22+
[Theory]
23+
[InlineData("0b10", 2)]
24+
[InlineData("0b100", 4)]
25+
[InlineData("0B1010", 10)]
26+
[InlineData("0b1_0000", 16)]
27+
[InlineData("0x1F", 31)]
28+
[InlineData("010", 8)]
29+
[InlineData("42", 42)]
30+
public void VisitLiteralExpression_Integer(string javaLiteral, int expected)
31+
{
32+
var expr = ExpressionVisitor.VisitExpression(new ConversionContext(new JavaConversionOptions()), new IntegerLiteralExpr(javaLiteral));
33+
Assert.Equal(expected, expr?.GetFirstToken().Value);
34+
}
35+
36+
[Theory]
37+
[InlineData("0b10L", 2L)]
38+
[InlineData("0B1010L", 10L)]
39+
[InlineData("0x1FL", 31L)]
40+
[InlineData("010L", 8L)]
41+
public void VisitLiteralExpression_Long(string javaLiteral, long expected)
42+
{
43+
var expr = ExpressionVisitor.VisitExpression(new ConversionContext(new JavaConversionOptions()), new LongLiteralExpr(javaLiteral));
44+
Assert.Equal(expected, expr?.GetFirstToken().Value);
45+
}
2146
}
2247

0 commit comments

Comments
 (0)