Fixed number to decimal parsing, additional tests
This commit is contained in:
parent
648bd3bad0
commit
362af6f7bf
5 changed files with 15 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using csmic;
|
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);
|
hex (. string hx = t.val.Remove(0,2);
|
||||||
try { r = signum * Convert.ToDecimal(Convert.ToInt64(hx, 16)); }
|
try { r = signum * Convert.ToDecimal(Convert.ToInt64(hx, 16)); }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using csmic;
|
using csmic;
|
||||||
|
@ -328,7 +329,7 @@ bool IsArrayCall()
|
||||||
|
|
||||||
} else if (la.kind == 5) {
|
} else if (la.kind == 5) {
|
||||||
Get();
|
Get();
|
||||||
r = signum * Convert.ToDecimal(t.val);
|
r = signum * decimal.Parse(t.val, NumberStyles.Float);
|
||||||
} else if (la.kind == 4) {
|
} else if (la.kind == 4) {
|
||||||
Get();
|
Get();
|
||||||
string hx = t.val.Remove(0,2);
|
string hx = t.val.Remove(0,2);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using csmic;
|
using csmic;
|
||||||
|
@ -328,7 +329,7 @@ bool IsArrayCall()
|
||||||
|
|
||||||
} else if (la.kind == 5) {
|
} else if (la.kind == 5) {
|
||||||
Get();
|
Get();
|
||||||
r = signum * Convert.ToDecimal(t.val);
|
r = signum * decimal.Parse(t.val, NumberStyles.Float);
|
||||||
} else if (la.kind == 4) {
|
} else if (la.kind == 4) {
|
||||||
Get();
|
Get();
|
||||||
string hx = t.val.Remove(0,2);
|
string hx = t.val.Remove(0,2);
|
||||||
|
|
|
@ -10,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||||
setup.ps1 = setup.ps1
|
setup.ps1 = setup.ps1
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tests", "tests\tests.csproj", "{F356A0E2-1338-43FE-B4C0-1AE7C9F0685F}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{5387FF55-3044-4EB4-BB90-AD2E922131C1}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -36,8 +36,10 @@ public class InputInterpreterTests
|
||||||
[TestCase("7%4", 3)]
|
[TestCase("7%4", 3)]
|
||||||
[TestCase("2^3", 8)]
|
[TestCase("2^3", 8)]
|
||||||
[TestCase("1e2", 100)]
|
[TestCase("1e2", 100)]
|
||||||
|
[TestCase("2.0e2", 200)]
|
||||||
[TestCase("0xFF", 255)]
|
[TestCase("0xFF", 255)]
|
||||||
[TestCase("1010b", 10)]
|
[TestCase("1010b", 10)]
|
||||||
|
[TestCase("0xFF*1010b", 2550)]
|
||||||
public void Arithmetic_Works(string expr, decimal expected)
|
public void Arithmetic_Works(string expr, decimal expected)
|
||||||
{
|
{
|
||||||
var result = _interp.Interpret(expr);
|
var result = _interp.Interpret(expr);
|
||||||
|
@ -85,7 +87,7 @@ public class InputInterpreterTests
|
||||||
[Test]
|
[Test]
|
||||||
public void ExpressionBinding_InvalidExpression_ProducesSoftError()
|
public void ExpressionBinding_InvalidExpression_ProducesSoftError()
|
||||||
{
|
{
|
||||||
_interp.Interpret("exp := bad + 1");
|
_interp.Interpret("exp :== bad + 1");
|
||||||
var result = _interp.Interpret("exp");
|
var result = _interp.Interpret("exp");
|
||||||
AssertSoftError(result, _interp);
|
AssertSoftError(result, _interp);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue