-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathXRefHrefFixerTests.cs
More file actions
147 lines (134 loc) · 7 KB
/
Copy pathXRefHrefFixerTests.cs
File metadata and controls
147 lines (134 loc) · 7 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
namespace UnityXrefMaps.Tests
{
public class XRefHrefFixerTests
{
[Theory]
[InlineData(
"https://docs.unity3d.com/6000.0/Documentation/ScriptReference/",
"UnityEngine",
"N:UnityEngine",
"https://docs.unity3d.com/6000.0/Documentation/ScriptReference/index.html")]
[InlineData(
"https://docs.unity3d.com/6000.0/Documentation/ScriptReference/",
"GameObject",
"T:UnityEngine.GameObject",
"https://docs.unity3d.com/6000.0/Documentation/ScriptReference/GameObject.html")]
public void Unity_Fix(string apiUrl, string name, string commentId, string expected)
{
XrefMapReference xrefMapReference = new()
{
Name = name,
CommentId = commentId,
};
Assert.Equal(expected, XRefHrefFixer.Fix(apiUrl, xrefMapReference, ["UnityEngine"], false));
}
[Theory]
[InlineData(
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/",
"UnityEngine.InputSystem",
"N:UnityEngine.InputSystem",
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/UnityEngine.InputSystem.html")]
[InlineData(
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/",
"InputSystem",
"T:UnityEngine.InputSystem.InputSystem",
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/UnityEngine.InputSystem.InputSystem.html")]
[InlineData(
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/",
"Enable()",
"M:UnityEngine.InputSystem.InputActionAsset.Enable",
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/UnityEngine.InputSystem.InputActionAsset.html#UnityEngine_InputSystem_InputActionAsset_Enable")]
[InlineData(
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/",
"Contains(InputAction)",
"M:UnityEngine.InputSystem.InputActionAsset.Contains(UnityEngine.InputSystem.InputAction)",
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/UnityEngine.InputSystem.InputActionAsset.html#UnityEngine_InputSystem_InputActionAsset_Contains_UnityEngine_InputSystem_InputAction_")]
[InlineData(
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/",
"FindBinding(InputBinding, out InputAction)",
"M:UnityEngine.InputSystem.InputActionAsset.FindBinding(UnityEngine.InputSystem.InputBinding,UnityEngine.InputSystem.InputAction@)",
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/UnityEngine.InputSystem.InputActionAsset.html#UnityEngine_InputSystem_InputActionAsset_FindBinding_UnityEngine_InputSystem_InputBinding_UnityEngine_InputSystem_InputAction__")]
[InlineData(
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/",
"AddDevice<TDevice>(string)",
"M:UnityEngine.InputSystem.InputSystem.AddDevice``1(System.String)",
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/UnityEngine.InputSystem.InputSystem.html#UnityEngine_InputSystem_InputSystem_AddDevice__1_System_String_")]
[InlineData(
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/",
"remoting",
"P:UnityEngine.InputSystem.InputSystem.remoting",
"https://docs.unity3d.com/Packages/com.unity.inputsystem@1.17/api/UnityEngine.InputSystem.InputSystem.html#UnityEngine_InputSystem_InputSystem_remoting")]
public void Package_Fix(string apiUrl, string name, string commentId, string expected)
{
XrefMapReference xrefMapReference = new()
{
Name = name,
CommentId = commentId,
};
Assert.Equal(expected, XRefHrefFixer.Fix(apiUrl, xrefMapReference, Array.Empty<string>(), true));
}
/// <summary>
/// The regex that extracts the bare method name requires a '(' character to match.
/// When the display name has no parentheses — e.g. Name = "MyMethod" — the regex
/// fails, producing an empty string. The code then called uid.Substring(0, -1),
/// which throws ArgumentOutOfRangeException.
/// </summary>
[Fact]
public void Fix_PackageMethodWithNoParenthesesInName_DoesNotThrow()
{
XrefMapReference xrefMapReference = new()
{
CommentId = "M:MyNamespace.MyClass.MyMethod",
Name = "MyMethod",
};
string result = XRefHrefFixer.Fix(
"https://docs.unity3d.com/Packages/test@1.0/api/",
xrefMapReference,
Array.Empty<string>(),
isPackage: true);
Assert.StartsWith("https://docs.unity3d.com/Packages/test@1.0/api/", result);
}
/// <summary>
/// When the method name extracted from the display name — e.g. "DifferentMethod" from
/// "DifferentMethod()" — does not appear in the uid, e.g.
/// "MyNamespace.MyClass.ActualMethod", IndexOf returns -1. The code then called
/// uid.Substring(0, -2), which throws ArgumentOutOfRangeException.
/// </summary>
[Fact]
public void Fix_PackageMethodNameAbsentFromUid_DoesNotThrow()
{
XrefMapReference xrefMapReference = new()
{
CommentId = "M:MyNamespace.MyClass.ActualMethod",
Name = "DifferentMethod()",
};
string result = XRefHrefFixer.Fix(
"https://docs.unity3d.com/Packages/test@1.0/api/",
xrefMapReference,
Array.Empty<string>(),
isPackage: true);
Assert.StartsWith("https://docs.unity3d.com/Packages/test@1.0/api/", result);
}
/// <summary>
/// When the property name — e.g. "DifferentProperty" — does not appear in the uid,
/// e.g. "MyNamespace.MyClass.ActualProperty", IndexOf returns -1. The code then called
/// uid.Substring(0, -2), which throws ArgumentOutOfRangeException.
/// </summary>
[Fact]
public void Fix_PackagePropertyNameAbsentFromUid_DoesNotThrow()
{
XrefMapReference xrefMapReference = new()
{
CommentId = "P:MyNamespace.MyClass.ActualProperty",
Name = "DifferentProperty",
};
string result = XRefHrefFixer.Fix(
"https://docs.unity3d.com/Packages/test@1.0/api/",
xrefMapReference,
Array.Empty<string>(),
isPackage: true);
Assert.StartsWith("https://docs.unity3d.com/Packages/test@1.0/api/", result);
}
}
}