def testGenerateArrayFieldContent(self): lines = ['STRUCT BEGINS'] GenerateFieldContent('test', { 'type': 'array', 'contents': { 'type': 'int' } }, None, lines, ' ', {}) self.assertEquals(['STRUCT BEGINS', ' NULL,', ' 0,'], lines) lines = ['STRUCT BEGINS'] GenerateFieldContent('test', { 'field': 'my_array', 'type': 'array', 'contents': { 'type': 'int' } }, [3, 4], lines, ' ', {}) self.assertEquals( 'const int array_test_my_array[] = {\n' + ' 3,\n' + ' 4,\n' + '};\n' + 'STRUCT BEGINS\n' + ' array_test_my_array,\n' + ' 2,', '\n'.join(lines)) lines = ['STRUCT BEGINS'] GenerateFieldContent('test', { 'field': 'my_array', 'type': 'array', 'contents': { 'type': 'int' } }, [3, 4], lines, ' ', {'array_test_my_array': 1}) self.assertEquals( 'const int array_test_my_array_1[] = {\n' + ' 3,\n' + ' 4,\n' + '};\n' + 'STRUCT BEGINS\n' + ' array_test_my_array_1,\n' + ' 2,', '\n'.join(lines))
def testGenerateIntFieldContent(self): lines = [] GenerateFieldContent({'type': 'int', 'default': 5}, None, lines) self.assertEquals([' 5,'], lines) lines = [] GenerateFieldContent({'type': 'int', 'default': 5}, 12, lines) self.assertEquals([' 12,'], lines) lines = [] GenerateFieldContent({'type': 'int'}, -3, lines) self.assertEquals([' -3,'], lines)
def testGenerateEnumFieldContent(self): lines = []; GenerateFieldContent('', {'type': 'enum', 'default': 'RED'}, None, lines, ' ', {}) self.assertEquals([' RED,'], lines) lines = []; GenerateFieldContent('', {'type': 'enum', 'default': 'RED'}, 'BLACK', lines, ' ', {}) self.assertEquals([' BLACK,'], lines) lines = []; GenerateFieldContent('', {'type': 'enum'}, 'BLUE', lines, ' ', {}) self.assertEquals([' BLUE,'], lines)
def testGenerateStringFieldContent(self): lines = []; GenerateFieldContent('', {'type': 'string', 'default': 'foo_bar'}, None, lines, ' ', {}) self.assertEquals([' "foo_bar",'], lines) lines = []; GenerateFieldContent('', {'type': 'string', 'default': 'foo'}, 'bar\n', lines, ' ', {}) self.assertEquals([' "bar\\n",'], lines) lines = []; GenerateFieldContent('', {'type': 'string'}, None, lines, ' ', {}) self.assertEquals([' NULL,'], lines) lines = []; GenerateFieldContent('', {'type': 'string'}, 'foo', lines, ' ', {}) self.assertEquals([' "foo",'], lines)
def testGenerateClassFieldContent(self): lines = [] GenerateFieldContent('', { 'type': 'class', 'default': 'absl::nullopt' }, None, lines, ' ', {}) self.assertEquals([' absl::nullopt,'], lines) lines = [] GenerateFieldContent('', { 'type': 'class', 'default': 'absl::nullopt' }, 'true', lines, ' ', {}) self.assertEquals([' true,'], lines) lines = [] GenerateFieldContent('', {'type': 'class'}, 'false', lines, ' ', {}) self.assertEquals([' false,'], lines)
def testGenerateString16FieldContent(self): lines = []; GenerateFieldContent('', {'type': 'string16', 'default': u'f\u00d8\u00d81a'}, None, lines, ' ', {}) self.assertEquals([' L"f\\x00d8" L"\\x00d8" L"1a",'], lines) lines = []; GenerateFieldContent('', {'type': 'string16', 'default': 'foo'}, u'b\uc3a5r', lines, ' ', {}) self.assertEquals([' L"b\\xc3a5" L"r",'], lines) lines = []; GenerateFieldContent('', {'type': 'string16'}, None, lines, ' ', {}) self.assertEquals([' NULL,'], lines) lines = []; GenerateFieldContent('', {'type': 'string16'}, u'foo\\u1234', lines, ' ', {}) self.assertEquals([' L"foo\\\\u1234",'], lines)