mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-20 03:17:57 +08:00
add tests for array token
This commit is contained in:
@@ -0,0 +1,54 @@
|
|||||||
|
namespace UglyToad.PdfPig.Tests.Tokenization.Tokens
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using PdfPig.Tokenization.Tokens;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
public class ArrayTokenTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void SetsData()
|
||||||
|
{
|
||||||
|
var token = new ArrayToken(new[]
|
||||||
|
{
|
||||||
|
OperatorToken.StartStream,
|
||||||
|
OperatorToken.EndStream
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.Equal(2, token.Data.Count);
|
||||||
|
|
||||||
|
Assert.Equal(OperatorToken.StartStream, token.Data[0]);
|
||||||
|
Assert.Equal(OperatorToken.EndStream, token.Data[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetsDataEmpty()
|
||||||
|
{
|
||||||
|
var token = new ArrayToken(new IToken[0]);
|
||||||
|
|
||||||
|
Assert.Empty(token.Data);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SetsDataNullThrows()
|
||||||
|
{
|
||||||
|
// ReSharper disable once ObjectCreationAsStatement
|
||||||
|
Action action = () => new ArrayToken(null);
|
||||||
|
|
||||||
|
Assert.Throws<ArgumentNullException>(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ToStringCorrect()
|
||||||
|
{
|
||||||
|
var token = new ArrayToken(new IToken[]
|
||||||
|
{
|
||||||
|
new StringToken("hedgehog"),
|
||||||
|
new NumericToken(7),
|
||||||
|
OperatorToken.StartObject
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.Equal("[ (hedgehog), 7, obj ]", token.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,6 @@
|
|||||||
namespace UglyToad.PdfPig.Tokenization.Tokens
|
namespace UglyToad.PdfPig.Tokenization.Tokens
|
||||||
{
|
{
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -9,16 +10,25 @@
|
|||||||
|
|
||||||
public ArrayToken(IReadOnlyList<IToken> data)
|
public ArrayToken(IReadOnlyList<IToken> data)
|
||||||
{
|
{
|
||||||
Data = data;
|
Data = data ?? throw new ArgumentNullException(nameof(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var builder = new StringBuilder("[ ");
|
var builder = new StringBuilder("[ ");
|
||||||
|
|
||||||
foreach (var token in Data)
|
for (var i = 0; i < Data.Count; i++)
|
||||||
{
|
{
|
||||||
builder.Append(token).Append(' ');
|
var token = Data[i];
|
||||||
|
|
||||||
|
builder.Append(token);
|
||||||
|
|
||||||
|
if (i < Data.Count - 1)
|
||||||
|
{
|
||||||
|
builder.Append(',');
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.Append(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.Append(']');
|
builder.Append(']');
|
||||||
|
@@ -11,7 +11,7 @@ namespace UglyToad.PdfPig.Tokenization.Tokens
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"\"{Data}\"";
|
return $"({Data})";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user