Well,
the
promised
explanations.
The screenshot
shows
work-log.el
debugging session. The "a-a-i-i-d" patchwork you see there is a work
log model (more on this below). A work log is a sequence of dates,
active entries, and inactive entries (the latter include comments);
see example
here.
In short: resolved tasks == inactive, pending ones == active, that's it.
Now. `work-log-hide-inactive' function (`C-c C-h') lets user
concentrate on open tasks, making inactive "noise" invisible.
The first implementation of the hiding function did hide resolved
tasks but also left some dates with no entries at all hanging
void. Like this:
2009-07-03
http://lib/it/processMMS: update scenarios' table
2009-07-02
2009-07-01
import `recsep' to CVS
Note the "hanging" 2009-07-02.
Okay. Let's omit the boring details (head scratching, pencil
sketching, and a couple of "aha!" moments) and goto right to
the way I debugged the damn function...
Here the simplified model of a work log suffice: a "d-a-i"
sequence -- sequence of ['d', 'a', 'i', '-'] characters, where
'd' represents date, 'a' -- active entry, and 'i' --
inactive. Hyphen ('-') is either empty line or the continuation of
previous entry (a task entry in real log can consist of several
lines).
All we need to do is change a bit the hiding function (substitute
regexps, replace `forward-line' with `forward-char', and show the
"hidden" regions in inverted color instead of actually hiding them)
and run it on a bunch of dai-sequences.
Testing input is easy to generate:
import Data.List (permutations)
main = putStrLn $ concatMap (\(x,y) -> x++y) (xs `zip` repeat "-")
where xs = concat $ permutations ["a", "a", "i", "i", "d"]
Given "i-d-a-d-i-d-a-i-" we get:
i-d-a-d-i-d-a-i-
Do you see a hanging date? The hidden (black) region in the middle
should cover preceding date ('d-') but it does not.
Well, you got the idea. Once the testing routine was established, it was easy
to fix the bug.
i-d-a-d-i-d-a-i-
Q.E.D.
* * *
Yes, and while you're here, I'd like to recommend this post:
Benefits
of automated functional testing (was: Why unit testing is a waste of
time)
Have fun!