1+ using System . Reflection ;
2+
13using NUnit . Framework ;
24
35using Python . Runtime ;
@@ -7,6 +9,8 @@ namespace Python.EmbeddingTest
79 [ TestFixture ]
810 public class TestUtil
911 {
12+ private static BindingFlags _bindingFlags = BindingFlags . Static | BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ;
13+
1014 [ TestCase ( "TestCamelCaseString" , "test_camel_case_string" ) ]
1115 [ TestCase ( "testCamelCaseString" , "test_camel_case_string" ) ]
1216 [ TestCase ( "TestCamelCaseString123 " , "test_camel_case_string123" ) ]
@@ -19,5 +23,91 @@ public void ConvertsNameToSnakeCase(string name, string expected)
1923 {
2024 Assert . AreEqual ( expected , name . ToSnakeCase ( ) ) ;
2125 }
26+
27+ [ TestCase ( "TestNonConstField1" , "test_non_const_field1" ) ]
28+ [ TestCase ( "TestNonConstField2" , "test_non_const_field2" ) ]
29+ [ TestCase ( "TestNonConstField3" , "test_non_const_field3" ) ]
30+ [ TestCase ( "TestNonConstField4" , "test_non_const_field4" ) ]
31+ public void ConvertsNonConstantFieldsToSnakeCase ( string fieldName , string expected )
32+ {
33+ var fi = typeof ( TestClass ) . GetField ( fieldName , _bindingFlags ) ;
34+ Assert . AreEqual ( expected , fi . ToSnakeCase ( ) ) ;
35+ }
36+
37+ [ TestCase ( "TestConstField1" , "TEST_CONST_FIELD1" ) ]
38+ [ TestCase ( "TestConstField2" , "TEST_CONST_FIELD2" ) ]
39+ [ TestCase ( "TestConstField3" , "TEST_CONST_FIELD3" ) ]
40+ [ TestCase ( "TestConstField4" , "TEST_CONST_FIELD4" ) ]
41+ public void ConvertsConstantFieldsToFullCapitalCase ( string fieldName , string expected )
42+ {
43+ var fi = typeof ( TestClass ) . GetField ( fieldName , _bindingFlags ) ;
44+ Assert . AreEqual ( expected , fi . ToSnakeCase ( ) ) ;
45+ }
46+
47+ [ TestCase ( "TestNonConstProperty1" , "test_non_const_property1" ) ]
48+ [ TestCase ( "TestNonConstProperty2" , "test_non_const_property2" ) ]
49+ [ TestCase ( "TestNonConstProperty3" , "test_non_const_property3" ) ]
50+ [ TestCase ( "TestNonConstProperty4" , "test_non_const_property4" ) ]
51+ [ TestCase ( "TestNonConstProperty5" , "test_non_const_property5" ) ]
52+ [ TestCase ( "TestNonConstProperty6" , "test_non_const_property6" ) ]
53+ [ TestCase ( "TestNonConstProperty7" , "test_non_const_property7" ) ]
54+ [ TestCase ( "TestNonConstProperty8" , "test_non_const_property8" ) ]
55+ [ TestCase ( "TestNonConstProperty9" , "test_non_const_property9" ) ]
56+ [ TestCase ( "TestNonConstProperty10" , "test_non_const_property10" ) ]
57+ [ TestCase ( "TestNonConstProperty11" , "test_non_const_property11" ) ]
58+ [ TestCase ( "TestNonConstProperty12" , "test_non_const_property12" ) ]
59+ [ TestCase ( "TestNonConstProperty13" , "test_non_const_property13" ) ]
60+ [ TestCase ( "TestNonConstProperty14" , "test_non_const_property14" ) ]
61+ [ TestCase ( "TestNonConstProperty15" , "test_non_const_property15" ) ]
62+ [ TestCase ( "TestNonConstProperty16" , "test_non_const_property16" ) ]
63+ public void ConvertsNonConstantPropertiesToSnakeCase ( string propertyName , string expected )
64+ {
65+ var pi = typeof ( TestClass ) . GetProperty ( propertyName , _bindingFlags ) ;
66+ Assert . AreEqual ( expected , pi . ToSnakeCase ( ) ) ;
67+ }
68+
69+ [ TestCase ( "TestConstProperty1" , "TEST_CONST_PROPERTY1" ) ]
70+ [ TestCase ( "TestConstProperty2" , "TEST_CONST_PROPERTY2" ) ]
71+ [ TestCase ( "TestConstProperty3" , "TEST_CONST_PROPERTY3" ) ]
72+ public void ConvertsConstantPropertiesToFullCapitalCase ( string propertyName , string expected )
73+ {
74+ var pi = typeof ( TestClass ) . GetProperty ( propertyName , _bindingFlags ) ;
75+ Assert . AreEqual ( expected , pi . ToSnakeCase ( ) ) ;
76+ }
77+
78+ private class TestClass
79+ {
80+ public string TestNonConstField1 = "TestNonConstField1" ;
81+ protected string TestNonConstField2 = "TestNonConstField2" ;
82+ public static string TestNonConstField3 = "TestNonConstField3" ;
83+ protected static string TestNonConstField4 = "TestNonConstField4" ;
84+
85+ public const string TestConstField1 = "TestConstField1" ;
86+ protected const string TestConstField2 = "TestConstField2" ;
87+ public static readonly string TestConstField3 = "TestConstField3" ;
88+ protected static readonly string TestConstField4 = "TestConstField4" ;
89+
90+ public string TestNonConstProperty1 { get ; set ; } = "TestNonConstProperty1" ;
91+ protected string TestNonConstProperty2 { get ; set ; } = "TestNonConstProperty2" ;
92+ public string TestNonConstProperty3 { get ; } = "TestNonConstProperty3" ;
93+ protected string TestNonConstProperty4 { get ; } = "TestNonConstProperty4" ;
94+ public string TestNonConstProperty5 { get ; private set ; } = "TestNonConstProperty5" ;
95+ protected string TestNonConstProperty6 { get ; private set ; } = "TestNonConstProperty6" ;
96+ public string TestNonConstProperty7 { get ; protected set ; } = "TestNonConstProperty7" ;
97+ public string TestNonConstProperty8 { get ; internal set ; } = "TestNonConstProperty8" ;
98+ public string TestNonConstProperty9 { get ; protected internal set ; } = "TestNonConstProperty9" ;
99+ public static string TestNonConstProperty10 { get ; set ; } = "TestNonConstProperty10" ;
100+ protected static string TestNonConstProperty11 { get ; set ; } = "TestNonConstProperty11" ;
101+ public static string TestNonConstProperty12 { get ; private set ; } = "TestNonConstProperty12" ;
102+ protected static string TestNonConstProperty13 { get ; private set ; } = "TestNonConstProperty13" ;
103+ public static string TestNonConstProperty14 { get ; protected set ; } = "TestNonConstProperty14" ;
104+ public static string TestNonConstProperty15 { get ; internal set ; } = "TestNonConstProperty15" ;
105+ public static string TestNonConstProperty16 { get ; protected internal set ; } = "TestNonConstProperty16" ;
106+
107+
108+ public static string TestConstProperty1 => "TestConstProperty1" ;
109+ public static string TestConstProperty2 { get ; } = "TestConstProperty2" ;
110+ protected static string TestConstProperty3 { get ; } = "TestConstProperty3" ;
111+ }
22112 }
23113}
0 commit comments