Skip to content

Commit 6ca2df9

Browse files
authored
Merge pull request #4 from hlaueriksson/dencode
DenCode
2 parents 4303631 + c80eee0 commit 6ca2df9

File tree

11 files changed

+115
-32
lines changed

11 files changed

+115
-32
lines changed

docs/dencode.png

-18.3 KB
Loading

src/Community.PowerToys.Run.Plugin.DenCode.UnitTests/ExtensionsTests.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public void GetDenCodeMethods()
1111
{
1212
var result = Constants.Methods.GetDenCodeMethods();
1313
result.Should().NotBeEmpty();
14-
result.Should().HaveCount(67);
14+
result.Should().HaveCount(68);
1515

1616
var last = result.Last().Value;
1717
last.Should().BeEquivalentTo(new DenCodeMethod()
@@ -33,7 +33,7 @@ public void GetDenCodeLabels()
3333
{
3434
var result = Constants.Methods.GetDenCodeMethods().GetDenCodeLabels();
3535
result.Should().NotBeEmpty();
36-
result.Should().HaveCount(104);
36+
result.Should().HaveCount(106);
3737

3838
var last = result.Last().Value;
3939
last.Should().BeEquivalentTo(new DenCodeMethod()
@@ -60,5 +60,33 @@ public void GetRequestType()
6060
var result = method.GetRequestType();
6161
result.Should().Be("hash");
6262
}
63+
64+
[TestMethod]
65+
public void IsRoot()
66+
{
67+
var result = Constants.Methods.GetDenCodeMethods();
68+
var first = result.First().Value;
69+
first.IsRoot().Should().BeTrue();
70+
result.Skip(1).Should().AllSatisfy(x => x.Value.IsRoot().Should().BeFalse());
71+
}
72+
73+
[TestMethod]
74+
public void IsBranch()
75+
{
76+
string[] branches = ["all.all", "string.all", "number.all", "date.all", "color.all", "cipher.all", "hash.all"];
77+
var result = Constants.Methods.GetDenCodeMethods();
78+
79+
foreach (var method in result.Values)
80+
{
81+
if (branches.Contains(method.Key))
82+
{
83+
method.IsBranch().Should().BeTrue();
84+
}
85+
else
86+
{
87+
method.IsBranch().Should().BeFalse();
88+
}
89+
}
90+
}
6391
}
6492
}

src/Community.PowerToys.Run.Plugin.DenCode.UnitTests/MainTests.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,23 @@ public class MainTests
1414
[TestInitialize]
1515
public void TestInitialize()
1616
{
17-
var json = JsonDocument.Parse("{ \"encStrHex\": \"48656c6c6f2c20776f726c6421\", \"encStrURLEncoding\": \"Hello%2C%20world%21\" }");
17+
var json = JsonDocument.Parse(
18+
"""
19+
{
20+
"encStrHex": "48656c6c6f2c20776f726c6421",
21+
"encStrURLEncoding": "Hello%2C%20world%21",
22+
"encStrHTMLEscape": "Hello, world!",
23+
"encStrHTMLEscapeFully": "Hello, world!",
24+
"decStrHTMLEscape": "Hello, world!"
25+
}
26+
"""
27+
);
1828

1929
var mock = new Mock<IDenCodeClient>();
2030
mock.Setup(x => x.DenCodeAsync("Hello, world!")).ReturnsAsync(AllDenCodeResponse());
2131
mock.Setup(x => x.DenCodeAsync(It.Is<DenCodeMethod>(x => x.Key == "string.hex"), "Hello, world!")).ReturnsAsync(HexDenCodeResponse());
32+
mock.Setup(x => x.DenCodeAsync(It.Is<DenCodeMethod>(x => x.Key == "string.all"), "Hello, world!")).ReturnsAsync(HtmlEscapeDenCodeResponse());
33+
mock.Setup(x => x.DenCodeAsync(It.Is<DenCodeMethod>(x => x.Key == "string.html-escape"), "Hello, world!")).ReturnsAsync(HtmlEscapeDenCodeResponse());
2234

2335
_subject = new Main(mock.Object);
2436

@@ -35,7 +47,17 @@ public void TestInitialize()
3547
{
3648
response = new Dictionary<string, JsonElement>
3749
{
38-
{ "encStrHex", json.RootElement.GetProperty("encStrHex") }
50+
{ "encStrHex", json.RootElement.GetProperty("encStrHex") },
51+
}
52+
};
53+
54+
DenCodeResponse HtmlEscapeDenCodeResponse() => new()
55+
{
56+
response = new Dictionary<string, JsonElement>
57+
{
58+
{ "encStrHTMLEscape", json.RootElement.GetProperty("encStrHTMLEscape") },
59+
{ "encStrHTMLEscapeFully", json.RootElement.GetProperty("encStrHTMLEscapeFully") },
60+
{ "decStrHTMLEscape", json.RootElement.GetProperty("decStrHTMLEscape") },
3961
}
4062
};
4163
}
@@ -54,7 +76,7 @@ public void Query_without_delayedExecution_should_return_empty_result()
5476
public void Query_with_empty_args_should_return_all_DenCodeMethods()
5577
{
5678
_subject.Query(new(""), true)
57-
.Should().HaveCount(67);
79+
.Should().HaveCount(68);
5880
}
5981

6082
[TestMethod]
@@ -78,6 +100,20 @@ public void Query_with_value_args_should_return_matching_DenCodeMethods()
78100
.Should().HaveCount(2);
79101
}
80102

103+
[TestMethod]
104+
public void Query_branch_method_removes_unchanged_results()
105+
{
106+
_subject.Query(new("string.all Hello, world!"), true)
107+
.Should().HaveCount(1);
108+
}
109+
110+
[TestMethod]
111+
public void Query_leaf_method_keeps_unchanged_results()
112+
{
113+
_subject.Query(new("string.html-escape Hello, world!"), true)
114+
.Should().HaveCount(3);
115+
}
116+
81117
[TestMethod]
82118
public void LoadContextMenus_with_no_ContextData_should_return_empty_result()
83119
{

src/Community.PowerToys.Run.Plugin.DenCode/DenCodeClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public string GetUrl(DenCodeMethod method)
9292
{
9393
ArgumentNullException.ThrowIfNull(method);
9494

95-
if (method.Method == Constants.AllMethod)
95+
if (method.IsRoot())
9696
{
9797
return "https://dencode.com";
9898
}

src/Community.PowerToys.Run.Plugin.DenCode/Extensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,15 @@ public static string GetRequestType(this DenCodeMethod method)
2929
{
3030
return method.Key.Substring(0, method.Key.IndexOf('.', StringComparison.Ordinal));
3131
}
32+
33+
public static bool IsRoot(this DenCodeMethod method)
34+
{
35+
return method.Key.Equals("all.all", StringComparison.Ordinal);
36+
}
37+
38+
public static bool IsBranch(this DenCodeMethod method)
39+
{
40+
return method.Key.Contains(".all", StringComparison.Ordinal);
41+
}
3242
}
3343
}
-249 Bytes
Loading
-639 Bytes
Loading
-1.28 KB
Loading

src/Community.PowerToys.Run.Plugin.DenCode/Main.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public List<Result> Query(Query query, bool delayedExecution)
114114
#pragma warning restore VSTHRD104 // Offer async methods
115115
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
116116

117-
return GetResultsFromDenCodeResponse(response, value);
117+
return GetResultsFromDenCodeResponse(response, value, method.IsBranch());
118118
}
119119
else
120120
{
@@ -137,7 +137,7 @@ public List<Result> Query(Query query, bool delayedExecution)
137137
ContextData = method,
138138
};
139139

140-
List<Result> GetResultsFromDenCodeResponse(DenCodeResponse? response, string value)
140+
List<Result> GetResultsFromDenCodeResponse(DenCodeResponse? response, string value, bool removeUnchangedResults = true)
141141
{
142142
var results = new List<Result>();
143143

@@ -155,7 +155,7 @@ List<Result> GetResultsFromDenCodeResponse(DenCodeResponse? response, string val
155155
continue;
156156
}
157157

158-
if (result == value)
158+
if (removeUnchangedResults && result == value)
159159
{
160160
continue;
161161
}

src/Community.PowerToys.Run.Plugin.DenCode/Models/Constants.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ namespace Community.PowerToys.Run.Plugin.DenCode.Models
55
/// </summary>
66
public static partial class Constants
77
{
8-
public const string AllMethod = "ALL";
9-
108
public const string AllRequest =
119
"""
1210
{

0 commit comments

Comments
 (0)