Skip to content

Commit f099dd5

Browse files
EliotJonesBobLd
authored andcommitted
add test coverage to stream scanning
1 parent 0586713 commit f099dd5

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/UglyToad.PdfPig.Tests/Tokenization/Scanner/CoreTokenScannerTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,76 @@ public void ScansStringWithWeirdWeirdDoubleSymbolNumerics()
191191
AssertCorrectToken<NameToken, string>(tokens[3], "F1");
192192
AssertCorrectToken<NumericToken, double>(tokens[4], 8);
193193
AssertCorrectToken<OperatorToken, string>(tokens[5], "Tf");
194+
}
195+
196+
[Fact]
197+
public void SkipsCommentsInStreams()
198+
{
199+
const string content =
200+
"""
201+
% 641 0 obj
202+
<<
203+
/Type /Encoding
204+
/Differences [16/quotedblleft/quotedblright 21/endash 27/ff/fi/fl/ffi 39/quoteright/parenleft/parenright 43/plus/comma/hyphen/period/slash/zero/one/two/three/four/five/six/seven/eight/nine/colon 64/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft 93/bracketright 97/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft 125/braceright 225/aacute 232/egrave/eacute 252/udieresis]
205+
>>
206+
% 315 0 obj
207+
<<
208+
/Type /Font
209+
/Subtype /Type1
210+
/BaseFont /IXNPPI+CMEX10
211+
/FontDescriptor 661 0 R
212+
/FirstChar 80
213+
/LastChar 88
214+
/Widths 644 0 R
215+
/ToUnicode 699 0 R
216+
>>
217+
% 306 0 obj
218+
<<
219+
/Type /Font
220+
/Subtype /Type1
221+
/BaseFont /MSNKTF+CMMI10
222+
/FontDescriptor 663 0 R
223+
/FirstChar 58
224+
/LastChar 119
225+
/Widths 651 0 R
226+
/ToUnicode 700 0 R
227+
>>
228+
""";
229+
230+
var tokens = new List<IToken>();
231+
232+
var scanner = new CoreTokenScanner(
233+
StringBytesTestConverter.Convert(content, false).Bytes,
234+
true,
235+
isStream: true);
236+
237+
while (scanner.MoveNext())
238+
{
239+
tokens.Add(scanner.CurrentToken);
240+
}
241+
242+
Assert.Equal(3, tokens.Count);
243+
244+
Assert.All(tokens, x => Assert.IsType<DictionaryToken>(x));
194245

246+
tokens.Clear();
247+
248+
var nonStreamScanner = new CoreTokenScanner(
249+
StringBytesTestConverter.Convert(content, false).Bytes,
250+
true,
251+
isStream: false);
252+
253+
while (nonStreamScanner.MoveNext())
254+
{
255+
tokens.Add(nonStreamScanner.CurrentToken);
256+
}
257+
258+
Assert.Equal(6, tokens.Count);
259+
260+
Assert.Equal(3, tokens.OfType<CommentToken>().Count());
261+
Assert.Equal(3, tokens.OfType<DictionaryToken>().Count());
195262
}
263+
196264
private static void AssertCorrectToken<T, TData>(IToken token, TData expected) where T : IDataToken<TData>
197265
{
198266
var cast = Assert.IsType<T>(token);

0 commit comments

Comments
 (0)