mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Improve code quality
This commit is contained in:
parent
071b75bcb5
commit
d7d3549c82
2 changed files with 9 additions and 10 deletions
|
|
@ -11,12 +11,10 @@ namespace Flow.Launcher.Infrastructure
|
||||||
// list[i] is the last translated index + 1 of original index i
|
// list[i] is the last translated index + 1 of original index i
|
||||||
private readonly List<int> _originalToTranslated = new();
|
private readonly List<int> _originalToTranslated = new();
|
||||||
|
|
||||||
|
|
||||||
public void AddNewIndex(int translatedIndex, int length)
|
public void AddNewIndex(int translatedIndex, int length)
|
||||||
{
|
{
|
||||||
if (_isConstructed)
|
if (_isConstructed)
|
||||||
throw new InvalidOperationException("Mapping shouldn't be changed after construction");
|
throw new InvalidOperationException("Mapping shouldn't be changed after construction");
|
||||||
|
|
||||||
_originalToTranslated.Add(translatedIndex + length);
|
_originalToTranslated.Add(translatedIndex + length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
using Flow.Launcher.Infrastructure;
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using Flow.Launcher.Infrastructure;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NUnit.Framework.Legacy;
|
using NUnit.Framework.Legacy;
|
||||||
|
|
||||||
|
|
@ -34,22 +36,21 @@ namespace Flow.Launcher.Test
|
||||||
mapping.AddNewIndex(2, 2);
|
mapping.AddNewIndex(2, 2);
|
||||||
mapping.AddNewIndex(5, 3);
|
mapping.AddNewIndex(5, 3);
|
||||||
|
|
||||||
|
|
||||||
var result = mapping.MapToOriginalIndex(translatedIndex);
|
var result = mapping.MapToOriginalIndex(translatedIndex);
|
||||||
ClassicAssert.AreEqual(expectedOriginalIndex, result);
|
ClassicAssert.AreEqual(expectedOriginalIndex, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetOriginalToTranslatedCount(TranslationMapping mapping)
|
private static int GetOriginalToTranslatedCount(TranslationMapping mapping)
|
||||||
{
|
{
|
||||||
var field = typeof(TranslationMapping).GetField("originalToTranslated", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
var field = typeof(TranslationMapping).GetField("originalToTranslated", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
var list = (System.Collections.Generic.List<int>)field.GetValue(mapping);
|
var list = (List<int>)field.GetValue(mapping);
|
||||||
return list.Count;
|
return list.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetOriginalToTranslatedAt(TranslationMapping mapping, int index)
|
private static int GetOriginalToTranslatedAt(TranslationMapping mapping, int index)
|
||||||
{
|
{
|
||||||
var field = typeof(TranslationMapping).GetField("originalToTranslated", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
var field = typeof(TranslationMapping).GetField("originalToTranslated", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
var list = (System.Collections.Generic.List<int>)field.GetValue(mapping);
|
var list = (List<int>)field.GetValue(mapping);
|
||||||
return list[index];
|
return list[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue