示例#1
0
文件: testLet.py 项目: andrewf/fern
class TestLetKVPairs(unittest.TestCase):
    def testKVPairs(self):
        self.let = Let()
        self.let.names['var'] = 3
        x = Map()
        x['bar'] = NameRef('var')
        self.let.put(KVPair('a', x))
        x = List()
        x.put(NameRef('var'))
        self.let.put(KVPair('b', x))
        root = Map()
        root.put(self.let)
        self.assertEqual(root.eval(), {'a':{'bar':3}, 'b':[3]})
示例#2
0
文件: builder.py 项目: andrewf/fern
class LetBuilder(Builder):
    def __init__(self):
        self.expecting = 'names'
        self.let = Let()
    def put(self, item):
        if self.expecting == 'names':
            self.let.names.put(item)
        else:
            self.let.put(item)
    def start_content(self):
        self.expecting = 'content'
    def get(self):
        return self.let
示例#3
0
文件: testLet.py 项目: andrewf/fern
class TestLetItem(unittest.TestCase):
    def setUp(self):
        self.m = Map()
        self.m['ref'] = NameRef('var')
        self.let = Let()
        self.let.put(self.m)
        self.let.names['var'] = 42
    def testMap(self):
        self.let.names['var'] = 42
        self.assertEqual(self.let.eval(), {'ref': 42})
    def testStream(self):
        self.let.names['var'] = True
        self.let.put(NameRef('var'))
        l = List()
        l.put(42)
        l.put(self.let)
        l.put('arg')
        self.assertEqual(l.eval(), [42, {'ref': True}, True, 'arg'])
示例#4
0
文件: testLet.py 项目: andrewf/fern
 def setUp(self):
     self.m = Map()
     self.m['ref'] = NameRef('var')
     self.let = Let()
     self.let.put(self.m)
     self.let.names['var'] = 42
示例#5
0
文件: builder.py 项目: andrewf/fern
 def __init__(self):
     self.expecting = 'names'
     self.let = Let()