The present generation of unit tests not only verify perfect import, but 
ensure that the outline has expected structure, more or less.

The outline of such tests is:

s = r'''
The input, maybe many lines.
'''
table = ( a list of expected headlines )
try:
    c.importCommands.coffeeScriptUnitTest(p,s=s,showTree=True)
    if 1: # Verify that the test produces the expected headlines.
      p2 = c.p.firstChild().firstChild()
      for h in table:
          assert p2.h == h, (p2.h, h)
          p2.moveToThreadNext()
finally:
    if 1: # clean up
        p.deleteAllChildren()

If the test produces a large outline, it would be unbearable to create the 
table by hand.  Instead, I used the following, now in scripts.leo:

@button make-table
'''
Create a table of expected headlines in a unit test.
After running this, copy the table from the console.
'''
g.cls()
# Proper escapes are tricky.
table = [
    '"%s",' % p.h.replace('\\', '\\\\').replace('"', '\\"')
        for p in c.p.subtree()
]
print("table = (\n    %s\n)" % '\n    '.join(table))

Python's string capabilities are yet another reason to love python. Much 
better than snobol or icon, two old languages that were supposedly geared 
to pattern matching and substitution.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to