51 lines
2.0 KiB
Python
51 lines
2.0 KiB
Python
"""Regression checks for the reference coverage guard."""
|
|
|
|
import unittest
|
|
|
|
from check_reference import REFERENCE, check, operation_names
|
|
|
|
|
|
class ReferenceCheckTest(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.document = REFERENCE.read_text()
|
|
|
|
def test_current_reference(self):
|
|
self.assertEqual(check(self.document), [])
|
|
|
|
def test_missing_operation(self):
|
|
document = self.document.replace('<article id="spat.graph_compute">', '<section>')
|
|
self.assertIn("Missing operation: spat.graph_compute", check(document))
|
|
|
|
def test_duplicate_id(self):
|
|
document = self.document + '<div id="spat.graph_compute"></div>'
|
|
self.assertIn("Duplicate HTML id: spat.graph_compute", check(document))
|
|
|
|
def test_empty_semantics(self):
|
|
prefix, marker, article = self.document.partition('<article id="spat.graph_compute">')
|
|
document = prefix + marker + article.replace('data-field="semantics"', 'data-unused="semantics"', 1)
|
|
self.assertIn("spat.graph_compute: missing/empty semantics", check(document))
|
|
|
|
def test_broken_links(self):
|
|
errors = check(self.document + '<a href="#missing">bad</a><a href="missing.cpp">bad</a>')
|
|
self.assertIn("Broken fragment: #missing", errors)
|
|
self.assertIn("Broken local link: missing.cpp", errors)
|
|
|
|
def test_stale_operation(self):
|
|
document = self.document.replace('id="spat.graph_compute"', 'id="spat.removed"')
|
|
self.assertIn("Unknown/stale operation: spat.removed", check(document))
|
|
|
|
def test_inherited_operation_definitions(self):
|
|
source = '''
|
|
class Plan<string mnemonic> : SpatOp<mnemonic>;
|
|
class Compute<string mnemonic> : Plan<mnemonic>;
|
|
def Example : Compute<"example">;
|
|
def LayoutAttr : EnumAttr<SpatialDialect, Layout, "layout">;
|
|
// def Removed : SpatOp<"removed">;
|
|
'''
|
|
self.assertEqual(operation_names([source]), {"spat.example"})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|