From d549b05fcb28a2e7b927c168b4dbb49bfffef066 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 20 Mar 2018 16:08:50 +0000 Subject: [PATCH] add basic test routine for Pin class --- src/interface_decl.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/interface_decl.py b/src/interface_decl.py index 3297f7c..c66098e 100644 --- a/src/interface_decl.py +++ b/src/interface_decl.py @@ -91,8 +91,34 @@ class Pin(object): if self.action: res += " Action " res += self.name - if inout: + if self.inout: res += ' (Bit#(1) in)' res += ";" return res + +# basic test +if __name__ == '__main__': + + def _pinmunge(p, sep, repl, dedupe=True): + """ munges the text so it's easier to compare. + splits by separator, strips out blanks, re-joins. + """ + p = p.strip() + p = p.split(sep) + if dedupe: + p = filter(lambda x: x, p) # filter out blanks + return repl.join(p) + + def pinmunge(p): + """ munges the text so it's easier to compare. + """ + p = _pinmunge(p, "(", " ( ", False) + p = _pinmunge(p, ")", " ) ", False) + p = _pinmunge(p, " ", " ") + return p + + pwm = Pin("pwm{0}", True, True, True, True) + print pinmunge(str(pwm)) + print pinmunge(pwminterface_decl) + assert pinmunge(str(pwm)) == pinmunge(pwminterface_decl) -- 2.30.2