def setUp(self):
     self.visitor = SpecDescVisitor()
Esempio n. 2
0
 def setUp(self):
     self.visitor = SpecDescVisitor()
class TestSpecDescVisitor(TestCase):
    def setUp(self):
        self.visitor = SpecDescVisitor()

    def assert_specdesc(self, html, items, issues):
        parsed = kumascript_grammar.parse(html)
        self.visitor.visit(parsed)
        actual = [item.to_html() for item in self.visitor.desc_items]
        self.assertEqual(items, actual)
        self.assertEqual(self.visitor.issues, issues)

    def test_empty(self):
        self.assert_specdesc('<td></td>', [''], [])

    def test_plain_text(self):
        self.assert_specdesc('<td> Plain text </td>', ['Plain text'], [])

    def test_html(self):
        html = '<td>Defines <code>right</code> as animatable.</td>'
        expected = ['Defines', '<code>right</code>', 'as animatable.']
        self.assert_specdesc(html, expected, [])

    def test_styled(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/inherit
        html = """<td style=\"vertical-align: top;\">
            Initial definition.
        </td>"""
        expected = ['Initial definition.']
        issue = (
            'unexpected_attribute', 4, 32,
            {'expected': 'no attributes', 'node_type': 'td', 'ident': 'style',
             'value': 'vertical-align: top;'})
        self.assert_specdesc(html, expected, [issue])

    def test_kumascript(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align
        html = (
            '<td>Add the {{ xref_csslength() }} value and allows it to be'
            ' applied to element with a {{ cssxref("display") }} type of'
            ' <code>table-cell</code>.</td>')
        expected = [
            'Add the',
            ('<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/'
             'length"><code>&lt;length&gt;</code></a>'),
            'value and allows it to be applied to element with a',
            ('<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/'
             'display"><code>display</code></a>'),
            'type of', '<code>table-cell</code>', '.']
        self.assert_specdesc(html, expected, [])

    def test_kumascript_spec2(self):
        # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/data
        html = "<td>No change from {{Spec2('HTML5 W3C')}}</td>"
        expected = ['No change from', 'specification HTML5 W3C']
        issues = [
            ('unexpected_kumascript', 19, 41,
             {'name': 'Spec2', 'args': ['HTML5 W3C'],
              'scope': 'specification description',
              'kumascript': '{{Spec2("HTML5 W3C")}}',
              'expected_scopes': 'specification maturity'}),
            ('unknown_spec', 19, 41, {'key': 'HTML5 W3C'})]
        self.assert_specdesc(html, expected, issues)

    def test_kumascript_experimental_inline(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/position_value
        html = (
            '<td>Defines <code>&lt;position&gt;</code> explicitly and extends'
            ' it to support offsets from any edge. {{ experimental_inline() }}'
            '</td>')
        expected = [
            'Defines', '<code>&lt;position&gt;</code>',
            'explicitly and extends it to support offsets from any edge.', '']
        kname = 'experimental_inline'
        issue = (
            'unexpected_kumascript', 102, 129,
            {'args': [], 'kumascript': '{{%s}}' % kname,
             'name': kname, 'scope': 'specification description',
             'expected_scopes': 'compatibility feature'})
        self.assert_specdesc(html, expected, [issue])
Esempio n. 4
0
class TestSpecDescVisitor(TestCase):
    def setUp(self):
        self.visitor = SpecDescVisitor()

    def assert_specdesc(self, html, items, issues):
        parsed = kumascript_grammar.parse(html)
        self.visitor.visit(parsed)
        actual = [item.to_html() for item in self.visitor.desc_items]
        self.assertEqual(items, actual)
        self.assertEqual(self.visitor.issues, issues)

    def test_empty(self):
        self.assert_specdesc('<td></td>', [''], [])

    def test_plain_text(self):
        self.assert_specdesc('<td> Plain text </td>', ['Plain text'], [])

    def test_html(self):
        html = '<td>Defines <code>right</code> as animatable.</td>'
        expected = ['Defines', '<code>right</code>', 'as animatable.']
        self.assert_specdesc(html, expected, [])

    def test_styled(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/inherit
        html = """<td style=\"vertical-align: top;\">
            Initial definition.
        </td>"""
        expected = ['Initial definition.']
        issue = ('unexpected_attribute', 4, 32, {
            'expected': 'no attributes',
            'node_type': 'td',
            'ident': 'style',
            'value': 'vertical-align: top;'
        })
        self.assert_specdesc(html, expected, [issue])

    def test_kumascript(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align
        html = ('<td>Add the {{ xref_csslength() }} value and allows it to be'
                ' applied to element with a {{ cssxref("display") }} type of'
                ' <code>table-cell</code>.</td>')
        expected = [
            'Add the',
            ('<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/'
             'length"><code>&lt;length&gt;</code></a>'),
            'value and allows it to be applied to element with a',
            ('<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/'
             'display"><code>display</code></a>'), 'type of',
            '<code>table-cell</code>', '.'
        ]
        self.assert_specdesc(html, expected, [])

    def test_kumascript_spec2(self):
        # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/data
        html = "<td>No change from {{Spec2('HTML5 W3C')}}</td>"
        expected = ['No change from', 'specification HTML5 W3C']
        issues = [('unexpected_kumascript', 19, 41, {
            'name': 'Spec2',
            'args': ['HTML5 W3C'],
            'scope': 'specification description',
            'kumascript': '{{Spec2("HTML5 W3C")}}',
            'expected_scopes': 'specification maturity'
        }), ('unknown_spec', 19, 41, {
            'key': 'HTML5 W3C'
        })]
        self.assert_specdesc(html, expected, issues)

    def test_kumascript_experimental_inline(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/position_value
        html = (
            '<td>Defines <code>&lt;position&gt;</code> explicitly and extends'
            ' it to support offsets from any edge. {{ experimental_inline() }}'
            '</td>')
        expected = [
            'Defines', '<code>&lt;position&gt;</code>',
            'explicitly and extends it to support offsets from any edge.', ''
        ]
        kname = 'experimental_inline'
        issue = ('unexpected_kumascript', 102, 129, {
            'args': [],
            'kumascript': '{{%s}}' % kname,
            'name': kname,
            'scope': 'specification description',
            'expected_scopes': 'compatibility feature'
        })
        self.assert_specdesc(html, expected, [issue])