Skip to content

Commit d94b7e4

Browse files
Minor snakecase naming fix (#88)
- Minor snakecase naming fix. Extending unit tests
1 parent 7847dbb commit d94b7e4

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

src/embed_tests/TestUtil.cs

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,57 +23,67 @@ public class TestUtil
2323
[TestCase("test_CamelCaseString", "test_camel_case_string")]
2424
[TestCase("SP500EMini", "sp_500_e_mini")]
2525
[TestCase("Sentiment30Days", "sentiment_30_days")]
26-
[TestCase("PriceChange1m", "price_change_1m")] // A single digit followed by a lowercase letter
26+
[TestCase("PriceChange1m", "price_change_1m")]
27+
[TestCase("PriceChange1M", "price_change_1m")]
28+
[TestCase("PriceChange1MY", "price_change_1_my")]
29+
[TestCase("PriceChange1My", "price_change_1_my")]
30+
[TestCase("PERatio", "pe_ratio")]
31+
[TestCase("PERatio1YearGrowth", "pe_ratio_1_year_growth")]
32+
[TestCase("HeadquarterAddressLine5", "headquarter_address_line_5")]
33+
[TestCase("PERatio10YearAverage", "pe_ratio_10_year_average")]
34+
[TestCase("CAPERatio", "cape_ratio")]
35+
[TestCase("EVToEBITDA3YearGrowth", "ev_to_ebitda_3_year_growth")]
36+
[TestCase("", "")]
2737
public void ConvertsNameToSnakeCase(string name, string expected)
2838
{
2939
Assert.AreEqual(expected, name.ToSnakeCase());
3040
}
3141

32-
[TestCase("TestNonConstField1", "test_non_const_field1")]
33-
[TestCase("TestNonConstField2", "test_non_const_field2")]
34-
[TestCase("TestNonConstField3", "test_non_const_field3")]
35-
[TestCase("TestNonConstField4", "test_non_const_field4")]
42+
[TestCase("TestNonConstField1", "test_non_const_field_1")]
43+
[TestCase("TestNonConstField2", "test_non_const_field_2")]
44+
[TestCase("TestNonConstField3", "test_non_const_field_3")]
45+
[TestCase("TestNonConstField4", "test_non_const_field_4")]
3646
public void ConvertsNonConstantFieldsToSnakeCase(string fieldName, string expected)
3747
{
3848
var fi = typeof(TestClass).GetField(fieldName, _bindingFlags);
3949
Assert.AreEqual(expected, fi.ToSnakeCase());
4050
}
4151

42-
[TestCase("TestConstField1", "TEST_CONST_FIELD1")]
43-
[TestCase("TestConstField2", "TEST_CONST_FIELD2")]
44-
[TestCase("TestConstField3", "TEST_CONST_FIELD3")]
45-
[TestCase("TestConstField4", "TEST_CONST_FIELD4")]
52+
[TestCase("TestConstField1", "TEST_CONST_FIELD_1")]
53+
[TestCase("TestConstField2", "TEST_CONST_FIELD_2")]
54+
[TestCase("TestConstField3", "TEST_CONST_FIELD_3")]
55+
[TestCase("TestConstField4", "TEST_CONST_FIELD_4")]
4656
public void ConvertsConstantFieldsToFullCapitalCase(string fieldName, string expected)
4757
{
4858
var fi = typeof(TestClass).GetField(fieldName, _bindingFlags);
4959
Assert.AreEqual(expected, fi.ToSnakeCase());
5060
}
5161

52-
[TestCase("TestNonConstProperty1", "test_non_const_property1")]
53-
[TestCase("TestNonConstProperty2", "test_non_const_property2")]
54-
[TestCase("TestNonConstProperty3", "test_non_const_property3")]
55-
[TestCase("TestNonConstProperty4", "test_non_const_property4")]
56-
[TestCase("TestNonConstProperty5", "test_non_const_property5")]
57-
[TestCase("TestNonConstProperty6", "test_non_const_property6")]
58-
[TestCase("TestNonConstProperty7", "test_non_const_property7")]
59-
[TestCase("TestNonConstProperty8", "test_non_const_property8")]
60-
[TestCase("TestNonConstProperty9", "test_non_const_property9")]
61-
[TestCase("TestNonConstProperty10", "test_non_const_property10")]
62-
[TestCase("TestNonConstProperty11", "test_non_const_property11")]
63-
[TestCase("TestNonConstProperty12", "test_non_const_property12")]
64-
[TestCase("TestNonConstProperty13", "test_non_const_property13")]
65-
[TestCase("TestNonConstProperty14", "test_non_const_property14")]
66-
[TestCase("TestNonConstProperty15", "test_non_const_property15")]
67-
[TestCase("TestNonConstProperty16", "test_non_const_property16")]
62+
[TestCase("TestNonConstProperty1", "test_non_const_property_1")]
63+
[TestCase("TestNonConstProperty2", "test_non_const_property_2")]
64+
[TestCase("TestNonConstProperty3", "test_non_const_property_3")]
65+
[TestCase("TestNonConstProperty4", "test_non_const_property_4")]
66+
[TestCase("TestNonConstProperty5", "test_non_const_property_5")]
67+
[TestCase("TestNonConstProperty6", "test_non_const_property_6")]
68+
[TestCase("TestNonConstProperty7", "test_non_const_property_7")]
69+
[TestCase("TestNonConstProperty8", "test_non_const_property_8")]
70+
[TestCase("TestNonConstProperty9", "test_non_const_property_9")]
71+
[TestCase("TestNonConstProperty10", "test_non_const_property_10")]
72+
[TestCase("TestNonConstProperty11", "test_non_const_property_11")]
73+
[TestCase("TestNonConstProperty12", "test_non_const_property_12")]
74+
[TestCase("TestNonConstProperty13", "test_non_const_property_13")]
75+
[TestCase("TestNonConstProperty14", "test_non_const_property_14")]
76+
[TestCase("TestNonConstProperty15", "test_non_const_property_15")]
77+
[TestCase("TestNonConstProperty16", "test_non_const_property_16")]
6878
public void ConvertsNonConstantPropertiesToSnakeCase(string propertyName, string expected)
6979
{
7080
var pi = typeof(TestClass).GetProperty(propertyName, _bindingFlags);
7181
Assert.AreEqual(expected, pi.ToSnakeCase());
7282
}
7383

74-
[TestCase("TestConstProperty1", "TEST_CONST_PROPERTY1")]
75-
[TestCase("TestConstProperty2", "TEST_CONST_PROPERTY2")]
76-
[TestCase("TestConstProperty3", "TEST_CONST_PROPERTY3")]
84+
[TestCase("TestConstProperty1", "TEST_CONST_PROPERTY_1")]
85+
[TestCase("TestConstProperty2", "TEST_CONST_PROPERTY_2")]
86+
[TestCase("TestConstProperty3", "TEST_CONST_PROPERTY_3")]
7787
public void ConvertsConstantPropertiesToFullCapitalCase(string propertyName, string expected)
7888
{
7989
var pi = typeof(TestClass).GetProperty(propertyName, _bindingFlags);

src/runtime/Util/Util.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ public static string ToSnakeCase(this string name, bool constant = false)
189189
case UnicodeCategory.TitlecaseLetter:
190190
if (previousCategory == UnicodeCategory.SpaceSeparator ||
191191
previousCategory == UnicodeCategory.LowercaseLetter ||
192-
previousCategory == UnicodeCategory.DecimalDigitNumber ||
192+
previousCategory == UnicodeCategory.DecimalDigitNumber &&
193+
currentIndex + 1 < name.Length ||
193194
previousCategory != UnicodeCategory.DecimalDigitNumber &&
194195
previousCategory != null &&
195196
currentIndex > 0 &&

0 commit comments

Comments
 (0)