summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler/cpp_util_test.py
blob: eef4c554b5333d1ecdd976014af347c7973c38d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# 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, GenerateIfndefName, OpenNamespace)

class CppUtilTest(unittest.TestCase):
  def testClassname(self):
    self.assertEquals('Permissions', Classname('permissions'))
    self.assertEquals('UpdateAllTheThings',
        Classname('updateAllTheThings'))
    self.assertEquals('Aa_Bb_Cc', Classname('aa.bb.cc'))

  def testNamespaceDeclaration(self):
    self.assertEquals('namespace foo {',
                      OpenNamespace('foo').Render())
    self.assertEquals('}  // namespace foo',
                      CloseNamespace('foo').Render())

    self.assertEquals(
        'namespace extensions {\n'
        'namespace foo {',
        OpenNamespace('extensions::foo').Render())
    self.assertEquals(
        '}  // namespace foo\n'
        '}  // namespace extensions',
        CloseNamespace('extensions::foo').Render())

    self.assertEquals(
        'namespace extensions {\n'
        'namespace gen {\n'
        'namespace api {',
        OpenNamespace('extensions::gen::api').Render())
    self.assertEquals(
        '}  // namespace api\n'
        '}  // namespace gen\n'
        '}  // namespace extensions',
        CloseNamespace('extensions::gen::api').Render())

    self.assertEquals(
        'namespace extensions {\n'
        'namespace gen {\n'
        'namespace api {\n'
        'namespace foo {',
        OpenNamespace('extensions::gen::api::foo').Render())
    self.assertEquals(
        '}  // namespace foo\n'
        '}  // namespace api\n'
        '}  // namespace gen\n'
        '}  // namespace extensions',
        CloseNamespace('extensions::gen::api::foo').Render())

  def testGenerateIfndefName(self):
    self.assertEquals('FOO_BAR_BAZ_H__', GenerateIfndefName('foo\\bar\\baz.h'))
    self.assertEquals('FOO_BAR_BAZ_H__', GenerateIfndefName('foo/bar/baz.h'))


if __name__ == '__main__':
  unittest.main()