broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    url, width = x
    n = len(url)
    ok = set()
    for p in range(1, n):
        a, b = url[p - 1], url[p]
        if a == ':':
            ok.add(p)
        elif a == '/' and url[p - 1:p] == '//':
            ok.add(p)
        elif b == '/' and a != '/' and url[p + 1:p + 2] != '/':
            ok.add(p)
        elif b in '.-_?#%~':
            ok.add(p)
        elif a in '=&' or b in '=&':
            ok.add(p)
    lines = []
    start = 0
    while n - start > width:
        cands = [p for p in ok if start < p <= start + width]
        cut = max(cands) if cands else start + width
        lines.append(url[start:cut])
        start = cut
    lines.append(url[start:])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('regression: after double slash', ['https://www.docs.io/a/b/c#sec-3', 10], ['https://', 'www.docs', '.io/a/b/c', '#sec-3']), ('regression: after double slash', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 6], ['ftp://', 'files', '.site', '.net', '/pub', '/file', '-name', '_v2', '.tar', '.gz']), ('regression: after double slash', ['https://example.com/path/to/page.html', 12], ['https://', 'example.com', '/path/to', '/page.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['https://sub.domain.example.co.uk/~user/page', 14], ['https://sub', '.domain', '.example.co.uk', '/~user/page']), ('control layout', ['mailto:someone@example.com', 13], ['mailto:', 'someone@examp', 'le.com']), ('control layout', ['https://t.co/AbCdEf', 12], ['https://t.co', '/AbCdEf'])], [('regression: after double slash', ['https://www.docs.io/a/b/c#sec-3', 8], ['https://', 'www.docs', '.io/a/b', '/c#sec-3']), ('regression: after double slash', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('regression: after double slash', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 10], ['ftp://', 'files.site', '.net/pub', '/file-name', '_v2.tar.gz']), ('regression: after double slash', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 6], ['ftp://', 'files', '.site', '.net', '/pub', '/file', '-name', '_v2', '.tar', '.gz']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['file:///usr/local/share/doc', 15], ['file:///usr', '/local/share', '/doc']), ('control layout', ['https://t.co/AbCdEf', 6], ['https:', '//t.co', '/AbCdE', 'f'])], [('regression: after double slash', ['https://sub.domain.example.co.uk/~user/page', 5], ['https', '://', 'sub', '.doma', 'in', '.exam', 'ple', '.co', '.uk/', '~user', '/page']), ('regression: after double slash', ['https://example.com/path/to/page.html', 7], ['https:', '//', 'example', '.com', '/path', '/to', '/page', '.html']), ('regression: after double slash', ['https://example.com/path/to/page.html', 7], ['https:', '//', 'example', '.com', '/path', '/to', '/page', '.html']), ('regression: after double slash', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 5], ['ftp:', '//', 'files', '.site', '.net', '/pub', '/file', '-name', '_v2', '.tar', '.gz']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 4], ['http', '://a', '.b', '.org', '/x//', 'y?q=', '1&r=', '2']), ('control layout', ['https://t.co/AbCdEf', 5], ['https', '://t', '.co', '/AbCd', 'Ef'])], [('regression: after double slash', ['https://t.co/AbCdEf', 4], ['http', 's://', 't.co', '/AbC', 'dEf']), ('regression: after double slash', ['https://sub.domain.example.co.uk/~user/page', 8], ['https://', 'sub', '.domain', '.example', '.co.uk/', '~user', '/page']), ('regression: after double slash', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 8], ['ftp://', 'files', '.site', '.net/pub', '/file', '-name_v2', '.tar.gz']), ('regression: after double slash', ['https://sub.domain.example.co.uk/~user/page', 8], ['https://', 'sub', '.domain', '.example', '.co.uk/', '~user', '/page']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://www.docs.io/a/b/c#sec-3', 11], ['https://www', '.docs.io/a', '/b/c#sec-3']), ('control layout', ['https://x.io/search?term=line%20break&lang=en', 15], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en'])], [('regression: after double slash', ['https://sub.domain.example.co.uk/~user/page', 9], ['https://', 'sub', '.domain', '.example', '.co.uk/', '~user', '/page']), ('regression: after double slash', ['https://sub.domain.example.co.uk/~user/page', 5], ['https', '://', 'sub', '.doma', 'in', '.exam', 'ple', '.co', '.uk/', '~user', '/page']), ('regression: after double slash', ['https://example.com/path/to/page.html', 7], ['https:', '//', 'example', '.com', '/path', '/to', '/page', '.html']), ('regression: after double slash', ['https://example.com/path/to/page.html', 7], ['https:', '//', 'example', '.com', '/path', '/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['file:///usr/local/share/doc', 15], ['file:///usr', '/local/share', '/doc']), ('control layout', ['https://t.co/AbCdEf', 5], ['https', '://t', '.co', '/AbCd', 'Ef'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    url, width = x
    n = len(url)
    ok = set()
    for p in range(1, n):
        a, b = url[p - 1], url[p]
        if a == ':':
            ok.add(p)
        elif a == '/' and url[p - 3:p - 1] == '//':
            ok.add(p)
        elif b == '/' and a != '/' and url[p + 1:p + 2] != '/':
            ok.add(p)
        elif b in '.-_?#%~':
            ok.add(p)
        elif a in '=&' or b in '=&':
            ok.add(p)
    lines = []
    start = 0
    while n - start > width:
        cands = [p for p in ok if start < p <= start + width]
        cut = max(cands) if cands else start + width
        lines.append(url[start:cut])
        start = cut
    lines.append(url[start:])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('regression: after double slash', ['https://www.docs.io/a/b/c#sec-3', 10], ['https://', 'www.docs', '.io/a/b/c', '#sec-3']), ('regression: after double slash', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 6], ['ftp://', 'files', '.site', '.net', '/pub', '/file', '-name', '_v2', '.tar', '.gz']), ('regression: after double slash', ['https://example.com/path/to/page.html', 12], ['https://', 'example.com', '/path/to', '/page.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['https://sub.domain.example.co.uk/~user/page', 14], ['https://sub', '.domain', '.example.co.uk', '/~user/page']), ('control layout', ['mailto:someone@example.com', 13], ['mailto:', 'someone@examp', 'le.com']), ('control layout', ['https://t.co/AbCdEf', 12], ['https://t.co', '/AbCdEf'])], [('regression: after double slash', ['https://www.docs.io/a/b/c#sec-3', 8], ['https://', 'www.docs', '.io/a/b', '/c#sec-3']), ('regression: after double slash', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('regression: after double slash', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 10], ['ftp://', 'files.site', '.net/pub', '/file-name', '_v2.tar.gz']), ('regression: after double slash', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 6], ['ftp://', 'files', '.site', '.net', '/pub', '/file', '-name', '_v2', '.tar', '.gz']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['file:///usr/local/share/doc', 15], ['file:///usr', '/local/share', '/doc']), ('control layout', ['https://t.co/AbCdEf', 6], ['https:', '//t.co', '/AbCdE', 'f'])], [('regression: after double slash', ['https://sub.domain.example.co.uk/~user/page', 5], ['https', '://', 'sub', '.doma', 'in', '.exam', 'ple', '.co', '.uk/', '~user', '/page']), ('regression: after double slash', ['https://example.com/path/to/page.html', 7], ['https:', '//', 'example', '.com', '/path', '/to', '/page', '.html']), ('regression: after double slash', ['https://example.com/path/to/page.html', 7], ['https:', '//', 'example', '.com', '/path', '/to', '/page', '.html']), ('regression: after double slash', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 5], ['ftp:', '//', 'files', '.site', '.net', '/pub', '/file', '-name', '_v2', '.tar', '.gz']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 4], ['http', '://a', '.b', '.org', '/x//', 'y?q=', '1&r=', '2']), ('control layout', ['https://t.co/AbCdEf', 5], ['https', '://t', '.co', '/AbCd', 'Ef'])], [('regression: after double slash', ['https://t.co/AbCdEf', 4], ['http', 's://', 't.co', '/AbC', 'dEf']), ('regression: after double slash', ['https://sub.domain.example.co.uk/~user/page', 8], ['https://', 'sub', '.domain', '.example', '.co.uk/', '~user', '/page']), ('regression: after double slash', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 8], ['ftp://', 'files', '.site', '.net/pub', '/file', '-name_v2', '.tar.gz']), ('regression: after double slash', ['https://sub.domain.example.co.uk/~user/page', 8], ['https://', 'sub', '.domain', '.example', '.co.uk/', '~user', '/page']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://www.docs.io/a/b/c#sec-3', 11], ['https://www', '.docs.io/a', '/b/c#sec-3']), ('control layout', ['https://x.io/search?term=line%20break&lang=en', 15], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en'])], [('regression: after double slash', ['https://sub.domain.example.co.uk/~user/page', 9], ['https://', 'sub', '.domain', '.example', '.co.uk/', '~user', '/page']), ('regression: after double slash', ['https://sub.domain.example.co.uk/~user/page', 5], ['https', '://', 'sub', '.doma', 'in', '.exam', 'ple', '.co', '.uk/', '~user', '/page']), ('regression: after double slash', ['https://example.com/path/to/page.html', 7], ['https:', '//', 'example', '.com', '/path', '/to', '/page', '.html']), ('regression: after double slash', ['https://example.com/path/to/page.html', 7], ['https:', '//', 'example', '.com', '/path', '/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['file:///usr/local/share/doc', 15], ['file:///usr', '/local/share', '/doc']), ('control layout', ['https://t.co/AbCdEf', 5], ['https', '://t', '.co', '/AbCd', 'Ef'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
No break is offered right after "https://".

Input [url, width]. Break opportunities (no hyphen added): after ":"; after "//" (never between its slashes); before a single "/"; before . - _ ? # % ~; before or after = and &. While the rest exceeds the width, break at the latest opportunity within width characters, else hard-break at width. Return lines.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    url, width = x
    n = len(url)
    ok = set()
    for p in range(1, n):
        a, b = url[p - 1], url[p]
        if a == ':':
            ok.add(p)
        elif a == '/' and url[p - 2:p] == '//':
            ok.add(p)
        elif b == '/' and a != '/' and url[p + 1:p + 2] != '/':
            ok.add(p)
        elif a in '.-_?#%~':
            ok.add(p)
        elif a in '=&' or b in '=&':
            ok.add(p)
    lines = []
    start = 0
    while n - start > width:
        cands = [p for p in ok if start < p <= start + width]
        cut = max(cands) if cands else start + width
        lines.append(url[start:cut])
        start = cut
    lines.append(url[start:])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('regression: period break side', ['https://x.io/search?term=line%20break&lang=en', 5], ['https', '://x', '.io', '/sear', 'ch', '?term', '=line', '%20br', 'eak&', 'lang=', 'en']), ('regression: period break side', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 6], ['ftp://', 'files', '.site', '.net', '/pub', '/file', '-name', '_v2', '.tar', '.gz']), ('regression: period break side', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 6], ['ftp://', 'files', '.site', '.net', '/pub', '/file', '-name', '_v2', '.tar', '.gz']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['file:///usr/local/share/doc', 7], ['file://', '/usr', '/local', '/share', '/doc']), ('control layout', ['file:///usr/local/share/doc', 14], ['file:///usr', '/local/share', '/doc']), ('control layout', ['file:///usr/local/share/doc', 4], ['file', ':///', 'usr', '/loc', 'al', '/sha', 're', '/doc'])], [('regression: period break side', ['https://w.org/a=b/c&d', 12], ['https://w', '.org/a=b/c&d']), ('regression: period break side', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('regression: period break side', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 16], ['ftp://files.site', '.net/pub/file', '-name_v2.tar.gz']), ('regression: period break side', ['https://www.docs.io/a/b/c#sec-3', 5], ['https', '://', 'www', '.docs', '.io/a', '/b/c', '#sec', '-3']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 7], ['http://', 'a.b.org', '/x//y?q', '=1&r=2']), ('control layout', ['https://x.io/search?term=line%20break&lang=en', 15], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en'])], [('regression: period break side', ['https://sub.domain.example.co.uk/~user/page', 16], ['https://sub', '.domain.example', '.co.uk/~user', '/page']), ('regression: period break side', ['https://example.com/path/to/page.html', 9], ['https://', 'example', '.com/path', '/to/page', '.html']), ('regression: period break side', ['https://x.io/search?term=line%20break&lang=en', 9], ['https://x', '.io', '/search', '?term=', 'line', '%20break&', 'lang=en']), ('regression: period break side', ['https://sub.domain.example.co.uk/~user/page', 9], ['https://', 'sub', '.domain', '.example', '.co.uk/', '~user', '/page']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['file:///usr/local/share/doc', 6], ['file:', '///usr', '/local', '/share', '/doc']), ('control layout', ['https://w.org/a=b/c&d', 15], ['https://w.org/a', '=b/c&d'])], [('regression: period break side', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 8], ['ftp://', 'files', '.site', '.net/pub', '/file', '-name_v2', '.tar.gz']), ('regression: period break side', ['https://sub.domain.example.co.uk/~user/page', 15], ['https://sub', '.domain.example', '.co.uk/~user', '/page']), ('regression: period break side', ['https://x.io/search?term=line%20break&lang=en', 5], ['https', '://x', '.io', '/sear', 'ch', '?term', '=line', '%20br', 'eak&', 'lang=', 'en']), ('regression: period break side', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 15], ['http://a.b.org', '/x//y?q=1&r=2']), ('control layout', ['https://x.io/search?term=line%20break&lang=en', 15], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en'])], [('regression: period break side', ['https://x.io/search?term=line%20break&lang=en', 6], ['https:', '//x.io', '/searc', 'h?term', '=line', '%20bre', 'ak&', 'lang=', 'en']), ('regression: period break side', ['https://sub.domain.example.co.uk/~user/page', 5], ['https', '://', 'sub', '.doma', 'in', '.exam', 'ple', '.co', '.uk/', '~user', '/page']), ('regression: period break side', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('regression: period break side', ['https://x.io/search?term=line%20break&lang=en', 7], ['https:', '//x.io', '/search', '?term=', 'line', '%20brea', 'k&lang=', 'en']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 14], ['http://a.b.org', '/x//y?q=1&r=2']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 15], ['http://a.b.org', '/x//y?q=1&r=2'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    url, width = x
    n = len(url)
    ok = set()
    for p in range(1, n):
        a, b = url[p - 1], url[p]
        if a == ':':
            ok.add(p)
        elif a == '/' and url[p - 2:p] == '//':
            ok.add(p)
        elif b == '/' and a != '/' and url[p + 1:p + 2] != '/':
            ok.add(p)
        elif b in '.?#':
            ok.add(p)
        elif a in '=&' or b in '=&':
            ok.add(p)
    lines = []
    start = 0
    while n - start > width:
        cands = [p for p in ok if start < p <= start + width]
        cut = max(cands) if cands else start + width
        lines.append(url[start:cut])
        start = cut
    lines.append(url[start:])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('regression: period break side', ['https://x.io/search?term=line%20break&lang=en', 5], ['https', '://x', '.io', '/sear', 'ch', '?term', '=line', '%20br', 'eak&', 'lang=', 'en']), ('regression: period break side', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 6], ['ftp://', 'files', '.site', '.net', '/pub', '/file', '-name', '_v2', '.tar', '.gz']), ('regression: period break side', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 6], ['ftp://', 'files', '.site', '.net', '/pub', '/file', '-name', '_v2', '.tar', '.gz']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['file:///usr/local/share/doc', 7], ['file://', '/usr', '/local', '/share', '/doc']), ('control layout', ['file:///usr/local/share/doc', 14], ['file:///usr', '/local/share', '/doc']), ('control layout', ['file:///usr/local/share/doc', 4], ['file', ':///', 'usr', '/loc', 'al', '/sha', 're', '/doc'])], [('regression: period break side', ['https://w.org/a=b/c&d', 12], ['https://w', '.org/a=b/c&d']), ('regression: period break side', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('regression: period break side', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 16], ['ftp://files.site', '.net/pub/file', '-name_v2.tar.gz']), ('regression: period break side', ['https://www.docs.io/a/b/c#sec-3', 5], ['https', '://', 'www', '.docs', '.io/a', '/b/c', '#sec', '-3']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 7], ['http://', 'a.b.org', '/x//y?q', '=1&r=2']), ('control layout', ['https://x.io/search?term=line%20break&lang=en', 15], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en'])], [('regression: period break side', ['https://sub.domain.example.co.uk/~user/page', 16], ['https://sub', '.domain.example', '.co.uk/~user', '/page']), ('regression: period break side', ['https://example.com/path/to/page.html', 9], ['https://', 'example', '.com/path', '/to/page', '.html']), ('regression: period break side', ['https://x.io/search?term=line%20break&lang=en', 9], ['https://x', '.io', '/search', '?term=', 'line', '%20break&', 'lang=en']), ('regression: period break side', ['https://sub.domain.example.co.uk/~user/page', 9], ['https://', 'sub', '.domain', '.example', '.co.uk/', '~user', '/page']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['file:///usr/local/share/doc', 6], ['file:', '///usr', '/local', '/share', '/doc']), ('control layout', ['https://w.org/a=b/c&d', 15], ['https://w.org/a', '=b/c&d'])], [('regression: period break side', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 8], ['ftp://', 'files', '.site', '.net/pub', '/file', '-name_v2', '.tar.gz']), ('regression: period break side', ['https://sub.domain.example.co.uk/~user/page', 15], ['https://sub', '.domain.example', '.co.uk/~user', '/page']), ('regression: period break side', ['https://x.io/search?term=line%20break&lang=en', 5], ['https', '://x', '.io', '/sear', 'ch', '?term', '=line', '%20br', 'eak&', 'lang=', 'en']), ('regression: period break side', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 15], ['http://a.b.org', '/x//y?q=1&r=2']), ('control layout', ['https://x.io/search?term=line%20break&lang=en', 15], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en'])], [('regression: period break side', ['https://x.io/search?term=line%20break&lang=en', 6], ['https:', '//x.io', '/searc', 'h?term', '=line', '%20bre', 'ak&', 'lang=', 'en']), ('regression: period break side', ['https://sub.domain.example.co.uk/~user/page', 5], ['https', '://', 'sub', '.doma', 'in', '.exam', 'ple', '.co', '.uk/', '~user', '/page']), ('regression: period break side', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('regression: period break side', ['https://x.io/search?term=line%20break&lang=en', 7], ['https:', '//x.io', '/search', '?term=', 'line', '%20brea', 'k&lang=', 'en']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 14], ['http://a.b.org', '/x//y?q=1&r=2']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 15], ['http://a.b.org', '/x//y?q=1&r=2'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Lines end with a dangling period instead of starting with it.

Input [url, width]. Break opportunities (no hyphen added): after ":"; after "//" (never between its slashes); before a single "/"; before . - _ ? # % ~; before or after = and &. While the rest exceeds the width, break at the latest opportunity within width characters, else hard-break at width. Return lines.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    url, width = x
    n = len(url)
    ok = set()
    for p in range(1, n):
        a, b = url[p - 1], url[p]
        if a == ':':
            ok.add(p)
        elif a == '/' and url[p - 2:p] == '//':
            ok.add(p)
        elif b == '/' and a != '/' and url[p + 1:p + 2] != '/':
            ok.add(p)
        elif b in '.-_?#%~':
            ok.add(p)
        elif b in '=&':
            ok.add(p)
    lines = []
    start = 0
    while n - start > width:
        cands = [p for p in ok if start < p <= start + width]
        cut = max(cands) if cands else start + width
        lines.append(url[start:cut])
        start = cut
    lines.append(url[start:])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 6], ['https:', '//x.io', '/searc', 'h?term', '=line', '%20bre', 'ak&', 'lang=', 'en']), ('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 13], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 9], ['http://a', '.b.org', '/x//y?q=1', '&r=2']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 9], ['http://a', '.b.org', '/x//y?q=1', '&r=2']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://sub.domain.example.co.uk/~user/page', 7], ['https:', '//sub', '.domain', '.exampl', 'e.co.uk', '/~user', '/page']), ('control layout', ['https://example.com/path/to/page.html', 7], ['https:', '//', 'example', '.com', '/path', '/to', '/page', '.html'])], [('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 14], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en']), ('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 13], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 13], ['http://a.b', '.org/x//y?q=1', '&r=2']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 13], ['http://a.b', '.org/x//y?q=1', '&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['file:///usr/local/share/doc', 7], ['file://', '/usr', '/local', '/share', '/doc']), ('control layout', ['mailto:someone@example.com', 16], ['mailto:', 'someone@example', '.com'])], [('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 16], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en']), ('regression: equals and ampersand sides', ['http://a.b.org/x//y?q=1&r=2', 5], ['http:', '//a.b', '.org', '/x//y', '?q=1&', 'r=2']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 13], ['http://a.b', '.org/x//y?q=1', '&r=2']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 7], ['http://', 'a.b.org', '/x//y?q', '=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['file:///usr/local/share/doc', 6], ['file:', '///usr', '/local', '/share', '/doc']), ('control layout', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 12], ['ftp://files', '.site.net', '/pub/file', '-name_v2.tar', '.gz'])], [('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 13], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en']), ('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 6], ['https:', '//x.io', '/searc', 'h?term', '=line', '%20bre', 'ak&', 'lang=', 'en']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 6], ['http:', '//a.b', '.org', '/x//y', '?q=1&r', '=2']), ('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 6], ['https:', '//x.io', '/searc', 'h?term', '=line', '%20bre', 'ak&', 'lang=', 'en']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 9], ['ftp://', 'files', '.site.net', '/pub/file', '-name_v2', '.tar.gz']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 14], ['http://a.b.org', '/x//y?q=1&r=2'])], [('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 4], ['http', 's://', 'x.io', '/sea', 'rch', '?ter', 'm=', 'line', '%20b', 'reak', '&', 'lang', '=en']), ('regression: equals and ampersand sides', ['http://a.b.org/x//y?q=1&r=2', 12], ['http://a.b', '.org/x//y?q=', '1&r=2']), ('partial-repair probe', ['https://w.org/a=b/c&d', 6], ['https:', '//w', '.org/a', '=b/c&d']), ('partial-repair probe', ['https://w.org/a=b/c&d', 6], ['https:', '//w', '.org/a', '=b/c&d']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://sub.domain.example.co.uk/~user/page', 5], ['https', '://', 'sub', '.doma', 'in', '.exam', 'ple', '.co', '.uk/', '~user', '/page']), ('control layout', ['https://example.com/path/to/page.html', 12], ['https://', 'example.com', '/path/to', '/page.html'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    url, width = x
    n = len(url)
    ok = set()
    for p in range(1, n):
        a, b = url[p - 1], url[p]
        if a == ':':
            ok.add(p)
        elif a == '/' and url[p - 2:p] == '//':
            ok.add(p)
        elif b == '/' and a != '/' and url[p + 1:p + 2] != '/':
            ok.add(p)
        elif b in '.-_?#%~':
            ok.add(p)
        elif a in '=&':
            ok.add(p)
    lines = []
    start = 0
    while n - start > width:
        cands = [p for p in ok if start < p <= start + width]
        cut = max(cands) if cands else start + width
        lines.append(url[start:cut])
        start = cut
    lines.append(url[start:])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 6], ['https:', '//x.io', '/searc', 'h?term', '=line', '%20bre', 'ak&', 'lang=', 'en']), ('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 13], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 9], ['http://a', '.b.org', '/x//y?q=1', '&r=2']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 9], ['http://a', '.b.org', '/x//y?q=1', '&r=2']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://sub.domain.example.co.uk/~user/page', 7], ['https:', '//sub', '.domain', '.exampl', 'e.co.uk', '/~user', '/page']), ('control layout', ['https://example.com/path/to/page.html', 7], ['https:', '//', 'example', '.com', '/path', '/to', '/page', '.html'])], [('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 14], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en']), ('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 13], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 13], ['http://a.b', '.org/x//y?q=1', '&r=2']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 13], ['http://a.b', '.org/x//y?q=1', '&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['file:///usr/local/share/doc', 7], ['file://', '/usr', '/local', '/share', '/doc']), ('control layout', ['mailto:someone@example.com', 16], ['mailto:', 'someone@example', '.com'])], [('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 16], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en']), ('regression: equals and ampersand sides', ['http://a.b.org/x//y?q=1&r=2', 5], ['http:', '//a.b', '.org', '/x//y', '?q=1&', 'r=2']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 13], ['http://a.b', '.org/x//y?q=1', '&r=2']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 7], ['http://', 'a.b.org', '/x//y?q', '=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['file:///usr/local/share/doc', 6], ['file:', '///usr', '/local', '/share', '/doc']), ('control layout', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 12], ['ftp://files', '.site.net', '/pub/file', '-name_v2.tar', '.gz'])], [('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 13], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en']), ('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 6], ['https:', '//x.io', '/searc', 'h?term', '=line', '%20bre', 'ak&', 'lang=', 'en']), ('partial-repair probe', ['http://a.b.org/x//y?q=1&r=2', 6], ['http:', '//a.b', '.org', '/x//y', '?q=1&r', '=2']), ('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 6], ['https:', '//x.io', '/searc', 'h?term', '=line', '%20bre', 'ak&', 'lang=', 'en']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 9], ['ftp://', 'files', '.site.net', '/pub/file', '-name_v2', '.tar.gz']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 14], ['http://a.b.org', '/x//y?q=1&r=2'])], [('regression: equals and ampersand sides', ['https://x.io/search?term=line%20break&lang=en', 4], ['http', 's://', 'x.io', '/sea', 'rch', '?ter', 'm=', 'line', '%20b', 'reak', '&', 'lang', '=en']), ('regression: equals and ampersand sides', ['http://a.b.org/x//y?q=1&r=2', 12], ['http://a.b', '.org/x//y?q=', '1&r=2']), ('partial-repair probe', ['https://w.org/a=b/c&d', 6], ['https:', '//w', '.org/a', '=b/c&d']), ('partial-repair probe', ['https://w.org/a=b/c&d', 6], ['https:', '//w', '.org/a', '=b/c&d']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://sub.domain.example.co.uk/~user/page', 5], ['https', '://', 'sub', '.doma', 'in', '.exam', 'ple', '.co', '.uk/', '~user', '/page']), ('control layout', ['https://example.com/path/to/page.html', 12], ['https://', 'example.com', '/path/to', '/page.html'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Query strings only break on one side of = and &.

Input [url, width]. Break opportunities (no hyphen added): after ":"; after "//" (never between its slashes); before a single "/"; before . - _ ? # % ~; before or after = and &. While the rest exceeds the width, break at the latest opportunity within width characters, else hard-break at width. Return lines.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    url, width = x
    n = len(url)
    ok = set()
    for p in range(1, n):
        a, b = url[p - 1], url[p]
        if a == ':':
            ok.add(p)
        elif a == '/' and url[p - 2:p] == '//':
            ok.add(p)
        elif b == '/' and a != '/' and url[p + 1:p + 2] != '/':
            ok.add(p)
        elif b in '.-_?#%~':
            ok.add(p)
        elif a in '=&' or b in '=&':
            ok.add(p)
    lines = []
    start = 0
    while n - start > width:
        cands = [p for p in ok if start < p < start + width]
        cut = max(cands) if cands else start + width
        lines.append(url[start:cut])
        start = cut
    lines.append(url[start:])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('regression: candidate window', ['file:///usr/local/share/doc', 4], ['file', ':///', 'usr', '/loc', 'al', '/sha', 're', '/doc']), ('regression: candidate window', ['https://example.com/path/to/page.html', 4], ['http', 's://', 'exam', 'ple', '.com', '/pat', 'h/to', '/pag', 'e', '.htm', 'l']), ('partial-repair probe', ['file:///usr/local/share/doc', 5], ['file:', '///', 'usr', '/loca', 'l', '/shar', 'e/doc']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://x.io/search?term=line%20break&lang=en', 15], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en']), ('control layout', ['mailto:someone@example.com', 13], ['mailto:', 'someone@examp', 'le.com']), ('control layout', ['file:///usr/local/share/doc', 14], ['file:///usr', '/local/share', '/doc'])], [('regression: candidate window', ['https://sub.domain.example.co.uk/~user/page', 11], ['https://sub', '.domain', '.example.co', '.uk/~user', '/page']), ('regression: candidate window', ['https://x.io/search?term=line%20break&lang=en', 5], ['https', '://x', '.io', '/sear', 'ch', '?term', '=line', '%20br', 'eak&', 'lang=', 'en']), ('partial-repair probe', ['https://sub.domain.example.co.uk/~user/page', 6], ['https:', '//sub', '.domai', 'n', '.examp', 'le.co', '.uk/', '~user', '/page']), ('regression: candidate window', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['mailto:someone@example.com', 7], ['mailto:', 'someone', '@exampl', 'e.com']), ('control layout', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 5], ['ftp:', '//', 'files', '.site', '.net', '/pub', '/file', '-name', '_v2', '.tar', '.gz'])], [('regression: candidate window', ['https://x.io/search?term=line%20break&lang=en', 6], ['https:', '//x.io', '/searc', 'h?term', '=line', '%20bre', 'ak&', 'lang=', 'en']), ('regression: candidate window', ['https://w.org/a=b/c&d', 11], ['https://w', '.org/a=b/c&', 'd']), ('regression: candidate window', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('regression: candidate window', ['https://example.com/path/to/page.html', 4], ['http', 's://', 'exam', 'ple', '.com', '/pat', 'h/to', '/pag', 'e', '.htm', 'l']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['https://t.co/AbCdEf', 7], ['https:', '//t.co', '/AbCdEf']), ('control layout', ['https://sub.domain.example.co.uk/~user/page', 9], ['https://', 'sub', '.domain', '.example', '.co.uk/', '~user', '/page'])], [('regression: candidate window', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 12], ['ftp://files', '.site.net', '/pub/file', '-name_v2.tar', '.gz']), ('regression: candidate window', ['https://www.docs.io/a/b/c#sec-3', 5], ['https', '://', 'www', '.docs', '.io/a', '/b/c', '#sec', '-3']), ('regression: candidate window', ['https://x.io/search?term=line%20break&lang=en', 4], ['http', 's://', 'x.io', '/sea', 'rch', '?ter', 'm=', 'line', '%20b', 'reak', '&', 'lang', '=en']), ('regression: candidate window', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['https://sub.domain.example.co.uk/~user/page', 16], ['https://sub', '.domain.example', '.co.uk/~user', '/page']), ('control layout', ['mailto:someone@example.com', 16], ['mailto:', 'someone@example', '.com'])], [('regression: candidate window', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 9], ['ftp://', 'files', '.site.net', '/pub/file', '-name_v2', '.tar.gz']), ('regression: candidate window', ['https://t.co/AbCdEf', 4], ['http', 's://', 't.co', '/AbC', 'dEf']), ('partial-repair probe', ['mailto:someone@example.com', 6], ['mailto', ':', 'someon', 'e@exam', 'ple', '.com']), ('partial-repair probe', ['https://sub.domain.example.co.uk/~user/page', 6], ['https:', '//sub', '.domai', 'n', '.examp', 'le.co', '.uk/', '~user', '/page']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://sub.domain.example.co.uk/~user/page', 16], ['https://sub', '.domain.example', '.co.uk/~user', '/page']), ('control layout', ['mailto:someone@example.com', 8], ['mailto:', 'someone@', 'example', '.com'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    url, width = x
    n = len(url)
    ok = set()
    for p in range(1, n):
        a, b = url[p - 1], url[p]
        if a == ':':
            ok.add(p)
        elif a == '/' and url[p - 2:p] == '//':
            ok.add(p)
        elif b == '/' and a != '/' and url[p + 1:p + 2] != '/':
            ok.add(p)
        elif b in '.-_?#%~':
            ok.add(p)
        elif a in '=&' or b in '=&':
            ok.add(p)
    lines = []
    start = 0
    while n - start > width:
        cands = [p for p in ok if start + 1 < p <= start + width]
        cut = max(cands) if cands else start + width
        lines.append(url[start:cut])
        start = cut
    lines.append(url[start:])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('regression: candidate window', ['file:///usr/local/share/doc', 4], ['file', ':///', 'usr', '/loc', 'al', '/sha', 're', '/doc']), ('regression: candidate window', ['https://example.com/path/to/page.html', 4], ['http', 's://', 'exam', 'ple', '.com', '/pat', 'h/to', '/pag', 'e', '.htm', 'l']), ('partial-repair probe', ['file:///usr/local/share/doc', 5], ['file:', '///', 'usr', '/loca', 'l', '/shar', 'e/doc']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://x.io/search?term=line%20break&lang=en', 15], ['https://x.io', '/search?term=', 'line%20break&', 'lang=en']), ('control layout', ['mailto:someone@example.com', 13], ['mailto:', 'someone@examp', 'le.com']), ('control layout', ['file:///usr/local/share/doc', 14], ['file:///usr', '/local/share', '/doc'])], [('regression: candidate window', ['https://sub.domain.example.co.uk/~user/page', 11], ['https://sub', '.domain', '.example.co', '.uk/~user', '/page']), ('regression: candidate window', ['https://x.io/search?term=line%20break&lang=en', 5], ['https', '://x', '.io', '/sear', 'ch', '?term', '=line', '%20br', 'eak&', 'lang=', 'en']), ('partial-repair probe', ['https://sub.domain.example.co.uk/~user/page', 6], ['https:', '//sub', '.domai', 'n', '.examp', 'le.co', '.uk/', '~user', '/page']), ('regression: candidate window', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['mailto:someone@example.com', 7], ['mailto:', 'someone', '@exampl', 'e.com']), ('control layout', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 5], ['ftp:', '//', 'files', '.site', '.net', '/pub', '/file', '-name', '_v2', '.tar', '.gz'])], [('regression: candidate window', ['https://x.io/search?term=line%20break&lang=en', 6], ['https:', '//x.io', '/searc', 'h?term', '=line', '%20bre', 'ak&', 'lang=', 'en']), ('regression: candidate window', ['https://w.org/a=b/c&d', 11], ['https://w', '.org/a=b/c&', 'd']), ('regression: candidate window', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('regression: candidate window', ['https://example.com/path/to/page.html', 4], ['http', 's://', 'exam', 'ple', '.com', '/pat', 'h/to', '/pag', 'e', '.htm', 'l']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['https://t.co/AbCdEf', 7], ['https:', '//t.co', '/AbCdEf']), ('control layout', ['https://sub.domain.example.co.uk/~user/page', 9], ['https://', 'sub', '.domain', '.example', '.co.uk/', '~user', '/page'])], [('regression: candidate window', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 12], ['ftp://files', '.site.net', '/pub/file', '-name_v2.tar', '.gz']), ('regression: candidate window', ['https://www.docs.io/a/b/c#sec-3', 5], ['https', '://', 'www', '.docs', '.io/a', '/b/c', '#sec', '-3']), ('regression: candidate window', ['https://x.io/search?term=line%20break&lang=en', 4], ['http', 's://', 'x.io', '/sea', 'rch', '?ter', 'm=', 'line', '%20b', 'reak', '&', 'lang', '=en']), ('regression: candidate window', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['https://sub.domain.example.co.uk/~user/page', 16], ['https://sub', '.domain.example', '.co.uk/~user', '/page']), ('control layout', ['mailto:someone@example.com', 16], ['mailto:', 'someone@example', '.com'])], [('regression: candidate window', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 9], ['ftp://', 'files', '.site.net', '/pub/file', '-name_v2', '.tar.gz']), ('regression: candidate window', ['https://t.co/AbCdEf', 4], ['http', 's://', 't.co', '/AbC', 'dEf']), ('partial-repair probe', ['mailto:someone@example.com', 6], ['mailto', ':', 'someon', 'e@exam', 'ple', '.com']), ('partial-repair probe', ['https://sub.domain.example.co.uk/~user/page', 6], ['https:', '//sub', '.domai', 'n', '.examp', 'le.co', '.uk/', '~user', '/page']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://sub.domain.example.co.uk/~user/page', 16], ['https://sub', '.domain.example', '.co.uk/~user', '/page']), ('control layout', ['mailto:someone@example.com', 8], ['mailto:', 'someone@', 'example', '.com'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An opportunity exactly at the line end is ignored.

Input [url, width]. Break opportunities (no hyphen added): after ":"; after "//" (never between its slashes); before a single "/"; before . - _ ? # % ~; before or after = and &. While the rest exceeds the width, break at the latest opportunity within width characters, else hard-break at width. Return lines.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    url, width = x
    n = len(url)
    ok = set()
    for p in range(1, n):
        a, b = url[p - 1], url[p]
        if a == ':':
            ok.add(p)
        elif a == '/' and url[p - 2:p] == '//':
            ok.add(p)
        elif b == '/' and a != '/' and url[p + 1:p + 2] != '/':
            ok.add(p)
        elif b in '.-_?#%~':
            ok.add(p)
        elif a in '=&' or b in '=&':
            ok.add(p)
    lines = []
    start = 0
    while n - start > width:
        cands = [p for p in ok if start < p <= start + width]
        cut = max(cands) if cands else n
        lines.append(url[start:cut])
        start = cut
    lines.append(url[start:])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: hard break fallback', ['mailto:someone@example.com', 8], ['mailto:', 'someone@', 'example', '.com']), ('regression: hard break fallback', ['https://sub.domain.example.co.uk/~user/page', 5], ['https', '://', 'sub', '.doma', 'in', '.exam', 'ple', '.co', '.uk/', '~user', '/page']), ('regression: hard break fallback', ['mailto:someone@example.com', 11], ['mailto:', 'someone@exa', 'mple.com']), ('regression: hard break fallback', ['https://x.io/search?term=line%20break&lang=en', 6], ['https:', '//x.io', '/searc', 'h?term', '=line', '%20bre', 'ak&', 'lang=', 'en']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 9], ['http://a', '.b.org', '/x//y?q=1', '&r=2']), ('control layout', ['https://example.com/path/to/page.html', 13], ['https://', 'example.com', '/path/to/page', '.html'])], [('regression: hard break fallback', ['https://example.com/path/to/page.html', 6], ['https:', '//', 'exampl', 'e.com', '/path', '/to', '/page', '.html']), ('regression: hard break fallback', ['mailto:someone@example.com', 4], ['mail', 'to:', 'some', 'one@', 'exam', 'ple', '.com']), ('regression: hard break fallback', ['https://sub.domain.example.co.uk/~user/page', 5], ['https', '://', 'sub', '.doma', 'in', '.exam', 'ple', '.co', '.uk/', '~user', '/page']), ('regression: hard break fallback', ['mailto:someone@example.com', 12], ['mailto:', 'someone@exam', 'ple.com']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://t.co/AbCdEf', 14], ['https://t.co', '/AbCdEf']), ('control layout', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 10], ['ftp://', 'files.site', '.net/pub', '/file-name', '_v2.tar.gz'])], [('regression: hard break fallback', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('regression: hard break fallback', ['https://sub.domain.example.co.uk/~user/page', 7], ['https:', '//sub', '.domain', '.exampl', 'e.co.uk', '/~user', '/page']), ('regression: hard break fallback', ['https://x.io/search?term=line%20break&lang=en', 4], ['http', 's://', 'x.io', '/sea', 'rch', '?ter', 'm=', 'line', '%20b', 'reak', '&', 'lang', '=en']), ('regression: hard break fallback', ['mailto:someone@example.com', 9], ['mailto:', 'someone@e', 'xample', '.com']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['https://w.org/a=b/c&d', 11], ['https://w', '.org/a=b/c&', 'd']), ('control layout', ['file:///usr/local/share/doc', 12], ['file:///usr', '/local/share', '/doc'])], [('regression: hard break fallback', ['http://a.b.org/x//y?q=1&r=2', 4], ['http', '://a', '.b', '.org', '/x//', 'y?q=', '1&r=', '2']), ('regression: hard break fallback', ['https://www.docs.io/a/b/c#sec-3', 5], ['https', '://', 'www', '.docs', '.io/a', '/b/c', '#sec', '-3']), ('regression: hard break fallback', ['https://t.co/AbCdEf', 6], ['https:', '//t.co', '/AbCdE', 'f']), ('regression: hard break fallback', ['https://t.co/AbCdEf', 5], ['https', '://t', '.co', '/AbCd', 'Ef']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['https://example.com/path/to/page.html', 16], ['https://example', '.com/path/to', '/page.html']), ('control layout', ['https://t.co/AbCdEf', 11], ['https://t', '.co/AbCdEf'])], [('regression: hard break fallback', ['http://a.b.org/x//y?q=1&r=2', 4], ['http', '://a', '.b', '.org', '/x//', 'y?q=', '1&r=', '2']), ('regression: hard break fallback', ['https://sub.domain.example.co.uk/~user/page', 6], ['https:', '//sub', '.domai', 'n', '.examp', 'le.co', '.uk/', '~user', '/page']), ('regression: hard break fallback', ['https://t.co/AbCdEf', 5], ['https', '://t', '.co', '/AbCd', 'Ef']), ('regression: hard break fallback', ['https://t.co/AbCdEf', 6], ['https:', '//t.co', '/AbCdE', 'f']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://example.com/path/to/page.html', 11], ['https://', 'example.com', '/path/to', '/page.html']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 7], ['http://', 'a.b.org', '/x//y?q', '=1&r=2'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    url, width = x
    n = len(url)
    ok = set()
    for p in range(1, n):
        a, b = url[p - 1], url[p]
        if a == ':':
            ok.add(p)
        elif a == '/' and url[p - 2:p] == '//':
            ok.add(p)
        elif b == '/' and a != '/' and url[p + 1:p + 2] != '/':
            ok.add(p)
        elif b in '.-_?#%~':
            ok.add(p)
        elif a in '=&' or b in '=&':
            ok.add(p)
    lines = []
    start = 0
    while n - start > width:
        cands = [p for p in ok if start < p <= start + width]
        cut = max(cands) if cands else start + width - 1
        lines.append(url[start:cut])
        start = cut
    lines.append(url[start:])
    return lines
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: hard break fallback', ['mailto:someone@example.com', 8], ['mailto:', 'someone@', 'example', '.com']), ('regression: hard break fallback', ['https://sub.domain.example.co.uk/~user/page', 5], ['https', '://', 'sub', '.doma', 'in', '.exam', 'ple', '.co', '.uk/', '~user', '/page']), ('regression: hard break fallback', ['mailto:someone@example.com', 11], ['mailto:', 'someone@exa', 'mple.com']), ('regression: hard break fallback', ['https://x.io/search?term=line%20break&lang=en', 6], ['https:', '//x.io', '/searc', 'h?term', '=line', '%20bre', 'ak&', 'lang=', 'en']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 9], ['http://a', '.b.org', '/x//y?q=1', '&r=2']), ('control layout', ['https://example.com/path/to/page.html', 13], ['https://', 'example.com', '/path/to/page', '.html'])], [('regression: hard break fallback', ['https://example.com/path/to/page.html', 6], ['https:', '//', 'exampl', 'e.com', '/path', '/to', '/page', '.html']), ('regression: hard break fallback', ['mailto:someone@example.com', 4], ['mail', 'to:', 'some', 'one@', 'exam', 'ple', '.com']), ('regression: hard break fallback', ['https://sub.domain.example.co.uk/~user/page', 5], ['https', '://', 'sub', '.doma', 'in', '.exam', 'ple', '.co', '.uk/', '~user', '/page']), ('regression: hard break fallback', ['mailto:someone@example.com', 12], ['mailto:', 'someone@exam', 'ple.com']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://t.co/AbCdEf', 14], ['https://t.co', '/AbCdEf']), ('control layout', ['ftp://files.site.net/pub/file-name_v2.tar.gz', 10], ['ftp://', 'files.site', '.net/pub', '/file-name', '_v2.tar.gz'])], [('regression: hard break fallback', ['https://sub.domain.example.co.uk/~user/page', 4], ['http', 's://', 'sub', '.dom', 'ain', '.exa', 'mple', '.co', '.uk/', '~use', 'r', '/pag', 'e']), ('regression: hard break fallback', ['https://sub.domain.example.co.uk/~user/page', 7], ['https:', '//sub', '.domain', '.exampl', 'e.co.uk', '/~user', '/page']), ('regression: hard break fallback', ['https://x.io/search?term=line%20break&lang=en', 4], ['http', 's://', 'x.io', '/sea', 'rch', '?ter', 'm=', 'line', '%20b', 'reak', '&', 'lang', '=en']), ('regression: hard break fallback', ['mailto:someone@example.com', 9], ['mailto:', 'someone@e', 'xample', '.com']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['https://w.org/a=b/c&d', 11], ['https://w', '.org/a=b/c&', 'd']), ('control layout', ['file:///usr/local/share/doc', 12], ['file:///usr', '/local/share', '/doc'])], [('regression: hard break fallback', ['http://a.b.org/x//y?q=1&r=2', 4], ['http', '://a', '.b', '.org', '/x//', 'y?q=', '1&r=', '2']), ('regression: hard break fallback', ['https://www.docs.io/a/b/c#sec-3', 5], ['https', '://', 'www', '.docs', '.io/a', '/b/c', '#sec', '-3']), ('regression: hard break fallback', ['https://t.co/AbCdEf', 6], ['https:', '//t.co', '/AbCdE', 'f']), ('regression: hard break fallback', ['https://t.co/AbCdEf', 5], ['https', '://t', '.co', '/AbCd', 'Ef']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('control layout', ['https://example.com/path/to/page.html', 16], ['https://example', '.com/path/to', '/page.html']), ('control layout', ['https://t.co/AbCdEf', 11], ['https://t', '.co/AbCdEf'])], [('regression: hard break fallback', ['http://a.b.org/x//y?q=1&r=2', 4], ['http', '://a', '.b', '.org', '/x//', 'y?q=', '1&r=', '2']), ('regression: hard break fallback', ['https://sub.domain.example.co.uk/~user/page', 6], ['https:', '//sub', '.domai', 'n', '.examp', 'le.co', '.uk/', '~user', '/page']), ('regression: hard break fallback', ['https://t.co/AbCdEf', 5], ['https', '://t', '.co', '/AbCd', 'Ef']), ('regression: hard break fallback', ['https://t.co/AbCdEf', 6], ['https:', '//t.co', '/AbCdE', 'f']), ('double slash inside path', ['http://a.b.org/x//y?q=1&r=2', 10], ['http://a.b', '.org/x//y', '?q=1&r=2']), ('break after scheme', ['https://example.com/path/to/page.html', 8], ['https://', 'example', '.com', '/path/to', '/page', '.html']), ('control layout', ['https://example.com/path/to/page.html', 11], ['https://', 'example.com', '/path/to', '/page.html']), ('control layout', ['http://a.b.org/x//y?q=1&r=2', 7], ['http://', 'a.b.org', '/x//y?q', '=1&r=2'])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Unbreakable URL runs overflow the line.

Input [url, width]. Break opportunities (no hyphen added): after ":"; after "//" (never between its slashes); before a single "/"; before . - _ ? # % ~; before or after = and &. While the rest exceeds the width, break at the latest opportunity within width characters, else hard-break at width. Return lines.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, default = x
    depth = 0
    for i, c in enumerate(classes):
        if c in ('LRI', 'RLI', 'FSI'):
            depth += 1
        elif c == 'PDI':
            if depth > 0:
                depth -= 1
        elif depth == 0:
            if c == 'L':
                return [0, i]
            if c == 'R':
                return [1, i]
    return [default, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('regression: Arabic letter strength', [['AL'], 0], [1, 0]), ('regression: Arabic letter strength', [['AL', 'EN'], 1], [1, 0]), ('partial-repair probe', [['AN', 'R', 'L', 'ON', 'L'], 1], [1, 1]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('control layout', [['WS', 'FSI'], 0], [0, None]), ('control layout', [['EN', 'R'], 0], [1, 1])], [('regression: Arabic letter strength', [['AL', 'ON', 'PDI', 'AL', 'WS'], 1], [1, 0]), ('regression: Arabic letter strength', [['WS', 'WS', 'AL', 'AN', 'WS', 'PDI'], 0], [1, 2]), ('regression: Arabic letter strength', [['AL', 'RLI', 'PDI', 'WS', 'FSI', 'ON', 'L'], 1], [1, 0]), ('partial-repair probe', [['AN', 'ES', 'L', 'L', 'WS', 'L', 'AL', 'R'], 0], [0, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('control layout', [['PDI', 'FSI', 'L', 'NSM', 'ON', 'R'], 1], [1, None]), ('control layout', [['R', 'WS', 'ON', 'AN', 'RLI', 'RLI'], 0], [1, 0])], [('regression: Arabic letter strength', [['AL', 'EN'], 1], [1, 0]), ('regression: Arabic letter strength', [['ON', 'AL', 'FSI'], 0], [1, 1]), ('regression: Arabic letter strength', [['AL', 'L', 'WS'], 0], [1, 0]), ('partial-repair probe', [['LRE', 'AN', 'L', 'AN'], 1], [0, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('control layout', [['EN', 'PDI', 'L', 'EN', 'FSI'], 1], [0, 2]), ('control layout', [['RLI', 'PDI', 'RLI', 'EN'], 1], [1, None])], [('regression: Arabic letter strength', [['EN', 'LRE', 'AL', 'FSI'], 1], [1, 2]), ('regression: Arabic letter strength', [['ON', 'AL', 'ES', 'L', 'PDI', 'AN', 'NSM', 'LRI', 'ON'], 0], [1, 1]), ('partial-repair probe', [['ON', 'AN', 'RLI', 'RLI', 'R', 'R', 'EN', 'EN', 'L'], 1], [1, None]), ('regression: Arabic letter strength', [['AL', 'R', 'ON', 'AN', 'AL', 'EN', 'L', 'PDI', 'PDI', 'L'], 0], [1, 0]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['L', 'R', 'R', 'NSM', 'L', 'PDI', 'PDI', 'EN'], 1], [0, 0]), ('control layout', [['LRI', 'ES'], 0], [0, None])], [('regression: Arabic letter strength', [['AL', 'PDI'], 1], [1, 0]), ('regression: Arabic letter strength', [['AL', 'RLI', 'PDI', 'WS', 'FSI', 'ON', 'L'], 1], [1, 0]), ('regression: Arabic letter strength', [['NSM', 'AL', 'PDI', 'ON', 'AN', 'WS'], 0], [1, 1]), ('regression: Arabic letter strength', [['ON', 'AL'], 1], [1, 1]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['WS'], 0], [0, None]), ('control layout', [['EN'], 0], [0, None])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, default = x
    depth = 0
    for i, c in enumerate(classes):
        if c in ('LRI', 'RLI', 'FSI'):
            depth += 1
        elif c == 'PDI':
            if depth > 0:
                depth -= 1
        elif depth == 0:
            if c == 'L':
                return [0, i]
            if c in ('R', 'AN'):
                return [1, i]
    return [default, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('regression: Arabic letter strength', [['AL'], 0], [1, 0]), ('regression: Arabic letter strength', [['AL', 'EN'], 1], [1, 0]), ('partial-repair probe', [['AN', 'R', 'L', 'ON', 'L'], 1], [1, 1]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('control layout', [['WS', 'FSI'], 0], [0, None]), ('control layout', [['EN', 'R'], 0], [1, 1])], [('regression: Arabic letter strength', [['AL', 'ON', 'PDI', 'AL', 'WS'], 1], [1, 0]), ('regression: Arabic letter strength', [['WS', 'WS', 'AL', 'AN', 'WS', 'PDI'], 0], [1, 2]), ('regression: Arabic letter strength', [['AL', 'RLI', 'PDI', 'WS', 'FSI', 'ON', 'L'], 1], [1, 0]), ('partial-repair probe', [['AN', 'ES', 'L', 'L', 'WS', 'L', 'AL', 'R'], 0], [0, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('control layout', [['PDI', 'FSI', 'L', 'NSM', 'ON', 'R'], 1], [1, None]), ('control layout', [['R', 'WS', 'ON', 'AN', 'RLI', 'RLI'], 0], [1, 0])], [('regression: Arabic letter strength', [['AL', 'EN'], 1], [1, 0]), ('regression: Arabic letter strength', [['ON', 'AL', 'FSI'], 0], [1, 1]), ('regression: Arabic letter strength', [['AL', 'L', 'WS'], 0], [1, 0]), ('partial-repair probe', [['LRE', 'AN', 'L', 'AN'], 1], [0, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('control layout', [['EN', 'PDI', 'L', 'EN', 'FSI'], 1], [0, 2]), ('control layout', [['RLI', 'PDI', 'RLI', 'EN'], 1], [1, None])], [('regression: Arabic letter strength', [['EN', 'LRE', 'AL', 'FSI'], 1], [1, 2]), ('regression: Arabic letter strength', [['ON', 'AL', 'ES', 'L', 'PDI', 'AN', 'NSM', 'LRI', 'ON'], 0], [1, 1]), ('partial-repair probe', [['ON', 'AN', 'RLI', 'RLI', 'R', 'R', 'EN', 'EN', 'L'], 1], [1, None]), ('regression: Arabic letter strength', [['AL', 'R', 'ON', 'AN', 'AL', 'EN', 'L', 'PDI', 'PDI', 'L'], 0], [1, 0]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['L', 'R', 'R', 'NSM', 'L', 'PDI', 'PDI', 'EN'], 1], [0, 0]), ('control layout', [['LRI', 'ES'], 0], [0, None])], [('regression: Arabic letter strength', [['AL', 'PDI'], 1], [1, 0]), ('regression: Arabic letter strength', [['AL', 'RLI', 'PDI', 'WS', 'FSI', 'ON', 'L'], 1], [1, 0]), ('regression: Arabic letter strength', [['NSM', 'AL', 'PDI', 'ON', 'AN', 'WS'], 0], [1, 1]), ('regression: Arabic letter strength', [['ON', 'AL'], 1], [1, 1]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['WS'], 0], [0, None]), ('control layout', [['EN'], 0], [0, None])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Paragraphs starting with Arabic letters default to left-to-right.

Input [bidi classes, default level]. Scan for the first L (level 0) or R/AL (level 1), skipping characters between an isolate initiator (LRI, RLI, FSI) and its matching PDI (nesting counted; an unmatched PDI is ignored). Embedding codes are not skipped. Return [level, index of deciding character] or [default, None].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, default = x
    depth = 0
    for i, c in enumerate(classes):
        if c in ('LRI', 'RLI', 'FSI'):
            depth += 1
        elif c == 'PDI':
            depth -= 1
        elif depth == 0:
            if c == 'L':
                return [0, i]
            if c in ('R', 'AL'):
                return [1, i]
    return [default, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('regression: unmatched PDI', [['LRE', 'PDI', 'AL', 'PDI', 'AN', 'RLI', 'WS', 'AL', 'R', 'EN'], 1], [1, 2]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['AL', 'PDI', 'L', 'WS', 'EN', 'L', 'ES', 'ON'], 0], [1, 0]), ('control layout', [['WS', 'L', 'PDI', 'WS', 'AL'], 1], [0, 1])], [('regression: unmatched PDI', [['PDI', 'PDI', 'L', 'ON', 'L', 'EN', 'ON', 'RLI'], 0], [0, 2]), ('regression: unmatched PDI', [['PDI', 'LRI', 'AL', 'ON'], 1], [1, None]), ('partial-repair probe', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('partial-repair probe', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['LRI', 'AL', 'L', 'ON', 'AL', 'L', 'WS'], 1], [1, None]), ('control layout', [['RLI', 'WS', 'ON', 'ON', 'ON', 'L', 'R', 'LRI'], 0], [0, None])], [('regression: unmatched PDI', [['PDI', 'FSI', 'L', 'NSM', 'R', 'NSM', 'L', 'EN', 'WS', 'R'], 1], [1, None]), ('regression: unmatched PDI', [['PDI', 'AL', 'ON', 'PDI', 'L', 'WS', 'FSI', 'PDI', 'ON', 'LRI'], 0], [1, 1]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['WS'], 1], [1, None]), ('control layout', [['LRE', 'WS', 'LRI'], 0], [0, None])], [('regression: unmatched PDI', [['ON', 'PDI', 'LRE', 'L', 'AN', 'R', 'AL'], 1], [0, 3]), ('regression: unmatched PDI', [['EN', 'PDI', 'L', 'EN', 'FSI'], 1], [0, 2]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['WS', 'LRI', 'FSI', 'PDI', 'R', 'LRE'], 1], [1, None]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['EN', 'FSI', 'FSI', 'FSI', 'R', 'FSI', 'L'], 0], [0, None]), ('control layout', [['NSM', 'AN'], 1], [1, None])], [('regression: unmatched PDI', [['PDI', 'PDI', 'LRI', 'WS', 'LRI', 'PDI', 'LRI', 'R', 'EN', 'L'], 1], [1, None]), ('regression: unmatched PDI', [['PDI', 'AN', 'R', 'FSI', 'ES', 'EN'], 0], [1, 2]), ('partial-repair probe', [['EN', 'ES', 'LRI', 'WS', 'WS', 'FSI', 'PDI', 'AL'], 1], [1, None]), ('partial-repair probe', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['WS', 'AN', 'R', 'WS', 'EN', 'WS', 'PDI'], 1], [1, 2]), ('control layout', [['AN'], 1], [1, None])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, default = x
    depth = 0
    for i, c in enumerate(classes):
        if c in ('LRI', 'RLI', 'FSI'):
            depth += 1
        elif c == 'PDI':
            depth = 0
        elif depth == 0:
            if c == 'L':
                return [0, i]
            if c in ('R', 'AL'):
                return [1, i]
    return [default, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('regression: unmatched PDI', [['LRE', 'PDI', 'AL', 'PDI', 'AN', 'RLI', 'WS', 'AL', 'R', 'EN'], 1], [1, 2]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['LRI', 'ON', 'RLI', 'L', 'PDI', 'AL', 'R', 'WS'], 0], [0, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['AL', 'PDI', 'L', 'WS', 'EN', 'L', 'ES', 'ON'], 0], [1, 0]), ('control layout', [['WS', 'L', 'PDI', 'WS', 'AL'], 1], [0, 1])], [('regression: unmatched PDI', [['PDI', 'PDI', 'L', 'ON', 'L', 'EN', 'ON', 'RLI'], 0], [0, 2]), ('regression: unmatched PDI', [['PDI', 'LRI', 'AL', 'ON'], 1], [1, None]), ('partial-repair probe', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('partial-repair probe', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['LRI', 'AL', 'L', 'ON', 'AL', 'L', 'WS'], 1], [1, None]), ('control layout', [['RLI', 'WS', 'ON', 'ON', 'ON', 'L', 'R', 'LRI'], 0], [0, None])], [('regression: unmatched PDI', [['PDI', 'FSI', 'L', 'NSM', 'R', 'NSM', 'L', 'EN', 'WS', 'R'], 1], [1, None]), ('regression: unmatched PDI', [['PDI', 'AL', 'ON', 'PDI', 'L', 'WS', 'FSI', 'PDI', 'ON', 'LRI'], 0], [1, 1]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['LRI', 'EN', 'AN', 'LRI', 'RLI', 'AL', 'R', 'AN', 'PDI', 'R'], 1], [1, None]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['WS'], 1], [1, None]), ('control layout', [['LRE', 'WS', 'LRI'], 0], [0, None])], [('regression: unmatched PDI', [['ON', 'PDI', 'LRE', 'L', 'AN', 'R', 'AL'], 1], [0, 3]), ('regression: unmatched PDI', [['EN', 'PDI', 'L', 'EN', 'FSI'], 1], [0, 2]), ('partial-repair probe', [['ON', 'RLI', 'ON', 'LRI', 'AL', 'PDI', 'L', 'NSM'], 0], [0, None]), ('partial-repair probe', [['WS', 'LRI', 'FSI', 'PDI', 'R', 'LRE'], 1], [1, None]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['EN', 'FSI', 'FSI', 'FSI', 'R', 'FSI', 'L'], 0], [0, None]), ('control layout', [['NSM', 'AN'], 1], [1, None])], [('regression: unmatched PDI', [['PDI', 'PDI', 'LRI', 'WS', 'LRI', 'PDI', 'LRI', 'R', 'EN', 'L'], 1], [1, None]), ('regression: unmatched PDI', [['PDI', 'AN', 'R', 'FSI', 'ES', 'EN'], 0], [1, 2]), ('partial-repair probe', [['EN', 'ES', 'LRI', 'WS', 'WS', 'FSI', 'PDI', 'AL'], 1], [1, None]), ('partial-repair probe', [['LRI', 'WS', 'RLI', 'AN', 'PDI', 'AN', 'R', 'LRE', 'ES', 'L'], 1], [1, None]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('control layout', [['WS', 'AN', 'R', 'WS', 'EN', 'WS', 'PDI'], 1], [1, 2]), ('control layout', [['AN'], 1], [1, None])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A stray PDI hides the rest of the paragraph from direction detection.

Input [bidi classes, default level]. Scan for the first L (level 0) or R/AL (level 1), skipping characters between an isolate initiator (LRI, RLI, FSI) and its matching PDI (nesting counted; an unmatched PDI is ignored). Embedding codes are not skipped. Return [level, index of deciding character] or [default, None].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, default = x
    depth = 0
    for i, c in enumerate(classes):
        if c in ('LRI', 'RLI'):
            depth += 1
        elif c == 'PDI':
            if depth > 0:
                depth -= 1
        elif depth == 0:
            if c == 'L':
                return [0, i]
            if c in ('R', 'AL'):
                return [1, i]
    return [default, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'WS', 'AL', 'L'], 1], [1, None]), ('partial-repair probe', [['LRE', 'R', 'WS', 'EN', 'L'], 1], [1, 1]), ('partial-repair probe', [['EN', 'LRE', 'AL', 'FSI'], 1], [1, 2]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'AN', 'R', 'FSI', 'LRI', 'AN', 'FSI', 'WS', 'EN', 'WS'], 1], [1, 2]), ('control layout', [['LRI', 'PDI', 'FSI', 'PDI', 'PDI', 'WS', 'PDI', 'L'], 0], [0, 7])], [('regression: first-strong isolate initiator', [['FSI', 'L'], 0], [0, None]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'ON', 'R', 'RLI', 'WS', 'FSI', 'AL'], 1], [1, None]), ('partial-repair probe', [['PDI', 'RLI', 'LRE', 'ON', 'EN', 'PDI', 'R', 'L'], 0], [1, 6]), ('partial-repair probe', [['LRE', 'R', 'WS', 'EN', 'L'], 1], [1, 1]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'AL', 'FSI'], 0], [1, 1]), ('control layout', [['AL', 'PDI', 'WS', 'ON', 'PDI'], 1], [1, 0])], [('regression: first-strong isolate initiator', [['EN', 'FSI', 'L', 'RLI'], 1], [1, None]), ('regression: first-strong isolate initiator', [['FSI', 'R', 'L', 'LRE'], 1], [1, None]), ('partial-repair probe', [['LRE', 'AN', 'L', 'AN'], 1], [0, 2]), ('partial-repair probe', [['EN', 'LRE', 'R'], 0], [1, 2]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'R', 'AL', 'ES', 'PDI', 'RLI', 'AN', 'RLI', 'WS', 'LRI'], 1], [1, 1]), ('control layout', [['FSI', 'LRI', 'L', 'ON', 'FSI', 'FSI', 'ON', 'RLI', 'R', 'PDI'], 0], [0, None])], [('regression: first-strong isolate initiator', [['NSM', 'FSI', 'R', 'PDI', 'AL', 'AN', 'WS', 'PDI'], 0], [1, 4]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'ON', 'R', 'RLI', 'WS', 'FSI', 'AL'], 1], [1, None]), ('partial-repair probe', [['PDI', 'LRE', 'ON', 'R', 'FSI', 'WS'], 1], [1, 3]), ('partial-repair probe', [['PDI', 'RLI', 'LRE', 'ON', 'EN', 'PDI', 'R', 'L'], 0], [1, 6]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('control layout', [['WS', 'R', 'LRI', 'RLI', 'R', 'EN', 'ON', 'R'], 0], [1, 1]), ('control layout', [['FSI', 'ES', 'NSM', 'NSM', 'WS', 'PDI', 'AL', 'AL', 'ON', 'ES'], 1], [1, 6])], [('regression: first-strong isolate initiator', [['FSI', 'AL', 'ON', 'RLI', 'FSI', 'PDI'], 1], [1, None]), ('regression: first-strong isolate initiator', [['FSI', 'L', 'EN', 'LRI'], 1], [1, None]), ('partial-repair probe', [['LRE', 'AN', 'L', 'AN'], 1], [0, 2]), ('partial-repair probe', [['ON', 'ES', 'LRE', 'R', 'L', 'AN', 'RLI', 'R', 'L'], 1], [1, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['FSI', 'ON', 'LRI', 'RLI', 'LRE', 'AN', 'LRI', 'LRI'], 0], [0, None]), ('control layout', [['PDI', 'ON', 'PDI', 'FSI', 'EN'], 1], [1, None])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    classes, default = x
    depth = 0
    for i, c in enumerate(classes):
        if c in ('LRI', 'RLI', 'FSI', 'LRE'):
            depth += 1
        elif c == 'PDI':
            if depth > 0:
                depth -= 1
        elif depth == 0:
            if c == 'L':
                return [0, i]
            if c in ('R', 'AL'):
                return [1, i]
    return [default, None]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'WS', 'AL', 'L'], 1], [1, None]), ('partial-repair probe', [['LRE', 'R', 'WS', 'EN', 'L'], 1], [1, 1]), ('partial-repair probe', [['EN', 'LRE', 'AL', 'FSI'], 1], [1, 2]), ('Arabic letter decides', [['ON', 'AL', 'L'], 0], [1, 1]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'AN', 'R', 'FSI', 'LRI', 'AN', 'FSI', 'WS', 'EN', 'WS'], 1], [1, 2]), ('control layout', [['LRI', 'PDI', 'FSI', 'PDI', 'PDI', 'WS', 'PDI', 'L'], 0], [0, 7])], [('regression: first-strong isolate initiator', [['FSI', 'L'], 0], [0, None]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'ON', 'R', 'RLI', 'WS', 'FSI', 'AL'], 1], [1, None]), ('partial-repair probe', [['PDI', 'RLI', 'LRE', 'ON', 'EN', 'PDI', 'R', 'L'], 0], [1, 6]), ('partial-repair probe', [['LRE', 'R', 'WS', 'EN', 'L'], 1], [1, 1]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'AL', 'FSI'], 0], [1, 1]), ('control layout', [['AL', 'PDI', 'WS', 'ON', 'PDI'], 1], [1, 0])], [('regression: first-strong isolate initiator', [['EN', 'FSI', 'L', 'RLI'], 1], [1, None]), ('regression: first-strong isolate initiator', [['FSI', 'R', 'L', 'LRE'], 1], [1, None]), ('partial-repair probe', [['LRE', 'AN', 'L', 'AN'], 1], [0, 2]), ('partial-repair probe', [['EN', 'LRE', 'R'], 0], [1, 2]), ('stray PDI before isolate', [['PDI', 'RLI', 'L', 'PDI', 'R'], 0], [1, 4]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('control layout', [['ON', 'R', 'AL', 'ES', 'PDI', 'RLI', 'AN', 'RLI', 'WS', 'LRI'], 1], [1, 1]), ('control layout', [['FSI', 'LRI', 'L', 'ON', 'FSI', 'FSI', 'ON', 'RLI', 'R', 'PDI'], 0], [0, None])], [('regression: first-strong isolate initiator', [['NSM', 'FSI', 'R', 'PDI', 'AL', 'AN', 'WS', 'PDI'], 0], [1, 4]), ('regression: first-strong isolate initiator', [['PDI', 'FSI', 'ON', 'R', 'RLI', 'WS', 'FSI', 'AL'], 1], [1, None]), ('partial-repair probe', [['PDI', 'LRE', 'ON', 'R', 'FSI', 'WS'], 1], [1, 3]), ('partial-repair probe', [['PDI', 'RLI', 'LRE', 'ON', 'EN', 'PDI', 'R', 'L'], 0], [1, 6]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('FSI content skipped', [['FSI', 'R', 'PDI', 'L'], 1], [0, 3]), ('control layout', [['WS', 'R', 'LRI', 'RLI', 'R', 'EN', 'ON', 'R'], 0], [1, 1]), ('control layout', [['FSI', 'ES', 'NSM', 'NSM', 'WS', 'PDI', 'AL', 'AL', 'ON', 'ES'], 1], [1, 6])], [('regression: first-strong isolate initiator', [['FSI', 'AL', 'ON', 'RLI', 'FSI', 'PDI'], 1], [1, None]), ('regression: first-strong isolate initiator', [['FSI', 'L', 'EN', 'LRI'], 1], [1, None]), ('partial-repair probe', [['LRE', 'AN', 'L', 'AN'], 1], [0, 2]), ('partial-repair probe', [['ON', 'ES', 'LRE', 'R', 'L', 'AN', 'RLI', 'R', 'L'], 1], [1, 3]), ('numbers are not strong', [['EN', 'ON', 'R'], 0], [1, 2]), ('nested isolates', [['LRI', 'RLI', 'R', 'PDI', 'L', 'PDI', 'R'], 0], [1, 6]), ('control layout', [['FSI', 'ON', 'LRI', 'RLI', 'LRE', 'AN', 'LRI', 'LRI'], 0], [0, None]), ('control layout', [['PDI', 'ON', 'PDI', 'FSI', 'EN'], 1], [1, None])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Letters inside an FSI isolate decide the paragraph direction.

Input [bidi classes, default level]. Scan for the first L (level 0) or R/AL (level 1), skipping characters between an isolate initiator (LRI, RLI, FSI) and its matching PDI (nesting counted; an unmatched PDI is ignored). Embedding codes are not skipped. Return [level, index of deciding character] or [default, None].

split: open-access