Internal Test: Compares the behavior of Maximum (rule-level) and GlobalMaximum (transformer-level) invalidation.
ID: 947
See: Maximum = [int]
using uCalcSoftware;
var uc = new uCalc();
var FruitsXML =
"""
""";
var t = new uCalc.Transformer();
var fruitsTagRule = t.FromTo("", "List of fruits");
var fruitRule = t.FromTo("CommonName={@string:name}", "- {name}");
Console.WriteLine("--- Using Maximum (Rule-Level Invalidation) ---");
// The fruitRule will fail because there are 4 fruits, exceeding the max of 3.
fruitRule.Maximum = 3;
t.Filter(FruitsXML);
Console.WriteLine($"Match count: {t.Matches.Count()}"); // The 'fruitsTagRule' still matches and is counted.
Console.WriteLine(t.Matches.Text);
Console.WriteLine("");
Console.WriteLine("--- Using GlobalMaximum (Transformer-Level Invalidation) ---");
fruitRule.Maximum = -1; // Reset local maximum to default (unlimited).
fruitRule.GlobalMaximum = 3; // The entire transformer will fail if more than 3 fruits are found.
t.Filter(FruitsXML);
Console.WriteLine($"Match count: {t.Matches.Count()}"); // All matches (including fruitsTagRule) are invalidated.
Console.WriteLine(t.Matches.Text);
--- Using Maximum (Rule-Level Invalidation) ---
Match count: 1
List of fruits
--- Using GlobalMaximum (Transformer-Level Invalidation) ---
Match count: 0
using uCalcSoftware; var uc = new uCalc(); var FruitsXML = """ <Fruits> <Fruit CommonName='Apple' /> <Fruit CommonName='Banana' /> <Fruit CommonName='Orange' /> <Fruit CommonName='Grapes' /> </Fruits> """; var t = new uCalc.Transformer(); var fruitsTagRule = t.FromTo("<Fruits>", "List of fruits"); var fruitRule = t.FromTo("CommonName={@string:name}", "- {name}"); Console.WriteLine("--- Using Maximum (Rule-Level Invalidation) ---"); // The fruitRule will fail because there are 4 fruits, exceeding the max of 3. fruitRule.Maximum = 3; t.Filter(FruitsXML); Console.WriteLine($"Match count: {t.Matches.Count()}"); // The 'fruitsTagRule' still matches and is counted. Console.WriteLine(t.Matches.Text); Console.WriteLine(""); Console.WriteLine("--- Using GlobalMaximum (Transformer-Level Invalidation) ---"); fruitRule.Maximum = -1; // Reset local maximum to default (unlimited). fruitRule.GlobalMaximum = 3; // The entire transformer will fail if more than 3 fruits are found. t.Filter(FruitsXML); Console.WriteLine($"Match count: {t.Matches.Count()}"); // All matches (including fruitsTagRule) are invalidated. Console.WriteLine(t.Matches.Text);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto FruitsXML =
R"(
)";
uCalc::Transformer t;
auto fruitsTagRule = t.FromTo("", "List of fruits");
auto fruitRule = t.FromTo("CommonName={@string:name}", "- {name}");
cout << "--- Using Maximum (Rule-Level Invalidation) ---" << endl;
// The fruitRule will fail because there are 4 fruits, exceeding the max of 3.
fruitRule.Maximum(3);
t.Filter(FruitsXML);
cout << "Match count: " << t.Matches().Count() << endl; // The 'fruitsTagRule' still matches and is counted.
cout << t.Matches().Text() << endl;
cout << "" << endl;
cout << "--- Using GlobalMaximum (Transformer-Level Invalidation) ---" << endl;
fruitRule.Maximum(-1); // Reset local maximum to default (unlimited).
fruitRule.GlobalMaximum(3); // The entire transformer will fail if more than 3 fruits are found.
t.Filter(FruitsXML);
cout << "Match count: " << t.Matches().Count() << endl; // All matches (including fruitsTagRule) are invalidated.
cout << t.Matches().Text() << endl;
}
--- Using Maximum (Rule-Level Invalidation) ---
Match count: 1
List of fruits
--- Using GlobalMaximum (Transformer-Level Invalidation) ---
Match count: 0
#include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto FruitsXML = R"( <Fruits> <Fruit CommonName='Apple' /> <Fruit CommonName='Banana' /> <Fruit CommonName='Orange' /> <Fruit CommonName='Grapes' /> </Fruits> )"; uCalc::Transformer t; auto fruitsTagRule = t.FromTo("<Fruits>", "List of fruits"); auto fruitRule = t.FromTo("CommonName={@string:name}", "- {name}"); cout << "--- Using Maximum (Rule-Level Invalidation) ---" << endl; // The fruitRule will fail because there are 4 fruits, exceeding the max of 3. fruitRule.Maximum(3); t.Filter(FruitsXML); cout << "Match count: " << t.Matches().Count() << endl; // The 'fruitsTagRule' still matches and is counted. cout << t.Matches().Text() << endl; cout << "" << endl; cout << "--- Using GlobalMaximum (Transformer-Level Invalidation) ---" << endl; fruitRule.Maximum(-1); // Reset local maximum to default (unlimited). fruitRule.GlobalMaximum(3); // The entire transformer will fail if more than 3 fruits are found. t.Filter(FruitsXML); cout << "Match count: " << t.Matches().Count() << endl; // All matches (including fruitsTagRule) are invalidated. cout << t.Matches().Text() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim FruitsXML =
"
"
Dim t As New uCalc.Transformer()
Dim fruitsTagRule = t.FromTo("", "List of fruits")
Dim fruitRule = t.FromTo("CommonName={@string:name}", "- {name}")
Console.WriteLine("--- Using Maximum (Rule-Level Invalidation) ---")
'// The fruitRule will fail because there are 4 fruits, exceeding the max of 3.
fruitRule.Maximum = 3
t.Filter(FruitsXML)
Console.WriteLine($"Match count: {t.Matches.Count()}") '// The 'fruitsTagRule' still matches and is counted.
Console.WriteLine(t.Matches.Text)
Console.WriteLine("")
Console.WriteLine("--- Using GlobalMaximum (Transformer-Level Invalidation) ---")
fruitRule.Maximum = -1 '// Reset local maximum to default (unlimited).
fruitRule.GlobalMaximum = 3 '// The entire transformer will fail if more than 3 fruits are found.
t.Filter(FruitsXML)
Console.WriteLine($"Match count: {t.Matches.Count()}") '// All matches (including fruitsTagRule) are invalidated.
Console.WriteLine(t.Matches.Text)
End Sub
End Module
--- Using Maximum (Rule-Level Invalidation) ---
Match count: 1
List of fruits
--- Using GlobalMaximum (Transformer-Level Invalidation) ---
Match count: 0
Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim FruitsXML = " <Fruits> <Fruit CommonName='Apple' /> <Fruit CommonName='Banana' /> <Fruit CommonName='Orange' /> <Fruit CommonName='Grapes' /> </Fruits> " Dim t As New uCalc.Transformer() Dim fruitsTagRule = t.FromTo("<Fruits>", "List of fruits") Dim fruitRule = t.FromTo("CommonName={@string:name}", "- {name}") Console.WriteLine("--- Using Maximum (Rule-Level Invalidation) ---") '// The fruitRule will fail because there are 4 fruits, exceeding the max of 3. fruitRule.Maximum = 3 t.Filter(FruitsXML) Console.WriteLine($"Match count: {t.Matches.Count()}") '// The 'fruitsTagRule' still matches and is counted. Console.WriteLine(t.Matches.Text) Console.WriteLine("") Console.WriteLine("--- Using GlobalMaximum (Transformer-Level Invalidation) ---") fruitRule.Maximum = -1 '// Reset local maximum to default (unlimited). fruitRule.GlobalMaximum = 3 '// The entire transformer will fail if more than 3 fruits are found. t.Filter(FruitsXML) Console.WriteLine($"Match count: {t.Matches.Count()}") '// All matches (including fruitsTagRule) are invalidated. Console.WriteLine(t.Matches.Text) End Sub End Module