def test_dtab_read_ignores_comment_line(self): withComments = Dtab.read(""" # a comment /#foo => /biz # another comment | ( /bliz & # yet another comment /bluth ) # duh bluths ; #finalmente #/ignore=>/me; """) dtab = Dtab([ Dentry( Path.Utf8("#foo"), NameTree.Alt( NameTree.Leaf(Path.Utf8("biz")), NameTree.Union( NameTree.Weighted( NameTree.Weighted.defaultWeight, NameTree.Leaf(Path.Utf8("bliz")), ), NameTree.Weighted( NameTree.Weighted.defaultWeight, NameTree.Leaf(Path.Utf8("bluth")), ), ), ), ) ]) s = "Dtab(Label(#foo)=>NameTree.Leaf(Path(/biz))," s += "NameTree.Union(NameTree.Weighted(1.0,NameTree.Leaf(Path(/bliz)))," s += "NameTree.Weighted(1.0,NameTree.Leaf(Path(/bluth)))))" self.assertEqual(repr(dtab), s) self.assertEqual(withComments, dtab)
def test_parseDtab(self): self.assertTrue(NameTreeParsers.parseDtab("") == Dtab.empty) self.assertTrue( NameTreeParsers.parseDtab(" /=>! ") == Dtab([Dentry(Path.empty, NameTree.Fail)]) ) self.assertTrue( NameTreeParsers.parseDtab("/=>!;") == Dtab([Dentry(Path.empty, NameTree.Fail)]) ) self.assertTrue( NameTreeParsers.parseDtab("/=>!;/foo=>/bar") == Dtab( [ Dentry(Path.empty, NameTree.Fail), Dentry(Path.Utf8("foo"), NameTree.Leaf(Path.Utf8("bar"))), ] ) )
def test_is_collection(self): # these are mostly just compilation tests. dtab = Dtab.empty dtab += Dentry.read("/a => /b") dtab += Dentry.read("/c => /d") dtab1 = Dtab( map( lambda d: Dentry.read("/{}=>{}".format( "/".join(map(lambda x: x.buf, d.prefix.elems)), d.nametree.value.show, )), dtab, )) self.assertTrue(dtab1.length, 2)