class FCallBuilder(Builder): def __init__(self): self.expecting = 'func' self.func = None self.args = ItemStream() def put(self, item): if self.expecting == 'func': self.func = item self.expecting = 'params' else: self.args.put(item) def get(self): return FunctionCall(self.func, self.args)
def setUp(self): self.stream = ItemStream([ KVPair(42, 'foo'), KVPair('foo', 17), KVPair('umm', List()), ]) self.m = Map()
class ItemStreamCompatibility(unittest.TestCase): def setUp(self): self.stream = ItemStream([ KVPair(42, 'foo'), KVPair('foo', 17), KVPair('umm', List()), ]) self.m = Map() def testPut(self): self.m.put(self.stream) self.assertEqual(self.m[42], 'foo') self.assertEqual(self.m['foo'], 17) self.assertEqual(self.m['umm'], []) def testBadPut(self): self.stream.append(14) # non kvpair is an error self.assertRaises(fern.errors.TypeError, self.m.put, self.stream) def testReparentInStream(self): self.m['var'] = 17 self.stream.put(KVPair('ref', NameRef('var'))) self.m.put(self.stream) self.assertEqual(self.m['ref'], 17)
def __init__(self): self.expecting = 'func' self.func = None self.args = ItemStream()