The SQLite store keeps every chapter revision, so a chapter that the site removes stays in the book. The merge puts new chapters after the chapter that comes before them on the site. Diffs compare text, not HTML, and replacement rules run on chapter HTML when a book is built.
34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
from bindery.diffing import diff_html, html_to_blocks, text_hash
|
|
|
|
|
|
def test_random_class_names_do_not_count_as_changes():
|
|
a = '<div><p class="cnMwZG">Hello <em>there</em>.</p><p class="x1">Second</p></div>'
|
|
b = '<div><p class="zzQ99">Hello <em>there</em>.</p><p class="y2">Second</p></div>'
|
|
assert text_hash(a) == text_hash(b)
|
|
assert html_to_blocks(a) == ["Hello there.", "Second"]
|
|
|
|
|
|
def test_text_changes_change_the_hash():
|
|
assert text_hash("<p>one</p>") != text_hash("<p>two</p>")
|
|
|
|
|
|
def test_diff_counts_and_word_level_changes():
|
|
old = "<p>Same.</p><p>The cat sat.</p><p>Gone.</p>"
|
|
new = "<p>Same.</p><p>The dog sat.</p><p>Gone.</p><p>Added.</p>"
|
|
result = diff_html(old, new)
|
|
assert (result["changed"], result["added"], result["removed"]) == (1, 1, 0)
|
|
assert "<del>cat</del><ins>dog</ins>" in result["html"]
|
|
assert not result["identical"]
|
|
|
|
|
|
def test_diff_output_is_escaped():
|
|
result = diff_html("<p>a</p>", "<p><script>alert(1)</script></p>")
|
|
assert "<script>" not in result["html"]
|
|
assert "<script>" in result["html"]
|
|
|
|
|
|
def test_source_diff_sees_markup_changes():
|
|
old, new = "<p>Hi</p>", '<p class="x">Hi</p>'
|
|
assert diff_html(old, new)["identical"]
|
|
assert not diff_html(old, new, source=True)["identical"]
|