Internal Test: Verifies correct precedence with overlapping patterns and confirms that re-running Find produces the same results.

ID: 1067

See: Find
				
					using uCalcSoftware;

var uc = new uCalc();
var t = new uCalc.Transformer();
t.Text = "The apple is an apple.";

// Overlapping patterns. The longer one is defined last, so it gets precedence.
t.Pattern("apple");
t.Pattern("an apple");

Console.WriteLine("--- First Find ---");
t.Find();
// The first 'apple' matches the first rule.
// The 'an apple' matches the second (higher precedence) rule.
Console.WriteLine(t.Matches.Text);

// Re-running find should produce the exact same result
Console.WriteLine("--- Second Find (no change) ---");
t.Find();
Console.WriteLine(t.Matches.Text);
				
			
--- First Find ---
apple
an apple
--- Second Find (no change) ---
apple
an apple
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc::Transformer t;
   t.Text("The apple is an apple.");

   // Overlapping patterns. The longer one is defined last, so it gets precedence.
   t.Pattern("apple");
   t.Pattern("an apple");

   cout << "--- First Find ---" << endl;
   t.Find();
   // The first 'apple' matches the first rule.
   // The 'an apple' matches the second (higher precedence) rule.
   cout << t.Matches().Text() << endl;

   // Re-running find should produce the exact same result
   cout << "--- Second Find (no change) ---" << endl;
   t.Find();
   cout << t.Matches().Text() << endl;
}
				
			
--- First Find ---
apple
an apple
--- Second Find (no change) ---
apple
an apple
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t As New uCalc.Transformer()
      t.Text = "The apple is an apple."
      
      '// Overlapping patterns. The longer one is defined last, so it gets precedence.
      t.Pattern("apple")
      t.Pattern("an apple")
      
      Console.WriteLine("--- First Find ---")
      t.Find()
      '// The first 'apple' matches the first rule.
      '// The 'an apple' matches the second (higher precedence) rule.
      Console.WriteLine(t.Matches.Text)
      
      '// Re-running find should produce the exact same result
      Console.WriteLine("--- Second Find (no change) ---")
      t.Find()
      Console.WriteLine(t.Matches.Text)
   End Sub
End Module
				
			
--- First Find ---
apple
an apple
--- Second Find (no change) ---
apple
an apple