def testPatternStr(self): """str -> _1""" index = {'str': '_1', 'ztype': '_2'} ast_type = ast_pb2.Type() text_format.Parse(""" lang_type: "str" """, ast_type) self.assertEqual(postconv.Initializer(ast_type, index), '_1')
def testPatternInt(self): """int -> {}""" index = {'str': 1, 'ztype': 2} ast_type = ast_pb2.Type() text_format.Parse(""" lang_type: "int" """, ast_type) self.assertEqual(postconv.Initializer(ast_type, index), '{}')
def testPatternListStr(self): """list<str> -> {_1}""" index = {'str': '_1', 'ztype': '_2'} ast_type = ast_pb2.Type() text_format.Parse(""" lang_type: "list<str>" params { lang_type: "str" } """, ast_type) self.assertEqual(postconv.Initializer(ast_type, index), '{_1}')
def testPatternNested(self): """dict<int, tuple<str, ztype>> -> {_0,{_1,_2}}""" index = {'str': '_1', 'ztype': '_2'} ast_type = ast_pb2.Type() text_format.Parse(""" lang_type: "dict<int, tuple<str, ztype>>" params { lang_type: "int" } params { lang_type: "tuple<str, ztype>" params { lang_type: "str" } params { lang_type: "ztype" } } """, ast_type) self.assertEqual(postconv.Initializer(ast_type, index), '{_0,{_1,_2}}')