0
Files
src/tools/json_schema_compiler/cpp_util_test.py
Tim Judkins 1e3d052650 Enable python formatting in //tools/json_schema_compiler/
Python formatting using `git cl format` has been enabled in the codebase
for a while now by including a .style.yapf file in your folder
hierarchy. However back in 2020 an exception was added to ignore the
json schema compiler folder, as the code in there uses a lot of chained
function calls that are split across lines for readability and the
formatter was condensing them into a much less readable state.

This CL resolves this by using the line continuation character `\` for
these chained function lines, allowing us to retain the more readable
indentation and also enable the formatter by default. It also runs a
full format over all the files in the directory, to get them into a
consistent state where we can have the formatter enabled by default
going forward with low impact.

No behavior change is expected.

Bug: 40711753
Change-Id: I6e10dc5af022ce0e3557099a84773aa9cc92d2e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5804254
Commit-Queue: Tim <tjudkins@chromium.org>
Reviewed-by: Devlin Cronin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1345613}
2024-08-22 20:16:07 +00:00

67 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright 2012 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import unittest
from cpp_util import (Classname, CloseNamespace, GetCppNamespace,
GenerateIfndefName, OpenNamespace)
class CppUtilTest(unittest.TestCase):
def testClassname(self):
self.assertEqual('Permissions', Classname('permissions'))
self.assertEqual('UpdateAllTheThings', Classname('updateAllTheThings'))
self.assertEqual('Aa_Bb_Cc', Classname('aa.bb.cc'))
def testNamespaceDeclaration(self):
self.assertEqual('namespace foo {', OpenNamespace('foo').Render())
self.assertEqual('} // namespace foo', CloseNamespace('foo').Render())
self.assertEqual('namespace extensions {\n'
'namespace foo {',
OpenNamespace('extensions::foo').Render())
self.assertEqual('} // namespace foo\n'
'} // namespace extensions',
CloseNamespace('extensions::foo').Render())
self.assertEqual(
'namespace extensions {\n'
'namespace gen {\n'
'namespace api {',
OpenNamespace('extensions::gen::api').Render())
self.assertEqual(
'} // namespace api\n'
'} // namespace gen\n'
'} // namespace extensions',
CloseNamespace('extensions::gen::api').Render())
self.assertEqual(
'namespace extensions {\n'
'namespace gen {\n'
'namespace api {\n'
'namespace foo {',
OpenNamespace('extensions::gen::api::foo').Render())
self.assertEqual(
'} // namespace foo\n'
'} // namespace api\n'
'} // namespace gen\n'
'} // namespace extensions',
CloseNamespace('extensions::gen::api::foo').Render())
def testGenerateIfndefName(self):
self.assertEqual('FOO_BAR_BAZ_H__', GenerateIfndefName('foo\\bar\\baz.h'))
self.assertEqual('FOO_BAR_BAZ_H__', GenerateIfndefName('foo/bar/baz.h'))
def testGetCppNamespace(self):
namespace_pattern = "test::api::%(namespace)s"
unix_name = "SimpleApi"
self.assertEqual("test::api::SimpleApi",
GetCppNamespace(namespace_pattern, unix_name))
if __name__ == '__main__':
unittest.main()