Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 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,8 +106,9 @@ 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
{ "$(FRAMEWORK)", IronPython.Runtime.ClrModule.TargetFramework },
{ "$(IS_NETCOREAPP)", IronPython.Runtime.ClrModule.IsNetCoreApp.ToString() },
{ "$(IS_NETSTANDARD)", IronPython.Runtime.ClrModule.TargetFramework.StartsWith(".NETStandard", StringComparison.Ordinal).ToString() },
{ "$(IS_MONO)", IronPython.Runtime.ClrModule.IsMono.ToString() },
Expand All @@ -119,20 +121,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
Loading