Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Unified Diff: tools/json_to_struct/element_generator_test.py

Issue 1209733002: Add the ability to code generated prepopulated static nested structs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/json_to_struct/element_generator_test.py
diff --git a/tools/json_to_struct/element_generator_test.py b/tools/json_to_struct/element_generator_test.py
index 67459a1d8713f142ebbc8850d2978ed279e09bae..c9a5da71695faccbdb5f81a660e6fb4f80283cef 100755
--- a/tools/json_to_struct/element_generator_test.py
+++ b/tools/json_to_struct/element_generator_test.py
@@ -85,14 +85,38 @@ class ElementGeneratorTest(unittest.TestCase):
{'field': 'f2', 'type': 'enum', 'ctype': 'QuasiBool', 'default': 'MAYBE',
'optional': True},
{'field': 'f3', 'type': 'array', 'contents': {'type': 'string16'},
- 'optional': True}
+ 'optional': True},
+ {
+ 'field': 'f4',
+ 'type': 'object',
+ 'type_name': 'InnerType',
+ 'fields': [
+ {'field': 'g0', 'type': 'string'}
+ ],
+ 'optional': True
+ },
+ {
+ 'field': 'f5',
+ 'type': 'array',
+ 'contents': {
+ 'type': 'object',
+ 'type_name': 'InnerType',
+ 'fields': [
+ {'field': 'a0', 'type': 'string'},
+ {'field': 'a1', 'type': 'string'}
+ ]
+ },
+ 'optional': True
+ }
]
description = {
'int_variables': {'a': -5, 'b': 5},
'elements': {
'elem0': {'f0': 5, 'f1': 'foo', 'f2': 'SURE'},
'elem1': {'f2': 'NOWAY', 'f0': -2, 'f1': 'bar'},
- 'elem2': {'f1': 'foo_bar', 'f3': [u'bar', u'foo']}
+ 'elem2': {'f1': 'foo_bar', 'f3': [u'bar', u'foo']},
+ 'elem3': {'f1': 'foo', 'f4': {'g0': 'test'}},
+ 'elem4': {'f1': 'foo', 'f5': [{'a0': 'test0', 'a1': 'test1'}]},
}
}
@@ -103,30 +127,67 @@ class ElementGeneratorTest(unittest.TestCase):
'b': 'const int b = 5;\n',
}
elements_expected = {
- 'elem0': 'const MyType elem0 = {\n' +
- ' 5,\n' +
- ' "foo",\n' +
- ' SURE,\n' +
- ' NULL,\n' +
+ 'elem0': 'const MyType elem0 = {\n'
+ ' 5,\n'
+ ' "foo",\n'
+ ' SURE,\n'
+ ' NULL,\n'
+ ' 0,\n'
+ ' {0},\n'
+ ' NULL,\n'
' 0,\n'
'};\n',
- 'elem1': 'const MyType elem1 = {\n' +
- ' -2,\n' +
- ' "bar",\n' +
- ' NOWAY,\n' +
- ' NULL,\n' +
+ 'elem1': 'const MyType elem1 = {\n'
+ ' -2,\n'
+ ' "bar",\n'
+ ' NOWAY,\n'
+ ' NULL,\n'
+ ' 0,\n'
+ ' {0},\n'
+ ' NULL,\n'
' 0,\n'
'};\n',
- 'elem2': 'const wchar_t* const array_elem2_f3[] = {\n' +
- ' L"bar",\n' +
- ' L"foo",\n' +
- '};\n' +
- 'const MyType elem2 = {\n' +
- ' 1000,\n' +
- ' "foo_bar",\n' +
- ' MAYBE,\n' +
- ' array_elem2_f3,\n' +
+ 'elem2': 'const wchar_t* const array_elem2_f3[] = {\n'
+ ' L"bar",\n'
+ ' L"foo",\n'
+ '};\n'
+ 'const MyType elem2 = {\n'
+ ' 1000,\n'
+ ' "foo_bar",\n'
+ ' MAYBE,\n'
+ ' array_elem2_f3,\n'
' 2,\n'
+ ' {0},\n'
+ ' NULL,\n'
+ ' 0,\n'
+ '};\n',
+ 'elem3': 'const MyType elem3 = {\n'
+ ' 1000,\n'
+ ' "foo",\n'
+ ' MAYBE,\n'
+ ' NULL,\n'
+ ' 0,\n'
+ ' {\n'
+ ' "test",\n'
+ ' },\n'
+ ' NULL,\n'
+ ' 0,\n'
+ '};\n',
+ 'elem4': 'const InnerType array_elem4_f5[] = {\n'
+ ' {\n'
+ ' "test0",\n'
+ ' "test1",\n'
+ ' },\n'
+ '};\n'
+ 'const MyType elem4 = {\n'
+ ' 1000,\n'
+ ' "foo",\n'
+ ' MAYBE,\n'
+ ' NULL,\n'
+ ' 0,\n'
+ ' {0},\n'
+ ' array_elem4_f5,\n'
+ ' 1,\n'
'};\n'
}
expected = ''

Powered by Google App Engine
This is Rietveld 408576698