Fixed number to decimal parsing, additional tests

This commit is contained in:
Jordan Wages 2025-08-19 05:15:13 -05:00
commit 362af6f7bf
5 changed files with 15 additions and 4 deletions

View file

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Text;
using System.Collections.Generic;
using csmic;
@ -217,7 +218,7 @@ Value<out decimal r> (.
}
.)
|
number (. r = signum * Convert.ToDecimal(t.val); .)
number (. r = signum * decimal.Parse(t.val, NumberStyles.Float); .)
|
hex (. string hx = t.val.Remove(0,2);
try { r = signum * Convert.ToDecimal(Convert.ToInt64(hx, 16)); }

View file

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Text;
using System.Collections.Generic;
using csmic;
@ -328,7 +329,7 @@ bool IsArrayCall()
} else if (la.kind == 5) {
Get();
r = signum * Convert.ToDecimal(t.val);
r = signum * decimal.Parse(t.val, NumberStyles.Float);
} else if (la.kind == 4) {
Get();
string hx = t.val.Remove(0,2);

View file

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Text;
using System.Collections.Generic;
using csmic;
@ -328,7 +329,7 @@ bool IsArrayCall()
} else if (la.kind == 5) {
Get();
r = signum * Convert.ToDecimal(t.val);
r = signum * decimal.Parse(t.val, NumberStyles.Float);
} else if (la.kind == 4) {
Get();
string hx = t.val.Remove(0,2);

View file

@ -10,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
setup.ps1 = setup.ps1
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tests", "tests\tests.csproj", "{F356A0E2-1338-43FE-B4C0-1AE7C9F0685F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -21,6 +23,10 @@ Global
{5387FF55-3044-4EB4-BB90-AD2E922131C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5387FF55-3044-4EB4-BB90-AD2E922131C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5387FF55-3044-4EB4-BB90-AD2E922131C1}.Release|Any CPU.Build.0 = Release|Any CPU
{F356A0E2-1338-43FE-B4C0-1AE7C9F0685F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F356A0E2-1338-43FE-B4C0-1AE7C9F0685F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F356A0E2-1338-43FE-B4C0-1AE7C9F0685F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F356A0E2-1338-43FE-B4C0-1AE7C9F0685F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -36,8 +36,10 @@ public class InputInterpreterTests
[TestCase("7%4", 3)]
[TestCase("2^3", 8)]
[TestCase("1e2", 100)]
[TestCase("2.0e2", 200)]
[TestCase("0xFF", 255)]
[TestCase("1010b", 10)]
[TestCase("0xFF*1010b", 2550)]
public void Arithmetic_Works(string expr, decimal expected)
{
var result = _interp.Interpret(expr);
@ -85,7 +87,7 @@ public class InputInterpreterTests
[Test]
public void ExpressionBinding_InvalidExpression_ProducesSoftError()
{
_interp.Interpret("exp := bad + 1");
_interp.Interpret("exp :== bad + 1");
var result = _interp.Interpret("exp");
AssertSoftError(result, _interp);
}