def setUp(self):
     self.parent_feature = self.get_instance(
         'Feature', 'web-css-background-size')
     self.visitor = CompatFeatureVisitor(parent_feature=self.parent_feature)
Beispiel #2
0
 def setUp(self):
     self.parent_feature = self.get_instance('Feature',
                                             'web-css-background-size')
     self.visitor = CompatFeatureVisitor(parent_feature=self.parent_feature)
class TestFeatureVisitor(TestCase):
    scope = 'compatibility feature'

    def setUp(self):
        self.parent_feature = self.get_instance(
            'Feature', 'web-css-background-size')
        self.visitor = CompatFeatureVisitor(parent_feature=self.parent_feature)

    def assert_feature(
            self, contents, feature_id, name, slug, canonical=False,
            experimental=False, standardized=True, obsolete=False,
            issues=None):
        row_cell = '<td>%s</td>' % contents
        parsed = compat_feature_grammar['html'].parse(row_cell)
        self.visitor.visit(parsed)
        feature_dict = self.visitor.to_feature_dict()
        self.assertEqual(issues or [], self.visitor.issues)
        self.assertEqual(feature_id, feature_dict['id'])
        self.assertEqual(slug, feature_dict['slug'])
        self.assertEqual(name, feature_dict['name'])
        if canonical:
            self.assertTrue(feature_dict['canonical'])
        else:
            self.assertFalse('canonical' in feature_dict)
        if experimental:
            self.assertTrue(feature_dict['experimental'])
        else:
            self.assertFalse('experimental' in feature_dict)
        if obsolete:
            self.assertTrue(feature_dict['obsolete'])
        else:
            self.assertFalse('obsolete' in feature_dict)
        if standardized:
            self.assertFalse('standardized' in feature_dict)
        else:
            self.assertFalse(feature_dict['standardized'])

    def test_remove_whitespace(self):
        cell = (
            ' Support for<br>\n     <code>contain</code> and'
            ' <code>cover</code> ')
        feature_id = '_support for contain and cover'
        name = 'Support for <code>contain</code> and <code>cover</code>'
        slug = 'web-css-background-size_support_for_contain_and_co'
        self.assert_feature(cell, feature_id, name, slug)

    def test_code_sequence(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/display
        cell = (
            '<code>none</code>, <code>inline</code> and'
            ' <code>block</code>')
        feature_id = '_none, inline and block'
        name = '<code>none</code>, <code>inline</code> and <code>block</code>'
        slug = 'web-css-background-size_none_inline_and_block'
        self.assert_feature(cell, feature_id, name, slug)

    def test_canonical(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/display
        cell = '<code>list-item</code>'
        feature_id = '_list-item'
        name = 'list-item'
        slug = 'web-css-background-size_list-item'
        self.assert_feature(cell, feature_id, name, slug, canonical=True)

    def test_canonical_match(self):
        name = 'list-item'
        slug = 'slug-list-item'
        feature = self.create(
            Feature, parent=self.parent_feature, name={'zxx': name}, slug=slug)
        cell = '<code>list-item</code>'
        self.assert_feature(cell, feature.id, name, slug, canonical=True)

    def test_ks_experimental(self):
        cell = '<code>grid</code> {{experimental_inline}}'
        feature_id = '_grid'
        name = 'grid'
        slug = 'web-css-background-size_grid'
        self.assert_feature(
            cell, feature_id, name, slug, canonical=True, experimental=True)

    def test_ks_non_standard_inline(self):
        # https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent
        cell = '<code>initAnimationEvent()</code> {{non-standard_inline}}'
        feature_id = '_initanimationevent()'
        name = 'initAnimationEvent()'
        slug = 'web-css-background-size_initanimationevent'
        self.assert_feature(
            cell, feature_id, name, slug, canonical=True, standardized=False)

    def test_ks_deprecated_inline(self):
        cell = '<code>initAnimationEvent()</code> {{deprecated_inline}}'
        feature_id = '_initanimationevent()'
        name = 'initAnimationEvent()'
        slug = 'web-css-background-size_initanimationevent'
        self.assert_feature(
            cell, feature_id, name, slug, canonical=True, obsolete=True)

    def test_ks_obsolete_inline(self):
        # https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API
        cell = 'Version -76 support {{obsolete_inline}}'
        feature_id = '_version -76 support'
        name = 'Version -76 support'
        slug = 'web-css-background-size_version_-76_support'
        self.assert_feature(cell, feature_id, name, slug, obsolete=True)

    def test_ks_htmlelement(self):
        cell = '{{ HTMLElement("progress") }}'
        feature_id = '_progress'
        name = '&lt;progress&gt;'
        slug = 'web-css-background-size_progress'
        self.assert_feature(cell, feature_id, name, slug, canonical=True)

    def test_ks_domxref(self):
        cell = '{{domxref("DeviceProximityEvent")}}'
        feature_id = '_deviceproximityevent'
        name = 'DeviceProximityEvent'
        slug = 'web-css-background-size_deviceproximityevent'
        self.assert_feature(cell, feature_id, name, slug, canonical=True)

    def test_unknown_kumascript(self):
        cell = 'feature foo {{bar}}'
        feature_id = '_feature foo'
        name = 'feature foo'
        slug = 'web-css-background-size_feature_foo'
        issue = ('unknown_kumascript', 16, 23,
                 {'name': 'bar', 'args': [], 'kumascript': '{{bar}}',
                  'scope': self.scope})
        self.assert_feature(cell, feature_id, name, slug, issues=[issue])

    def test_nonascii_name(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant
        cell = '<code>ß</code> → <code>SS</code>'
        feature_id = '_\xdf \u2192 ss'
        name = '<code>\xdf</code> \u2192 <code>SS</code>'
        slug = 'web-css-background-size_ss'
        self.assert_feature(cell, feature_id, name, slug)

    def test_footnote(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/text-align
        cell = 'Block alignment values [1] {{not_standard_inline}}'
        feature_id = '_block alignment values'
        name = 'Block alignment values'
        slug = 'web-css-background-size_block_alignment_values'
        issue = ('footnote_feature', 27, 31, {})
        self.assert_feature(
            cell, feature_id, name, slug, standardized=False, issues=[issue])

    def test_bracket(self):
        # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
        cell = 'accept=[file extension]'
        feature_id = '_accept=[file extension]'
        name = 'accept=[file extension]'
        slug = 'web-css-background-size_accept_file_extension'
        self.assert_feature(cell, feature_id, name, slug)

    def test_digit(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/transform
        cell = '3D Support'
        feature_id = '_3d support'
        name = '3D Support'
        slug = 'web-css-background-size_3d_support'
        self.assert_feature(cell, feature_id, name, slug)

    def test_link(self):
        # https://developer.mozilla.org/en-US/docs/Web/API/EventSource
        cell = ('<a href="/En/HTTP_access_control">'
                'Cross-Origin Resource Sharing</a><br>')
        feature_id = '_cross-origin resource sharing'
        name = 'Cross-Origin Resource Sharing'
        slug = 'web-css-background-size_cross-origin_resource_shar'
        issue = (
            'tag_dropped', 4, 38, {'tag': 'a', 'scope': self.scope})
        self.assert_feature(cell, feature_id, name, slug, issues=[issue])

    def test_p(self):
        # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
        cell = '<p>Reassignment fails</p>'
        feature_id = '_reassignment fails'
        name = 'Reassignment fails'
        slug = 'web-css-background-size_reassignment_fails'
        issue = ('tag_dropped', 4, 7, {'tag': 'p', 'scope': self.scope})
        self.assert_feature(cell, feature_id, name, slug, issues=[issue])

    def test_span(self):
        cell = '<span class="strong">Strong</span>'
        feature_id = '_strong'
        name = 'Strong'
        slug = 'web-css-background-size_strong'
        issue = ('tag_dropped', 4, 25, {'tag': 'span', 'scope': self.scope})
        self.assert_feature(cell, feature_id, name, slug, issues=[issue])

    def test_table(self):
        # https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack
        cell = """\
<table class="compat-table">
  <tbody>
    <tr>
      <td><code>.stop()</code></td>
    </tr>
  </tbody>
</table>"""
        feature_id = '_.stop()'
        name = '.stop()'
        slug = 'web-css-background-size_stop'
        issues = [
            ('tag_dropped', 4, 32, {'tag': 'table', 'scope': self.scope}),
            ('tag_dropped', 35, 42, {'tag': 'tbody', 'scope': self.scope}),
            ('tag_dropped', 47, 51, {'tag': 'tr', 'scope': self.scope}),
            ('tag_dropped', 58, 62, {'tag': 'td', 'scope': self.scope})]
        self.assert_feature(
            cell, feature_id, name, slug, canonical=True, issues=issues)
Beispiel #4
0
class TestFeatureVisitor(TestCase):
    scope = 'compatibility feature'

    def setUp(self):
        self.parent_feature = self.get_instance('Feature',
                                                'web-css-background-size')
        self.visitor = CompatFeatureVisitor(parent_feature=self.parent_feature)

    def assert_feature(self,
                       contents,
                       feature_id,
                       name,
                       slug,
                       canonical=False,
                       experimental=False,
                       standardized=True,
                       obsolete=False,
                       issues=None):
        row_cell = '<td>%s</td>' % contents
        parsed = compat_feature_grammar['html'].parse(row_cell)
        self.visitor.visit(parsed)
        feature_dict = self.visitor.to_feature_dict()
        self.assertEqual(issues or [], self.visitor.issues)
        self.assertEqual(feature_id, feature_dict['id'])
        self.assertEqual(slug, feature_dict['slug'])
        self.assertEqual(name, feature_dict['name'])
        if canonical:
            self.assertTrue(feature_dict['canonical'])
        else:
            self.assertFalse('canonical' in feature_dict)
        if experimental:
            self.assertTrue(feature_dict['experimental'])
        else:
            self.assertFalse('experimental' in feature_dict)
        if obsolete:
            self.assertTrue(feature_dict['obsolete'])
        else:
            self.assertFalse('obsolete' in feature_dict)
        if standardized:
            self.assertFalse('standardized' in feature_dict)
        else:
            self.assertFalse(feature_dict['standardized'])

    def test_remove_whitespace(self):
        cell = (' Support for<br>\n     <code>contain</code> and'
                ' <code>cover</code> ')
        feature_id = '_support for contain and cover'
        name = 'Support for <code>contain</code> and <code>cover</code>'
        slug = 'web-css-background-size_support_for_contain_and_co'
        self.assert_feature(cell, feature_id, name, slug)

    def test_code_sequence(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/display
        cell = ('<code>none</code>, <code>inline</code> and'
                ' <code>block</code>')
        feature_id = '_none, inline and block'
        name = '<code>none</code>, <code>inline</code> and <code>block</code>'
        slug = 'web-css-background-size_none_inline_and_block'
        self.assert_feature(cell, feature_id, name, slug)

    def test_canonical(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/display
        cell = '<code>list-item</code>'
        feature_id = '_list-item'
        name = 'list-item'
        slug = 'web-css-background-size_list-item'
        self.assert_feature(cell, feature_id, name, slug, canonical=True)

    def test_canonical_match(self):
        name = 'list-item'
        slug = 'slug-list-item'
        feature = self.create(Feature,
                              parent=self.parent_feature,
                              name={'zxx': name},
                              slug=slug)
        cell = '<code>list-item</code>'
        self.assert_feature(cell, feature.id, name, slug, canonical=True)

    def test_ks_experimental(self):
        cell = '<code>grid</code> {{experimental_inline}}'
        feature_id = '_grid'
        name = 'grid'
        slug = 'web-css-background-size_grid'
        self.assert_feature(cell,
                            feature_id,
                            name,
                            slug,
                            canonical=True,
                            experimental=True)

    def test_ks_non_standard_inline(self):
        # https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent
        cell = '<code>initAnimationEvent()</code> {{non-standard_inline}}'
        feature_id = '_initanimationevent()'
        name = 'initAnimationEvent()'
        slug = 'web-css-background-size_initanimationevent'
        self.assert_feature(cell,
                            feature_id,
                            name,
                            slug,
                            canonical=True,
                            standardized=False)

    def test_ks_deprecated_inline(self):
        cell = '<code>initAnimationEvent()</code> {{deprecated_inline}}'
        feature_id = '_initanimationevent()'
        name = 'initAnimationEvent()'
        slug = 'web-css-background-size_initanimationevent'
        self.assert_feature(cell,
                            feature_id,
                            name,
                            slug,
                            canonical=True,
                            obsolete=True)

    def test_ks_obsolete_inline(self):
        # https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API
        cell = 'Version -76 support {{obsolete_inline}}'
        feature_id = '_version -76 support'
        name = 'Version -76 support'
        slug = 'web-css-background-size_version_-76_support'
        self.assert_feature(cell, feature_id, name, slug, obsolete=True)

    def test_ks_htmlelement(self):
        cell = '{{ HTMLElement("progress") }}'
        feature_id = '_progress'
        name = '&lt;progress&gt;'
        slug = 'web-css-background-size_progress'
        self.assert_feature(cell, feature_id, name, slug, canonical=True)

    def test_ks_domxref(self):
        cell = '{{domxref("DeviceProximityEvent")}}'
        feature_id = '_deviceproximityevent'
        name = 'DeviceProximityEvent'
        slug = 'web-css-background-size_deviceproximityevent'
        self.assert_feature(cell, feature_id, name, slug, canonical=True)

    def test_unknown_kumascript(self):
        cell = 'feature foo {{bar}}'
        feature_id = '_feature foo'
        name = 'feature foo'
        slug = 'web-css-background-size_feature_foo'
        issue = ('unknown_kumascript', 16, 23, {
            'name': 'bar',
            'args': [],
            'kumascript': '{{bar}}',
            'scope': self.scope
        })
        self.assert_feature(cell, feature_id, name, slug, issues=[issue])

    def test_nonascii_name(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant
        cell = '<code>ß</code> → <code>SS</code>'
        feature_id = '_\xdf \u2192 ss'
        name = '<code>\xdf</code> \u2192 <code>SS</code>'
        slug = 'web-css-background-size_ss'
        self.assert_feature(cell, feature_id, name, slug)

    def test_footnote(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/text-align
        cell = 'Block alignment values [1] {{not_standard_inline}}'
        feature_id = '_block alignment values'
        name = 'Block alignment values'
        slug = 'web-css-background-size_block_alignment_values'
        issue = ('footnote_feature', 27, 31, {})
        self.assert_feature(cell,
                            feature_id,
                            name,
                            slug,
                            standardized=False,
                            issues=[issue])

    def test_bracket(self):
        # https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
        cell = 'accept=[file extension]'
        feature_id = '_accept=[file extension]'
        name = 'accept=[file extension]'
        slug = 'web-css-background-size_accept_file_extension'
        self.assert_feature(cell, feature_id, name, slug)

    def test_digit(self):
        # https://developer.mozilla.org/en-US/docs/Web/CSS/transform
        cell = '3D Support'
        feature_id = '_3d support'
        name = '3D Support'
        slug = 'web-css-background-size_3d_support'
        self.assert_feature(cell, feature_id, name, slug)

    def test_link(self):
        # https://developer.mozilla.org/en-US/docs/Web/API/EventSource
        cell = ('<a href="/En/HTTP_access_control">'
                'Cross-Origin Resource Sharing</a><br>')
        feature_id = '_cross-origin resource sharing'
        name = 'Cross-Origin Resource Sharing'
        slug = 'web-css-background-size_cross-origin_resource_shar'
        issue = ('tag_dropped', 4, 38, {'tag': 'a', 'scope': self.scope})
        self.assert_feature(cell, feature_id, name, slug, issues=[issue])

    def test_p(self):
        # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
        cell = '<p>Reassignment fails</p>'
        feature_id = '_reassignment fails'
        name = 'Reassignment fails'
        slug = 'web-css-background-size_reassignment_fails'
        issue = ('tag_dropped', 4, 7, {'tag': 'p', 'scope': self.scope})
        self.assert_feature(cell, feature_id, name, slug, issues=[issue])

    def test_span(self):
        cell = '<span class="strong">Strong</span>'
        feature_id = '_strong'
        name = 'Strong'
        slug = 'web-css-background-size_strong'
        issue = ('tag_dropped', 4, 25, {'tag': 'span', 'scope': self.scope})
        self.assert_feature(cell, feature_id, name, slug, issues=[issue])

    def test_table(self):
        # https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack
        cell = """\
<table class="compat-table">
  <tbody>
    <tr>
      <td><code>.stop()</code></td>
    </tr>
  </tbody>
</table>"""
        feature_id = '_.stop()'
        name = '.stop()'
        slug = 'web-css-background-size_stop'
        issues = [('tag_dropped', 4, 32, {
            'tag': 'table',
            'scope': self.scope
        }), ('tag_dropped', 35, 42, {
            'tag': 'tbody',
            'scope': self.scope
        }), ('tag_dropped', 47, 51, {
            'tag': 'tr',
            'scope': self.scope
        }), ('tag_dropped', 58, 62, {
            'tag': 'td',
            'scope': self.scope
        })]
        self.assert_feature(cell,
                            feature_id,
                            name,
                            slug,
                            canonical=True,
                            issues=issues)