# HG changeset patch
# User athomas
# Date 1181124467 0
# Node ID 1997f7af845c2bfcb5e5146c6f0d31c8f6ccc3c7
# Parent cabd80e75dad58ce2e776a7137dfe563286cbeea
Add a test for buffer reset by copy().
diff --git a/genshi/filters/transform.py b/genshi/filters/transform.py
--- a/genshi/filters/transform.py
+++ b/genshi/filters/transform.py
@@ -419,10 +419,25 @@
>>> buffer = StreamBuffer()
>>> html = HTML('
Some Title'
... 'Some body text.')
- >>> print html | Transformer('.//title/text()').copy(buffer) \\
- ... .select('.//body').prepend(tag.h1(buffer))
- Some TitleSome Title
Some
- body text.
+ >>> print html | Transformer('title/text()').copy(buffer) \\
+ ... .select('body').prepend(tag.h1(buffer))
+ Some TitleSome
+ Title
Some body text.
+
+ To ensure that a transformation can be reused deterministically, the
+ contents of ``buffer`` is replaced by the ``copy()`` operation:
+
+ >>> print buffer
+ Some Title
+ >>> print html | Transformer('head/title/text()').copy(buffer) \\
+ ... .select('body/em').copy(buffer).select('body') \\
+ ... .prepend(tag.h1(buffer))
+ Some
+ Titlebody
Some body
+ text.
+ >>> print buffer
+ body
+
:param buffer: the `StreamBuffer` in which the selection should be
stored