• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

luttje / Key2Joy / 6557152774

18 Oct 2023 06:36AM UTC coverage: 52.519% (+39.8%) from 12.718%
6557152774

push

github

web-flow
Adding more tests, fixing bugs in the process (#48)

* Add config manager tests

* legacy config and mapping profile tests (should fix #42)

* remove comment, problem was caused by transfer across appdomain (or to/fro scripting environment)

* Test core functionality #48 + includes minor refactoring to be able to test + added docs

* Add interop tests + implement and test async test utility (refactors away from singletons)

* fix not all tests running in workflow

* config and interop tests

* Refactor and allow mocking global input hook class

* add capture action test

* Make Execute override optional for script only methods

* add dependency injection + refactor and try test gamepad service

* Refactor config singleton to using dependency injection

* add tests for scripting

* add tests for plugin set + fix plugin showing as loaded even if checksum match failed

* fix tests failing because it relied on config exist (I guess the test order was accidentally correct earlier, this means we should really fix cleanup so we catch this sooner)

* refactor docs code + fix wrong enum summary

* refactor docs builder and start testing it a bit

* fix cmd project structure

* ignore designer files in tests

* cleanup and refactor UI code + show latest version in help

* truncate listview action column

* allow user config to minimize app when pressing X (defaults to shut down app) resolves #45

696 of 1757 branches covered (0.0%)

Branch coverage included in aggregate %.

4597 of 4597 new or added lines in 138 files covered. (100.0%)

3619 of 6459 relevant lines covered (56.03%)

17089.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.38
/Support/BuildMarkdownDocs/Members/FunctionMember.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Xml.Linq;
6
using BuildMarkdownDocs.Util;
7

8
namespace BuildMarkdownDocs.Members;
9

10
internal class FunctionMember : Member
11
{
12
    public Example[] MarkdownExamples { get; set; }
50✔
13
    public Parameter[] Parameters { get; set; }
205✔
14
    public ReturnType ReturnType { get; set; }
76✔
15
    public bool IsPlugin { get; set; }
50✔
16

17
    public string GetParametersSignature()
18
    {
19
        if (this.Parameters == null)
50✔
20
        {
21
            return string.Empty;
8✔
22
        }
23

24
        return string.Join(", ", this.Parameters?
42!
25
                .Select(p => $"```{p.GetTypeName()}```"));
124✔
26
    }
27

28
    internal static Member FromXml(XElement element, bool isPlugin = false)
29
    {
30
        // Get the parameter types from member attribute, e.g: <member name="M:Key2Joy.Mapping.KeyboardAction.ExecuteForScript(System.Windows.Forms.Keys,Key2Joy.Input.PressState)">
31
        var memberName = element.Attribute("name").Value;
25✔
32
        var parametersStart = memberName.IndexOf('(');
25✔
33
        Type[] parameterTypes;
34

35
        if (parametersStart > -1)
25✔
36
        {
37
            var parametersEnd = memberName.LastIndexOf(')') - 1;
21✔
38
            var parameters = memberName.Substring(parametersStart + 1, memberName.Length - parametersStart - (memberName.Length - parametersEnd));
21✔
39
            parameterTypes = parameters.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
21✔
40
                .Select(TypeUtil.GetType)
21✔
41
                .ToArray();
21✔
42
        }
43
        else
44
        {
45
            parameterTypes = new Type[0];
4✔
46
        }
47

48
        FunctionMember member = new()
25!
49
        {
25✔
50
            Name = element.Element("name")?.Value ?? element.Attribute("name").Value
25✔
51
        };
25✔
52

53
        var summaryNodes = element.Element("summary").Nodes();
25✔
54
        StringBuilder summary = new();
25✔
55

56
        foreach (var node in summaryNodes)
136✔
57
        {
58
            if (node is XElement nodeElement)
43✔
59
            {
60
                if (nodeElement.Name == "see")
9!
61
                {
62
                    var href = nodeElement.Attribute("href")?.Value;
9!
63
                    var cref = nodeElement.Attribute("cref")?.Value;
9!
64

65
                    if (href != null)
9!
66
                    {
67
                        var content = string.IsNullOrEmpty(nodeElement.Value) ? href : nodeElement.Value;
9✔
68
                        summary.Append($"[{content}]({href})");
9✔
69
                    }
70
                    else
71
                    {
72
                        summary.Append($"`{cref}`");
×
73
                    }
74
                }
75
                else
76
                {
77
                    summary.Append(nodeElement.Value.TrimEachLine());
×
78
                }
79
            }
80
            else
81
            {
82
                summary.Append(node.ToString().TrimEachLine());
34✔
83
            }
84
        }
85

86
        member.Summary = summary.ToString();
25✔
87

88
        var returnTypeEl = element.Element("returns");
25✔
89
        var methodInfo = TypeUtil.GetMethodInfo(memberName);
25✔
90
        member.ReturnType = returnTypeEl != null ? ReturnType.FromXml(returnTypeEl, methodInfo) : null;
25✔
91

92
        var i = 0;
25✔
93
        if (parameterTypes.Length > 0)
25✔
94
        {
95
            member.Parameters = element.Elements("param")?
21!
96
                .Select(e => Parameter.FromXml(e, parameterTypes[i++]))
41✔
97
                .ToArray();
21✔
98
        }
99

100
        var markdownMeta = element.Element("markdown-doc");
25✔
101

102
        member.IsPlugin = isPlugin;
25✔
103
        member.Parent = MarkdownMeta.FromXml(markdownMeta);
25✔
104
        member.MarkdownExamples = element.Elements("markdown-example")
25✔
105
            .Select(Example.FromXml)
25✔
106
            .ToArray();
25✔
107

108
        return member;
25✔
109
    }
110

111
    internal override string GetLinkMarkdown() => $"* [`{this.Name}` ({this.GetParametersSignature()})]({this.Parent.Path}{this.Name}.md)";
25✔
112

113
    internal override void FillTemplateReplacements(ref Dictionary<string, string> replacements)
114
    {
115
        base.FillTemplateReplacements(ref replacements);
25✔
116

117
        var parametersSignature = this.GetParametersSignature();
25✔
118
        var parameters = "";
25✔
119

120
        if (this.Parameters != null)
25✔
121
        {
122
            parameters = string.Join("\n", this.Parameters?
21!
123
                .Select(p =>
21✔
124
                    $"* **{p.Name} (" + (p.IsOptional ? "Optional " : "") + $"```{p.GetTypeName(false)}```)** \n" +
62✔
125
                    $"\t{p.Description}\n\n"));
62✔
126
        }
127

128
        var examples = string.Join<Example>("\n\n", this.MarkdownExamples);
25✔
129

130
        replacements.Add("ParametersSignature", parametersSignature);
25✔
131
        replacements.Add("Parameters", parameters);
25✔
132

133
        if (this.ReturnType != null)
25✔
134
        {
135
            replacements.Add("ReturnType", $"```{this.ReturnType.GetTypeName()}```");
13✔
136
            replacements.Add("ReturnTypeDescription", $"{this.ReturnType.Description ?? ""}.");
13✔
137
        }
138
        else
139
        {
140
            replacements.Add("ReturnType", "");
12✔
141
        }
142

143
        replacements.Add("Examples", examples);
25✔
144
        replacements.Add("IsPlugin", this.IsPlugin ? "true" : "");
25!
145
    }
25✔
146
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc