Commit bd29f868 authored by Jon Skeet's avatar Jon Skeet Committed by Jon Skeet

Fix CopyTo argument validation

Fixes #2669.
parent 39756643
......@@ -498,6 +498,14 @@ namespace Google.Protobuf.Collections
Assert.Throws<ArgumentNullException>(() => keys.Contains(null));
}
[Test]
public void KeysCopyTo()
{
var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
var keys = map.Keys.ToArray(); // Uses CopyTo internally
CollectionAssert.AreEquivalent(new[] { "foo", "x" }, keys);
}
[Test]
public void ValuesContains()
{
......@@ -510,6 +518,14 @@ namespace Google.Protobuf.Collections
Assert.IsFalse(values.Contains(null));
}
[Test]
public void ValuesCopyTo()
{
var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
var values = map.Values.ToArray(); // Uses CopyTo internally
CollectionAssert.AreEquivalent(new[] { "bar", "y" }, values);
}
[Test]
public void ToString_StringToString()
{
......
......@@ -715,7 +715,7 @@ namespace Google.Protobuf.Collections
{
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
}
if (arrayIndex + Count >= array.Length)
if (arrayIndex + Count > array.Length)
{
throw new ArgumentException("Not enough space in the array", nameof(array));
}
......@@ -746,7 +746,7 @@ namespace Google.Protobuf.Collections
{
throw new ArgumentOutOfRangeException(nameof(index));
}
if (index + Count >= array.Length)
if (index + Count > array.Length)
{
throw new ArgumentException("Not enough space in the array", nameof(array));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment