Improved diagnostic handling

This commit is contained in:
2019-06-19 15:50:11 +02:00
parent 203ddf149f
commit 0ff2815694
6 changed files with 75 additions and 16 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Linq;
using NUnit.Framework;
using PorygonSharp;
using PorygonSharp.UserData;
@@ -16,7 +17,7 @@ namespace PorygonSharpTests
var diags = script.Diagnostics.GetDiagnostics();
foreach (var diag in diags)
{
throw new Exception(diag.GetCode().ToString());
throw new Exception(script.Diagnostics.GetFullDiagnosticMessage(diag));
}
Assert.False(script.Diagnostics.HasErrors());
}
@@ -109,6 +110,18 @@ namespace PorygonSharpTests
}
}
[Test]
public void TestDiagnostic()
{
using (var script = new Script("\n'\\x'"))
{
var diagnostics = script.Diagnostics.GetDiagnostics().ToArray();
Assert.IsNotEmpty(diagnostics);
Assert.AreEqual("[Error] (1, 3) '\\x' is not a valid control character.", script.Diagnostics.GetFullDiagnosticMessage(diagnostics[0]));
}
}
[Test]
public void TestHash()
{

View File

@@ -30,7 +30,7 @@ end
var diags = script.Diagnostics.GetDiagnostics();
foreach (var diag in diags)
{
throw new Exception(diag.GetCode().ToString());
throw new Exception(script.Diagnostics.GetFullDiagnosticMessage(diag));
}
script.Evaluate();
@@ -54,7 +54,7 @@ end
var diags = script.Diagnostics.GetDiagnostics();
foreach (var diag in diags)
{
throw new Exception(diag.GetCode().ToString());
throw new Exception(script.Diagnostics.GetFullDiagnosticMessage(diag));
}
script.Evaluate();
@@ -78,7 +78,7 @@ end
var diags = script.Diagnostics.GetDiagnostics();
foreach (var diag in diags)
{
throw new Exception(diag.GetCode().ToString());
throw new Exception(script.Diagnostics.GetFullDiagnosticMessage(diag));
}
script.Evaluate();
@@ -119,7 +119,7 @@ end
var diags = script.Diagnostics.GetDiagnostics();
foreach (var diag in diags)
{
throw new Exception(diag.GetCode().ToString());
throw new Exception(script.Diagnostics.GetFullDiagnosticMessage(diag));
}
script.Evaluate();