2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
8 from document_renderer
import DocumentRenderer
11 class _FakeTableOfContentsRenderer(object):
12 def __init__(self
, string
):
16 return self
._string
, []
19 class DocumentRendererUnittest(unittest
.TestCase
):
21 self
._renderer
= DocumentRenderer(_FakeTableOfContentsRenderer('t-o-c'))
23 def testNothingToSubstitute(self
):
24 document
= 'hello world'
26 text
, warnings
= self
._renderer
.Render(document
)
27 self
.assertEqual(document
, text
)
28 self
.assertEqual([], warnings
)
30 text
, warnings
= self
._renderer
.Render(document
, render_title
=True)
31 self
.assertEqual(document
, text
)
32 self
.assertEqual(['Expected a title'], warnings
)
35 document
= '<h1>title</h1> then $(title) then another $(title)'
37 text
, warnings
= self
._renderer
.Render(document
)
38 self
.assertEqual(document
, text
)
39 self
.assertEqual(['Found unexpected title "title"'], warnings
)
41 text
, warnings
= self
._renderer
.Render(document
, render_title
=True)
42 self
.assertEqual('<h1>title</h1> then title then another $(title)', text
)
43 self
.assertEqual([], warnings
)
46 document
= ('here is a toc $(table_of_contents) '
47 'and another $(table_of_contents)')
48 expected_document
= 'here is a toc t-o-c and another $(table_of_contents)'
50 text
, warnings
= self
._renderer
.Render(document
)
51 self
.assertEqual(expected_document
, text
)
52 self
.assertEqual([], warnings
)
54 text
, warnings
= self
._renderer
.Render(document
, render_title
=True)
55 self
.assertEqual(expected_document
, text
)
56 self
.assertEqual(['Expected a title'], warnings
)
58 def testTitleAndToc(self
):
59 document
= '<h1>title</h1> $(title) and $(table_of_contents)'
61 text
, warnings
= self
._renderer
.Render(document
)
62 self
.assertEqual('<h1>title</h1> $(title) and t-o-c', text
)
63 self
.assertEqual(['Found unexpected title "title"'], warnings
)
65 text
, warnings
= self
._renderer
.Render(document
, render_title
=True)
66 self
.assertEqual('<h1>title</h1> title and t-o-c', text
)
67 self
.assertEqual([], warnings
)
70 if __name__
== '__main__':