Skip to content

Commit 79311d3

Browse files
authored
Merge pull request #124 from Rekkonnect/dev/hex-bin-int-display
Hex/binary integer value display
2 parents 92aa6d9 + b007605 commit 79311d3

21 files changed

Lines changed: 713 additions & 38 deletions
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Syndiesis.Utilities;
2+
3+
namespace Syndiesis.Tests;
4+
5+
public sealed class BinaryIntegerWriterTests
6+
{
7+
[Test]
8+
[MethodDataSource(nameof(WriterTestCasesSource))]
9+
public async Task Test(WriterTestCase @case)
10+
{
11+
var info = IntegerInfo.Create(@case.Value);
12+
var result = BinaryIntegerWriter.Write(info, @case.GroupLength);
13+
await Assert.That(result).IsEqualTo(@case.Expected);
14+
}
15+
16+
public IReadOnlyList<WriterTestCase> WriterTestCasesSource()
17+
{
18+
return
19+
[
20+
// int
21+
new(0b1, 0, "1"),
22+
new(0b0001, 0, "1"),
23+
24+
new(0b0001, 4, "1"),
25+
new(0b0010_0101_0001_0000, 4, "10_0101_0001_0000"),
26+
27+
new(0b101010101, 2, "1_01_01_01_01"),
28+
29+
new(0b1111111, 3, "1_111_111"),
30+
];
31+
}
32+
33+
public sealed record WriterTestCase(
34+
object Value, int GroupLength, string Expected);
35+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Syndiesis.Utilities;
2+
3+
namespace Syndiesis.Tests;
4+
5+
public sealed class HexIntegerWriterTests
6+
{
7+
[Test]
8+
[MethodDataSource(nameof(WriterTestCasesSource))]
9+
public async Task Test(WriterTestCase @case)
10+
{
11+
var info = IntegerInfo.Create(@case.Value);
12+
var result = HexIntegerWriter.Write(info, @case.GroupLength);
13+
await Assert.That(result).IsEqualTo(@case.Expected);
14+
}
15+
16+
public IReadOnlyList<WriterTestCase> WriterTestCasesSource()
17+
{
18+
return
19+
[
20+
new(0x00000123, 0, "00000123"),
21+
22+
new(0x0000_0123, 4, "0000_0123"),
23+
new(0x1021_3201, 4, "1021_3201"),
24+
25+
new(0x01_23_45_67, 2, "01_23_45_67"),
26+
27+
new(0x01234567, 3, "01_234_567"),
28+
];
29+
}
30+
31+
public sealed record WriterTestCase(
32+
object Value, int GroupLength, string Expected);
33+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using Syndiesis.Utilities;
2+
3+
namespace Syndiesis.Tests;
4+
5+
public sealed class RightSideBufferWriterTests
6+
{
7+
[Test]
8+
public async Task UseCase0()
9+
{
10+
const int capacity = 10;
11+
Span<char> s = stackalloc char[capacity];
12+
var writer = new RightSideBufferWriter<char>(s);
13+
writer.Write("312");
14+
writer.Write('4');
15+
writer.Write("01");
16+
17+
var finalized = writer.GetFinalized();
18+
await Assert.That(finalized.ToString()).IsEqualTo("014312");
19+
}
20+
21+
[Test]
22+
public async Task TestOverflowWithChar()
23+
{
24+
const int capacity = 1;
25+
Span<char> s = stackalloc char[capacity];
26+
var writer = new RightSideBufferWriter<char>(s);
27+
writer.Write('4');
28+
29+
// Can't use writer inside a lambda; hence the manual try block
30+
try
31+
{
32+
writer.Write('0');
33+
Assert.Fail("Expected an exception");
34+
}
35+
catch { }
36+
37+
var finalized = writer.GetFinalized();
38+
await Assert.That(finalized.ToString()).IsEqualTo("4");
39+
}
40+
41+
[Test]
42+
public async Task TestOverflowWithString0()
43+
{
44+
const int capacity = 1;
45+
Span<char> s = stackalloc char[capacity];
46+
var writer = new RightSideBufferWriter<char>(s);
47+
writer.Write('4');
48+
49+
// Can't use writer inside a lambda; hence the manual try block
50+
try
51+
{
52+
writer.Write("0");
53+
Assert.Fail("Expected an exception");
54+
}
55+
catch { }
56+
57+
try
58+
{
59+
writer.Write("041");
60+
Assert.Fail("Expected an exception");
61+
}
62+
catch { }
63+
64+
// Expect no exception with an empty string
65+
writer.Write(string.Empty);
66+
67+
var finalized = writer.GetFinalized();
68+
await Assert.That(finalized.ToString()).IsEqualTo("4");
69+
}
70+
71+
[Test]
72+
public async Task TestOverflowWithString1()
73+
{
74+
const int capacity = 2;
75+
Span<char> s = stackalloc char[capacity];
76+
var writer = new RightSideBufferWriter<char>(s);
77+
writer.Write('4');
78+
79+
try
80+
{
81+
writer.Write("041");
82+
Assert.Fail("Expected an exception");
83+
}
84+
catch { }
85+
86+
try
87+
{
88+
writer.Write("01");
89+
Assert.Fail("Expected an exception");
90+
}
91+
catch { }
92+
93+
// Expect no exception with an empty string
94+
writer.Write(string.Empty);
95+
96+
// Expect the buffer to have one more char of remaining space
97+
writer.Write("0");
98+
99+
// Now the buffer should be full
100+
try
101+
{
102+
writer.Write("0");
103+
Assert.Fail("Expected an exception");
104+
}
105+
catch { }
106+
107+
var finalized = writer.GetFinalized();
108+
await Assert.That(finalized.ToString()).IsEqualTo("04");
109+
}
110+
111+
[Test]
112+
public async Task TestEmpty()
113+
{
114+
Span<char> s = [];
115+
var writer = new RightSideBufferWriter<char>(s);
116+
var finalized = writer.GetFinalized();
117+
await Assert.That(finalized.ToString()).IsEqualTo(string.Empty);
118+
}
119+
}

Syndiesis/ColorHelpers/HsvTransformation.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
namespace Syndiesis.ColorHelpers;
44

5-
public readonly record struct HsvTransformation(double Alpha, double Hue, double Saturation, double Value)
5+
public readonly record struct HsvTransformation(
6+
double Alpha = 0,
7+
double Hue = 0,
8+
double Saturation = 0,
9+
double Value = 0)
610
: IColorTransformation<HsvColor>
711
{
812
public HsvColor Transform(HsvColor color)

Syndiesis/Controls/Editor/QuickInfo/CSharpTypeCommonInlinesCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private GroupedRunInline.IBuilder CreateTupleTypeFieldInline(IFieldSymbol field)
271271
ILazilyUpdatedBrush brush = fieldBrush;
272272
if (!field.IsExplicitlyNamedTupleElement)
273273
{
274-
var fadeTransformation = new HsvTransformation(0, 0, 0, 0.4);
274+
var fadeTransformation = new HsvTransformation(Value: -0.4);
275275
brush = fieldBrush.WithHsvTransformation(fadeTransformation);
276276
}
277277

Syndiesis/Controls/Editor/RoslynColorizer.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using AvaloniaEdit.Document;
44
using AvaloniaEdit.Rendering;
55
using Microsoft.CodeAnalysis;
6+
using Syndiesis.ColorHelpers;
67
using Syndiesis.Core;
78
using Syndiesis.InternalGenerators.Core;
89
using System.Text.Json.Serialization;
@@ -228,6 +229,9 @@ public LazilyUpdatedGradientStop ConflictMarkerEndStop
228229
[JsonIgnore]
229230
public readonly LazilyUpdatedGradientBrush ConflictMarkerBrush;
230231

232+
[JsonIgnore]
233+
public readonly LazilyUpdatedHsvTransformedSolidBrush FadedNumericLiteralBrush;
234+
231235
public ColorizationStyles()
232236
{
233237
RangeVariableBrush = DoubleColorGradientBrush(
@@ -236,6 +240,9 @@ public ColorizationStyles()
236240
PreprocessingStartStop, PreprocessingEndStop);
237241
ConflictMarkerBrush = DoubleColorGradientBrush(
238242
ConflictMarkerStartStop, ConflictMarkerEndStop);
243+
244+
FadedNumericLiteralBrush = NumericLiteralBrush
245+
.WithHsvTransformation(new HsvTransformation(Saturation: 0.2, Value: -0.2));
239246
}
240247

241248
private static LazilyUpdatedGradientBrush DoubleColorGradientBrush(
@@ -251,4 +258,4 @@ private static LazilyUpdatedGradientBrush DoubleColorGradientBrush(
251258
return new LazilyUpdatedGradientBrush(brush, [startStop, endStop]);
252259
}
253260
}
254-
}
261+
}

Syndiesis/Core/DisplayAnalysis/AttributesAnalysisNodeCreator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public override AnalysisTreeListNodeLine CreateNodeLine(
309309
{
310310
var inline = TypeDisplayGroupedRun(typeof(AttributeData));
311311
inlines.Add(inline);
312-
inlines.Add(NewValueKindSplitterRun());
312+
inlines.Add(CreateLargeSplitterRun());
313313
var className = attribute.AttributeData.AttributeClass?.Name;
314314
var nameInline = CreateNameInline(className);
315315
inlines.Add(nameInline);
@@ -427,7 +427,7 @@ public override AnalysisTreeListNodeLine CreateNodeLine(
427427
inlines.Add(nameInline);
428428
inlines.Add(splitterInline);
429429
inlines.Add(valueInline);
430-
inlines.Add(NewValueKindSplitterRun());
430+
inlines.Add(CreateLargeSplitterRun());
431431
inlines.Add(CreateKindInline(argument.Value));
432432

433433
return AnalysisTreeListNodeLine(

0 commit comments

Comments
 (0)