def stdin_read(count): primary_prompt = '\001' + green('\002In [\001') + green('\002{0}\001', style='bold') + green('\002]: \001') + '\002' secondary_prompt = ' ' * len(str(count)) + '\001' + green('\002 ...: \001') + '\002' prompt = primary_prompt.format(count) prefill = '' entry = '' while True: entry += input_with_prefill(prompt, prefill) + '\n' prompt = secondary_prompt parens_count = balance(entry) if parens_count > 0: prefill = ' ' * parens_count else: yield entry
def test_balance_nested_parens(self): self.assertEqual(0, utils.balance('(sfs (sfsfs) (sdf (sfs)))')) self.assertEqual(0, utils.balance('(sfs (sfsfs (sdf (sfs))))')) self.assertEqual(0, utils.balance('(((((sfs) sfsfs) sdf) sfs))'))
def test_balance_unbalanced_parens(self): self.assertEqual(1, utils.balance('(sfs sfsfs sdf sfs')) self.assertEqual(-1, utils.balance('sfs sfsfs sdf sfs)'))
def test_balance_single_parens(self): self.assertEqual(0, utils.balance('()')) self.assertEqual(-1, utils.balance(')(')) self.assertEqual(0, utils.balance(' ( ) ')) self.assertEqual(0, utils.balance('(sfs sfsfs sdf) sfs'))
def test_balance_empty(self): self.assertEqual(0, utils.balance(''))