Sample files for testing parsers and error handling
You are testing a parser, and that is two jobs. Some files must load, and load correctly. Others must fail, or fail cleanly.
The valid files below carry props in their manifest entries. The props say what a correct read
finds. The broken files carry an outcome, shown beside each link: must-fail, may-recover
or varies.
How do I prove a file loaded correctly?
https://loremfile.dev/pdf/a4-3pages.pdf · 4.4 KB (4,351 bytes) · application/pdf
Its manifest entry lists contains_text: strings taken from the text we generated the file
from. Assert that each one appears in what your extractor returns, after you collapse
whitespace. If they do, the pages were read. A call that merely returned proves nothing.
https://loremfile.dev/docx/with-tracked-changes.docx · 37.4 KB (37,393 bytes) · application/vnd.openxmlformats-officedocument.wordprocessingml.document · 3 paragraphs · 12 words
One deletion, one insertion and one comment. Join all the XML text and you get the deleted word as if it were current. The entry's props record the deleted, inserted and current text, so you can compare.
https://loremfile.dev/pdf/scanned-1page.pdf · 107 KB (107,030 bytes) · application/pdf
A page that looks readable and has no text layer, so extraction returns an empty string. A pipeline should notice that and send the page to OCR. It should not store an empty document.
https://loremfile.dev/json/all-types.json · 708 B · application/json; charset=utf-8 · utf-8 · LF · 23 lines
Integers beyond 2^53 and 2^63, negative zero and a surrogate pair. These are the values that change on a round trip through a double or a careless string decoder.
Where does text split in the wrong place?
https://loremfile.dev/csv/people-10-quoted-newlines.csv · 2.7 KB (2,697 bytes) · text/csv; charset=utf-8 · 10 rows · 14 columns · utf-8 · LF · 20 lines
A quoted field holding a real newline. Split the file into lines before you parse it as CSV, and that record is cut in two.
https://loremfile.dev/csv/people-10-utf8-bom.csv · 2.7 KB (2,682 bytes) · text/csv; charset=utf-8 · 10 rows · 14 columns · utf-8 · LF · 11 lines
A UTF-8 byte-order mark. Many readers leave it attached to the first column name, so a lookup by that name fails.
https://loremfile.dev/txt/utf16be-no-bom.txt · 3.6 KB (3,614 bytes) · text/plain; charset=utf-16be · utf-16be · LF · 5 lines
UTF-16 big-endian with no byte-order mark for a detector to find. Code that decides the encoding from a BOM reads it as the wrong one.
Files that must fail
https://loremfile.dev/edge/json-trailing-comma.json · 64 B · application/json; charset=utf-8 · must-fail
Commas before closing brackets. That is valid JavaScript and invalid JSON. A conforming JSON parser refuses it, so a reader that accepts it is not parsing JSON.
https://loremfile.dev/edge/xml-unclosed-tag.xml · 122 B · application/xml; charset=utf-8 · must-fail
An element that is never closed. XML 1.0 requires a parser to stop here. It must not guess where the element ends.
https://loremfile.dev/edge/zero-byte.json · 0 B · application/json; charset=utf-8 · must-fail
No bytes at all, where JSON requires a value. Check that the error says the file is empty. It should not say something about an unexpected end of input.
Files that may be recovered
https://loremfile.dev/edge/zip-truncated-50pct.zip · 911 B · application/zip · may-recover
The first half of a zip. The local headers survive and the central directory does not. A reader that walks local headers recovers the surviving entries. One that starts from the central directory finds nothing.
https://loremfile.dev/edge/pdf-truncated-60pct.pdf · 2.6 KB (2,610 bytes) · application/pdf · may-recover
The first part of a PDF, cut before its cross-reference table and trailer. Readers that rebuild the table by scanning the file recover the pages that survive.
https://loremfile.dev/edge/utf8-invalid-bytes.txt · 143 B · text/plain; charset=utf-8 · may-recover
Text served as UTF-8, with byte sequences that UTF-8 does not allow. Strict decoding fails. Replacing the bad bytes recovers the rest. Either is right. Silently dropping lines is not.
Files readers disagree on
https://loremfile.dev/edge/json-bom.json · 80 B · application/json; charset=utf-8 · varies
Valid JSON behind a byte-order mark, which RFC 8259 does not allow. Some parsers skip the mark and some refuse the file. Pin down which behaviour your code relies on.
https://loremfile.dev/edge/csv-ragged-rows.csv · 65 B · text/csv; charset=utf-8 · varies
Rows with fewer and more fields than the header. RFC 4180 says rows should match. It does not say what a reader does when they do not. A reader can pad, trim or refuse. Pick one, and test that your code does it.
What happens at the limits?
https://loremfile.dev/json/nested-100-levels.json · 1.4 KB (1,380 bytes) · application/json; charset=utf-8 · utf-8 · LF · 1 line
An object nested 100 levels deep. A recursive parser with a lower depth limit should refuse it with an error. It should not crash.
https://loremfile.dev/txt/very-long-line-1mb.txt · 1 MB (1,000,000 bytes) · text/plain; charset=utf-8 · utf-8 · LF · 1 line
A single line that fills the whole file. It is for line-based readers that hold a line in a fixed buffer.
Every broken file, with the exact damage and the valid file to compare it with, is on the edge cases page.