Skip to content

Main content

Random Word Wrap Boundary Corpus Generator

Compose fresh ASCII word/separator sequences and inclusive line-width draws, then compare greedy wrapping with paragraph-aware justification. Whitespace and long-token boundaries are retained; wrap keeps overlong words while justification returns its actual structured rejection, using UTF-16/ASCII widths rather than display-column estimates.

Loading tool…

Description

Compose fresh ASCII word/separator sequences and inclusive line-width draws, then compare greedy wrapping with paragraph-aware justification. Whitespace and long-token boundaries are retained; wrap keeps overlong words while justification returns its actual structured rejection, using UTF-16/ASCII widths rather than display-column estimates.

A parser corpus pairs literal input spellings or structured documents with observable parser results or explicitly constructed expectations. Successful parsing, semantic validity, and exact round-trip preservation are separate properties, so test records retain the relevant evidence.

Compose fresh ASCII word/separator sequences and inclusive line-width draws, then compare greedy wrapping with paragraph-aware justification. Whitespace and long-token boundaries are retained; wrap keeps overlong words while justification returns its actual structured rejection, using UTF-16/ASCII widths rather than display-column estimates.

When to use this tool

Use this generator to create reproducible word wrap boundary corpus cases from the supplied model or bank. Inspect the returned evidence before using cases in a test or exercise.

How to use the tool and how it works

  1. Supply words, separators, wordCount, minimumWidth, maximumWidth, count in the field shapes below. Set seed when you need an explicit replay.
  2. Run the tool and correct any input error. For generated controls, distinguish a successful fixture containing an invalid case from failure to generate the fixture.
  3. Read cases. Use the conventions below and keep answer-bearing fields separate when presenting an exercise.

Draw an inclusive integer line width and compose supplied ASCII words with supplied separators. Pass the resulting text to greedy wrapping and paragraph-aware justification, preserving actual successful text or structured justification rejection for each case.1

Delegated operations used for this result: word wrap; justify lines. Their calculation or parsing conventions apply to the corresponding result fields.2, 3

Input fieldMeaning and unitsAccepted input
wordsWordsRequired. Array of Text; minimum UTF-16 length 1; maximum UTF-16 length 128.; minimum items 1; maximum items 64.
separatorsSeparatorsRequired. Array of Text; one of " ", " ", "\t", "\n", "\r\n", "\n\n".; minimum items 1; maximum items 6.
wordCountWord CountRequired. Safe integer; minimum 1; maximum 64.
minimumWidthMinimum WidthRequired. Safe integer; minimum 1; maximum 500.
maximumWidthMaximum WidthRequired. Safe integer; minimum 1; maximum 500.
countRequested count; the mechanics explain whether one draw expands into several returned records.Required. Safe integer; minimum 1; maximum 32.
seedOptional numeric seed; takes precedence over context randomness. Without either, use the fixed tool.io default seed.Optional. Safe integer.
Output fieldInterpretationReturned shape
casesCasesRequired. Array of Object; no unknown keys.; minimum items 1; maximum items 32.
cases[].textTextRequired. Text; minimum UTF-16 length 1; maximum UTF-16 length 8318.
cases[].widthWidthRequired. Safe integer; minimum 1; maximum 500.
cases[].wrappedWrappedRequired. Object; no unknown keys.
cases[].wrapped.wrappedTextWrapped TextRequired. Text.
cases[].wrapped.lineCountLine CountRequired. Safe integer; minimum 1; maximum 64.
cases[].justifiedJustifiedRequired. Object; no unknown keys.
cases[].justified.okOkRequired. Boolean.
cases[].justified.textTextRequired. Text. or Null.
cases[].justified.errorCodeError CodeRequired. Text. or Null.
cases[].justified.errorMessageError MessageRequired. Text. or Null.
randomnessReplay metadata: source is seed or context; seed is the normalized 32-bit seed or null for a context source.Required. Object; no unknown keys.
randomness.seedOptional numeric replay seed; normalization and precedence are explained below.Required. Safe integer. or Null.
randomness.sourceSourceRequired. Text; one of "context", "seed".

An explicit safe-integer seed takes precedence over injected context randomness and is normalized to an unsigned 32-bit integer. With no seed and no context source, replay uses the fixed tool.io default seed. A context source must return finite values from zero inclusive to one exclusive; its advancing state must be retained separately. randomness records the source and normalized seed, or null for context. These generators are not cryptographic random sources.

json
{
  "input": {
    "words": [
      "one",
      "two",
      "longword"
    ],
    "separators": [
      " ",
      "  ",
      "\r\n"
    ],
    "wordCount": 5,
    "minimumWidth": 5,
    "maximumWidth": 12,
    "count": 2,
    "seed": 42
  },
  "output": {
    "cases": [
      {
        "text": "two\r\nlongword two two\r\ntwo",
        "width": 9,
        "wrapped": {
          "lineCount": 4,
          "wrappedText": "two\nlongword\ntwo two\ntwo"
        },
        "justified": {
          "ok": true,
          "text": "two\nlongword\ntwo   two\ntwo",
          "errorCode": null,
          "errorMessage": null
        }
      },
      {
        "text": "longword\r\none two\r\ntwo two",
        "width": 6,
        "wrapped": {
          "lineCount": 5,
          "wrappedText": "longword\none\ntwo\ntwo\ntwo"
        },
        "justified": {
          "ok": false,
          "text": null,
          "errorCode": "invalid_value",
          "errorMessage": "A word is longer than the requested width; this tool does not split words."
        }
      }
    ],
    "randomness": {
      "seed": 42,
      "source": "seed"
    }
  }
}

Limitations and assumptions

  • Widths count ASCII/UTF-16 units, not rendered columns. Wrapping can retain an overlong word while justification rejects it; the corpus records that distinction instead of inventing a common expected outcome.
  • A replay requires the same complete input and implementation. Randomized construction does not guarantee uniform coverage of every feasible output; finite samples can repeat unless a distinct-selection rule is explicitly stated.
  • The field tables state structural bounds; cross-field constraints and bounded search or output budgets also apply. Unknown keys are rejected where the object contract disallows them. Input errors are distinct from null fields and deliberate invalid controls in a successful output.

Alternative or Complementary methods

For a supplied example, inspect the returned construction or delegated check directly. To evaluate a consumer, also test cases chosen for its own boundaries; a generated finite corpus does not establish exhaustive coverage.

References

  1. Tool behavior and example: Random Word Wrap Boundary Corpus Generator — tool.io

  2. Calculation or validation: text/word-wrap — tool.io

  3. Calculation or validation: text/justify-lines — tool.io

Similar or alternative tools