using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TextCore;
using Object = UnityEngine.Object;
namespace TMPro
{
///
/// Coverage for the source string mapping that SetArraySizes writes into
/// TMP_CharacterInfo.index and TMP_CharacterInfo.stringLength when several code points are
/// folded into a single rendered character - a "cluster". Two constructs produce one:
/// a base character followed by a variation selector, and a ligature.
///
/// The regression these guard against: the VARIATION SELECTOR and LIGATURES blocks advance
/// the text processing index past the elements they consume, and index / stringLength used
/// to be read from textProcessingArray[i] *after* that advance. A cluster therefore
/// reported the span of its LAST consumed element instead of the span of the whole cluster,
/// so index pointed into the middle of the cluster. TMP_InputField derives every caret
/// position and every delete range from those two fields, which is why the first Backspace
/// after typing an Ideographic Variation Sequence appeared to do nothing. The input field
/// half of this is covered by TMP_InputFieldClusterTests.
///
/// Both renderers carry a duplicated copy of SetArraySizes, so every case here runs against
/// TextMeshPro and TextMeshProUGUI.
///
[Category("Text Parsing & Layout")]
internal class TMP_CharacterClusterTests: TMPTestSuiteWithEssentialResources
{
// U+FE0F VARIATION SELECTOR-16. A BMP selector: one UTF-16 code unit.
const string k_VariationSelector16 = "\uFE0F";
// U+E0100 VARIATION SELECTOR-17, the first Ideographic Variation Sequence selector.
// It lives in plane 14, so it is encoded as a surrogate pair: two UTF-16 code units.
// This is the construct from the original bug report.
const string k_VariationSelector17 = "\U000E0100";
// U+1F600 GRINNING FACE. A plain surrogate pair with no variation selector, used as the
// regression guard for characters the cluster accounting must leave alone.
const string k_AstralCharacter = "\U0001F600";
// Copy of the default font asset carrying a synthesized 'f' + 'i' ligature record, so the
// ligature case does not depend on which font the test project happens to ship.
TMP_FontAsset m_LigatureFontAsset;
TextMeshPro m_TextComponent;
TextMeshProUGUI m_TextComponentUGUI;
GameObject m_CanvasObject;
[OneTimeSetUp]
public void OneTimeSetUp()
{
GameObject textObject = new GameObject("Text Object");
m_TextComponent = textObject.AddComponent();
m_TextComponent.fontSize = 18;
m_CanvasObject = new GameObject("Canvas Object");
m_CanvasObject.AddComponent