mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-07-15 11:13:54 +08:00
Merge pull request #327 from kasperdaff/decodeparm-fix
DecodeParameterResolver looks in the wrong array when retrieving filter parameters
This commit is contained in:
commit
3869bbb786
@ -31,5 +31,106 @@
|
|||||||
|
|
||||||
Assert.Empty(result.Data);
|
Assert.Empty(result.Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SingleFilter_ReturnsParameterDictionary()
|
||||||
|
{
|
||||||
|
var filter = NameToken.CcittfaxDecode;
|
||||||
|
var filterParameters = new DictionaryToken(new Dictionary<NameToken, IToken>
|
||||||
|
{
|
||||||
|
{ NameToken.K, new NumericToken(-1) },
|
||||||
|
{ NameToken.Columns, new NumericToken(1800) },
|
||||||
|
{ NameToken.Rows, new NumericToken(3113) },
|
||||||
|
{ NameToken.BlackIs1, BooleanToken.True }
|
||||||
|
});
|
||||||
|
|
||||||
|
var dictionary = new Dictionary<NameToken, IToken>
|
||||||
|
{
|
||||||
|
{ NameToken.F, filter },
|
||||||
|
{ NameToken.DecodeParms, filterParameters }
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = DecodeParameterResolver.GetFilterParameters(new DictionaryToken(dictionary), 0);
|
||||||
|
|
||||||
|
Assert.Equal(filterParameters, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SingleFilter_SpecifiedInArray_ReturnsParameterDictionary()
|
||||||
|
{
|
||||||
|
var filter = NameToken.CcittfaxDecode;
|
||||||
|
var filterParameters = new DictionaryToken(new Dictionary<NameToken, IToken>
|
||||||
|
{
|
||||||
|
{ NameToken.K, new NumericToken(-1) },
|
||||||
|
{ NameToken.Columns, new NumericToken(1800) },
|
||||||
|
{ NameToken.Rows, new NumericToken(3113) },
|
||||||
|
{ NameToken.BlackIs1, BooleanToken.True }
|
||||||
|
});
|
||||||
|
|
||||||
|
var dictionary = new Dictionary<NameToken, IToken>
|
||||||
|
{
|
||||||
|
{ NameToken.F, new ArrayToken(new [] { filter }) },
|
||||||
|
{ NameToken.DecodeParms, new ArrayToken(new [] { filterParameters }) }
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = DecodeParameterResolver.GetFilterParameters(new DictionaryToken(dictionary), 0);
|
||||||
|
|
||||||
|
Assert.Equal(filterParameters, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MultipleFilters_WhenParameterIsNull_ReturnsEmptyDictionary()
|
||||||
|
{
|
||||||
|
var filter1 = NameToken.FlateDecode;
|
||||||
|
var filter1Parameters = NullToken.Instance;
|
||||||
|
|
||||||
|
var filter2 = NameToken.CcittfaxDecode;
|
||||||
|
var filter2Parameters = new DictionaryToken(new Dictionary<NameToken, IToken>
|
||||||
|
{
|
||||||
|
{ NameToken.K, new NumericToken(-1) },
|
||||||
|
{ NameToken.Columns, new NumericToken(1800) },
|
||||||
|
{ NameToken.Rows, new NumericToken(3113) },
|
||||||
|
{ NameToken.BlackIs1, BooleanToken.True }
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
var dictionary = new Dictionary<NameToken, IToken>
|
||||||
|
{
|
||||||
|
{ NameToken.F, new ArrayToken(new [] { filter1, filter2 }) },
|
||||||
|
{ NameToken.DecodeParms, new ArrayToken(new IToken[] { filter1Parameters, filter2Parameters }) }
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = DecodeParameterResolver.GetFilterParameters(new DictionaryToken(dictionary), 0);
|
||||||
|
|
||||||
|
Assert.Equal(new DictionaryToken(new Dictionary<NameToken, IToken>()), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void MultipleFilters_ReturnsParameterDictionary()
|
||||||
|
{
|
||||||
|
var filter1 = NameToken.FlateDecode;
|
||||||
|
var filter1Parameters = NullToken.Instance;
|
||||||
|
|
||||||
|
var filter2 = NameToken.CcittfaxDecode;
|
||||||
|
var filter2Parameters = new DictionaryToken(new Dictionary<NameToken, IToken>
|
||||||
|
{
|
||||||
|
{ NameToken.K, new NumericToken(-1) },
|
||||||
|
{ NameToken.Columns, new NumericToken(1800) },
|
||||||
|
{ NameToken.Rows, new NumericToken(3113) },
|
||||||
|
{ NameToken.BlackIs1, BooleanToken.True }
|
||||||
|
});
|
||||||
|
|
||||||
|
var dictionary = new Dictionary<NameToken, IToken>
|
||||||
|
{
|
||||||
|
{ NameToken.F, new ArrayToken(new [] { filter1, filter2 }) },
|
||||||
|
{ NameToken.DecodeParms, new ArrayToken(new IToken[] { filter1Parameters, filter2Parameters }) }
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = DecodeParameterResolver.GetFilterParameters(new DictionaryToken(dictionary), 1);
|
||||||
|
|
||||||
|
Assert.Equal(filter2Parameters, result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
/// A dictionary object is an associative table containing pairs of objects, known as the dictionary's entries.
|
/// A dictionary object is an associative table containing pairs of objects, known as the dictionary's entries.
|
||||||
/// The key must be a <see cref="NameToken"/> and the value may be an kind of <see cref="IToken"/>.
|
/// The key must be a <see cref="NameToken"/> and the value may be an kind of <see cref="IToken"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DictionaryToken : IDataToken<IReadOnlyDictionary<string, IToken>>
|
public class DictionaryToken : IDataToken<IReadOnlyDictionary<string, IToken>>, IEquatable<DictionaryToken>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The key value pairs in this dictionary.
|
/// The key value pairs in this dictionary.
|
||||||
@ -123,20 +123,25 @@
|
|||||||
return new DictionaryToken(data ?? throw new ArgumentNullException(nameof(data)));
|
return new DictionaryToken(data ?? throw new ArgumentNullException(nameof(data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool Equals(IToken obj)
|
public bool Equals(IToken obj)
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(this, obj))
|
return Equals(obj as DictionaryToken);
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(obj is DictionaryToken other))
|
/// <inheritdoc />
|
||||||
|
public bool Equals(DictionaryToken other)
|
||||||
|
{
|
||||||
|
if (other == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ReferenceEquals(this, other))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (Data.Count != other.Data.Count)
|
if (Data.Count != other.Data.Count)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -158,5 +163,6 @@
|
|||||||
{
|
{
|
||||||
return string.Join(", ", Data.Select(x => $"<{x.Key}, {x.Value}>"));
|
return string.Join(", ", Data.Select(x => $"<{x.Key}, {x.Value}>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
case ArrayToken array:
|
case ArrayToken array:
|
||||||
if (parameters is ArrayToken arr)
|
if (parameters is ArrayToken arr)
|
||||||
{
|
{
|
||||||
if (index < arr.Data.Count && array.Data[index] is DictionaryToken dictionary)
|
if (index < arr.Data.Count && arr.Data[index] is DictionaryToken dictionary)
|
||||||
{
|
{
|
||||||
return dictionary;
|
return dictionary;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user