transformed my shitty test code into nuint tests
This commit is contained in:
@@ -15,7 +15,6 @@ using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Text.Encodings.Web;
|
||||
using DTLib.Dtsod;
|
||||
using DTLib.Extensions;
|
||||
using DTLib.Web;
|
||||
using DTLib.Web.Routes;
|
||||
|
||||
@@ -39,73 +38,9 @@ public partial class Program
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
MaxDepth = 1024,
|
||||
};
|
||||
|
||||
static void TestSearchExpression(Stream saveStream, TestCase tc)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
saveStream.Seek(0, SeekOrigin.Begin);
|
||||
var se = SearchExpressionCompiler.Compile(tc.q);
|
||||
var parser = new SaveParserEU4(saveStream, se);
|
||||
var rootNode = parser.Parse();
|
||||
string json = JsonSerializer.Serialize(rootNode, _saveSerializerOptions);
|
||||
string pdx = json.Substring(1, json.Length - 2)
|
||||
.Replace(",", " ").Replace("{", "{ ").Replace("}", " }")
|
||||
.Replace("\"", "").Replace("[", "").Replace("]", "").Replace(":", "=");
|
||||
if (pdx == tc.a)
|
||||
{
|
||||
Console.WriteLine($"[OK] q:'{tc.q}' a:'{tc.a}'");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"[Invalid] q:'{tc.q}' a:'{tc.a}' r:'{pdx}'");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[Error] q:'{tc.q}' a:'{tc.a}' e:\n" + ex.ToStringDemystified());
|
||||
}
|
||||
}
|
||||
|
||||
record TestCase(string q, string a);
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
using var saveStream = new MemoryStream(
|
||||
"EU4txt a={ b={ c=0 d=1 e=2 } f=3 }".ToBytes(),
|
||||
false);
|
||||
|
||||
TestCase[] testCases = [
|
||||
new("a",
|
||||
"a={ b={ c=0 d=1 e=2 } f=3 }"),
|
||||
|
||||
new("a.*",
|
||||
"a={ b={ c=0 d=1 e=2 } f=3 }"),
|
||||
|
||||
new("a.b",
|
||||
"a={ b={ c=0 d=1 e=2 } }"),
|
||||
|
||||
new("a.[0].c",
|
||||
"a={ b={ c=0 } }"),
|
||||
|
||||
new("a.[1]",
|
||||
"a={ f=3 }"),
|
||||
|
||||
new("a.b.(c|d)",
|
||||
"a={ b={ c=0 d=1 } }"),
|
||||
|
||||
new("a.(b.e|f)",
|
||||
"a={ b={ e=2 } f=3 }"),
|
||||
];
|
||||
|
||||
foreach (var test in testCases)
|
||||
{
|
||||
TestSearchExpression(saveStream, test);
|
||||
}
|
||||
|
||||
/*
|
||||
Console.InputEncoding = Encoding.UTF8;
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
Console.CursorVisible = false;
|
||||
@@ -148,7 +83,6 @@ public partial class Program
|
||||
{
|
||||
logger.LogError(ex.ToStringDemystified());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public static void PrepareLocalFiles()
|
||||
|
||||
Reference in New Issue
Block a user