# HG changeset patch
# User athomas
# Date 1181124467 0
# Node ID ca20975cdeeeb36aa8f9b95272d0eca298654f26
# Parent 5fbc1cde74d6116c2b4c2f033df771d04a2c175b
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