Add more tests

This commit is contained in:
de4dot 2019-02-16 17:34:11 +01:00
parent ce578fd9ed
commit 1e842a07fe
1 changed files with 42 additions and 1 deletions

View File

@ -23,6 +23,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#if !NO_ENCODER
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
@ -400,6 +401,8 @@ namespace Iced.UnitTests.Intel.InstructionTests {
enum InsertRangeKind {
IEnumerable,
Array,
IList,
ReadOnlyList,
InstructionList,
@ -456,9 +459,17 @@ namespace Iced.UnitTests.Intel.InstructionTests {
// IEnumerable<Instruction> code path
return array.AsEnumerable();
case InsertRangeKind.Array:
// Instruction[] code path (none at the moment)
return array;
case InsertRangeKind.IList:
// IList<Instruction> code path
return new IListImpl<Instruction>(array);
case InsertRangeKind.ReadOnlyList:
// IReadOnlyList<Instruction> code path
return new ReadOnlyCollection<Instruction>(array);
return new IReadOnlyListImpl<Instruction>(array);
case InsertRangeKind.InstructionList:
// InstructionList code path
@ -470,6 +481,36 @@ namespace Iced.UnitTests.Intel.InstructionTests {
}
}
sealed class IListImpl<T> : IList<T> {
readonly T[] array;
public IListImpl(T[] array) => this.array = array;
public int Count => array.Length;
public T this[int index] {
get => array[index];
set => throw new NotImplementedException();
}
public bool IsReadOnly => throw new NotImplementedException();
public int IndexOf(T item) => throw new NotImplementedException();
public void Insert(int index, T item) => throw new NotImplementedException();
public void RemoveAt(int index) => throw new NotImplementedException();
public void Add(T item) => throw new NotImplementedException();
public void Clear() => throw new NotImplementedException();
public bool Contains(T item) => throw new NotImplementedException();
public bool Remove(T item) => throw new NotImplementedException();
public void CopyTo(T[] array, int arrayIndex) => throw new NotImplementedException();
public IEnumerator<T> GetEnumerator() => throw new NotImplementedException();
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
}
sealed class IReadOnlyListImpl<T> : IReadOnlyList<T> {
readonly T[] array;
public IReadOnlyListImpl(T[] array) => this.array = array;
public int Count => array.Length;
public T this[int index] => array[index];
public IEnumerator<T> GetEnumerator() => throw new NotImplementedException();
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
}
[Theory]
[MemberData(nameof(AddRange_works_Data))]
void AddRange_works(InstructionList list, IEnumerable<Instruction> inserted, Instruction[] expected) {