Browse Source

Adding some Builder tests

tags/v0.2
Ben Kurtovic 11 years ago
parent
commit
cb23587ab6
1 changed files with 25 additions and 2 deletions
  1. +25
    -2
      tests/test_builder.py

+ 25
- 2
tests/test_builder.py View File

@@ -26,6 +26,8 @@ import unittest
from mwparserfromhell.nodes import (Argument, Comment, Heading, HTMLEntity, from mwparserfromhell.nodes import (Argument, Comment, Heading, HTMLEntity,
Tag, Template, Text, Wikilink) Tag, Template, Text, Wikilink)
from mwparserfromhell.nodes.extras import Attribute, Parameter from mwparserfromhell.nodes.extras import Attribute, Parameter
from mwparserfromhell.parser import tokens
from mwparserfromhell.parser.builder import Builder
from mwparserfromhell.smart_list import SmartList from mwparserfromhell.smart_list import SmartList
from mwparserfromhell.wikicode import Wikicode from mwparserfromhell.wikicode import Wikicode


@@ -36,13 +38,34 @@ wrap = lambda L: Wikicode(SmartList(L))
class TestBuilder(TreeEqualityTestCase): class TestBuilder(TreeEqualityTestCase):
"""Tests for the builder, which turns tokens into Wikicode objects.""" """Tests for the builder, which turns tokens into Wikicode objects."""


def setUp(self):
self.builder = Builder()

def test_text(self): def test_text(self):
"""tests for building Text nodes""" """tests for building Text nodes"""
pass
tests = [
([tokens.Text(text="foobar")], wrap([Text("foobar")])),
([tokens.Text(text="fóóbar")], wrap([Text("fóóbar")])),
([tokens.Text(text="spam"), tokens.Text(text="eggs")],
wrap([Text("spam"), Text("eggs")])),
]
for test, valid in tests:
self.assertWikicodeEqual(valid, self.builder.build(test))


def test_template(self): def test_template(self):
"""tests for building Template nodes""" """tests for building Template nodes"""
pass
tests = [
([tokens.TemplateOpen(), tokens.Text(text="foobar"), tokens.TemplateClose()],
wrap([Template(wrap([Text("foobar")]))])),
([tokens.TemplateOpen(), tokens.Text(text="spam"), tokens.Text(text="eggs"), tokens.TemplateClose()],
wrap([Template(wrap([Text("spam"), Text("eggs")]))])),
([tokens.TemplateOpen(), tokens.Text(text="foo"), tokens.TemplateParamSeparator(), tokens.Text(text="bar"), tokens.TemplateClose()],
wrap([Template(wrap([Text("foo")]), params=[Parameter(wrap([Text("1")]), wrap([Text("bar")]), showkey=False)])])),
([tokens.TemplateOpen(), tokens.Text(text="foo"), tokens.TemplateParamSeparator(), tokens.Text(text="bar"), tokens.TemplateParamEquals(), tokens.Text(text="baz"), tokens.TemplateClose()],
wrap([Template(wrap([Text("foo")]), params=[Parameter(wrap([Text("bar")]), wrap([Text("baz")]))])])),
]
for test, valid in tests:
self.assertWikicodeEqual(valid, self.builder.build(test))


def test_argument(self): def test_argument(self):
"""tests for building Argument nodes""" """tests for building Argument nodes"""


Loading…
Cancel
Save