def testEnumValueAssignmentSetReferences(self): definition = EnumDefinition(original_enum_name='c', enum_package='p') definition.AppendEntry('A', None) definition.AppendEntry('B', 'A') definition.AppendEntry('C', 'B') definition.AppendEntry('D', None) definition.Finalize() self.assertEqual(collections.OrderedDict([('A', 0), ('B', 0), ('C', 0), ('D', 1)]), definition.entries)
def testImplicitPrefixStripping(self): definition = EnumDefinition(original_enum_name='ClassName', enum_package='p') definition.AppendEntry('CLASS_NAME_A', None) definition.AppendEntry('CLASS_NAME_B', None) definition.AppendEntry('CLASS_NAME_C', None) definition.AppendEntry('CLASS_NAME_LAST', 'CLASS_NAME_C') definition.Finalize() self.assertEqual(collections.OrderedDict([('A', 0), ('B', 1), ('C', 2), ('LAST', 2)]), definition.entries)
def testExplicitPrefixStripping(self): definition = EnumDefinition(original_enum_name='c', enum_package='p') definition.AppendEntry('P_A', None) definition.AppendEntry('B', None) definition.AppendEntry('P_C', None) definition.AppendEntry('P_LAST', 'P_C') definition.prefix_to_strip = 'P_' definition.Finalize() self.assertEqual(collections.OrderedDict([('A', 0), ('B', 1), ('C', 2), ('LAST', 2)]), definition.entries)
def testOutput(self): definition = EnumDefinition(original_enum_name='ClassName', enum_package='some.package', entries=[('E1', 1), ('E2', '2 << 2')], comments=[('E2', 'This is a comment.'), ('E1', 'This is a multiple line ' 'comment that is really long. ' 'This is a multiple line ' 'comment that is really ' 'really long.')]) output = GenerateOutput('path/to/file', definition) expected = """ // Copyright %d 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. // This file is autogenerated by // %s // From // path/to/file package some.package; import android.support.annotation.IntDef; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; public class ClassName { @IntDef({ E1, E2 }) @Retention(RetentionPolicy.SOURCE) public @interface ClassNameEnum {} /** * %s * really really long. */ public static final int E1 = 1; /** * This is a comment. */ public static final int E2 = 2 << 2; } """ long_comment = ('This is a multiple line comment that is really long. ' 'This is a multiple line comment that is') self.assertEqual( expected % (date.today().year, GetScriptName(), long_comment), output)
def testOutput(self): definition = EnumDefinition(original_enum_name='ClassName', enum_package='some.package', entries=[('E1', 1), ('E2', '2 << 2')]) output = GenerateOutput('path/to/file', definition) expected = """ // Copyright 2014 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. // This file is autogenerated by // %s // From // path/to/file package some.package; public class ClassName { public static final int E1 = 1; public static final int E2 = 2 << 2; } """ self.assertEqual(expected % GetScriptName(), output)