Skip to content

Commit d29e5d0

Browse files
committed
Handle "starts with" and "ends with" case.
1 parent c808330 commit d29e5d0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Java.Interop.Tools.Generator/Metadata/NamespaceTransform.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ public string ApplyInternal (string value)
4545

4646
public string Apply (string value)
4747
{
48+
// Handle a "starts with" and "ends with" transform
49+
if (IsStartsWith && IsEndsWith) {
50+
if (value.Equals (OldValue, StringComparison.OrdinalIgnoreCase))
51+
return NewValue;
52+
53+
// Don't let this fall through
54+
return value;
55+
}
56+
4857
// Handle a "starts with" transform
4958
if (IsStartsWith) {
5059
if (value.StartsWith (OldValue, StringComparison.OrdinalIgnoreCase))

tests/Java.Interop.Tools.Generator-Tests/Metadata/NamespaceTransformTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public void GetTransformedNamespace ()
7878
AssertTransformedNamespace ("Androidx.Androidx.Core", "AndroidX.AndroidX.Core", new NamespaceTransform ("androidx", "AndroidX"));
7979
AssertTransformedNamespace ("google.androidx.Core", "Xamarin.AndroidX.Core", new NamespaceTransform ("androidx", "AndroidX"), new NamespaceTransform ("google", "Xamarin"));
8080

81+
// Starts with and ends with
82+
AssertTransformedNamespace ("example", "Transformed", new NamespaceTransform (".example.", "Transformed"));
83+
AssertTransformedNamespace ("Androidx.Core", "Transformed", new NamespaceTransform (".Androidx.Core.", "Transformed"));
84+
AssertTransformedNamespace ("Androidx.Core", "Androidx.Core", new NamespaceTransform (".Core.", "Transformed"));
85+
AssertTransformedNamespace ("Androidx.Core", "Androidx.Core", new NamespaceTransform (".AndroidX.", "Transformed"));
86+
8187
// Starts with
8288
AssertTransformedNamespace ("Androidx.Androidx.Core", "AndroidX2.Androidx.Core", new NamespaceTransform ("AndroidX.", "AndroidX2"));
8389
AssertTransformedNamespace ("Androidx.Androidx.Core", "Androidx.Core", new NamespaceTransform ("AndroidX.", ""));

0 commit comments

Comments
 (0)