Skip to content

Commit

Permalink
Predictable test run condition processing
Browse files Browse the repository at this point in the history
  • Loading branch information
BCSharp committed Jan 2, 2025
1 parent e0bb6ad commit 3293f7e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Src/IronPythonTest/Cases/CaseGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.IO;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -105,7 +106,7 @@ protected bool ConditionMatched(string condition) {
private bool EvaluateExpression(string expression) {
var dummy = new DataTable();
string filter = expression;
var replacements = new Dictionary<string, string>() {
var replacements = new OrderedDictionary() {
// variables
{ "$(IS_NETCOREAPP)", IronPython.Runtime.ClrModule.IsNetCoreApp.ToString() },
{ "$(IS_NETSTANDARD)", IronPython.Runtime.ClrModule.TargetFramework.StartsWith(".NETStandard", StringComparison.Ordinal).ToString() },
Expand All @@ -119,20 +120,20 @@ private bool EvaluateExpression(string expression) {
// operators
{ "==", "=" },
{ "||", "OR" },
{ "\"", "'" }, // replace double quotes before double-double quotes
{ "\"\"", "\"" },
{ "\"", "'" },
{ "&&", "AND" },
{ "!=", "<>" }
{ "!=", "<>" },
};

foreach (var replacement in replacements) {
expression = expression.Replace(replacement.Key, replacement.Value);
foreach (DictionaryEntry replacement in replacements) {
expression = expression.Replace((string)replacement.Key, replacement.Value?.ToString());
}

try {
object res = dummy.Compute(expression, null);
if (res is bool) {
return (bool)res;
if (res is bool result) {
return result;
}
} catch (EvaluateException ex) {
if (ex.Message.StartsWith("The expression contains undefined function call", StringComparison.Ordinal))
Expand Down

0 comments on commit 3293f7e

Please sign in to comment.