コード例 #1
0
 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')
コード例 #2
0
 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), '{}')
コード例 #3
0
 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}')
コード例 #4
0
 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}}')