Skip to content

Commit 8d78bba

Browse files
author
Daniel Lemire
committed
silencing more warnings.
1 parent a29aadd commit 8d78bba

File tree

3 files changed

+15
-71
lines changed

3 files changed

+15
-71
lines changed

test/AsciiTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void HardCodedSequencesTest()
8989
}
9090

9191
[Fact]
92-
public void Test_ASCII_generator()
92+
public void TestASCIIGenerator()
9393
{
9494
const int NUM_TRIALS = 1000;
9595
const int MAX_LENGTH = 255;

test/UTF8ValidationTests.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public enum TestSystemRequirements
3131
// Add more as needed
3232
}
3333

34-
public class FactOnSystemRequirementAttribute : FactAttribute
34+
private sealed class FactOnSystemRequirementAttribute : FactAttribute
3535
{
3636
private TestSystemRequirements RequiredSystems;
3737

@@ -62,7 +62,7 @@ private bool IsSystemSupported(TestSystemRequirements requiredSystems)
6262
}
6363

6464

65-
public class TestIfCondition : FactAttribute
65+
public sealed class TestIfCondition : FactAttribute
6666
{
6767
public TestIfCondition(Func<bool> condition, string skipReason)
6868
{
@@ -1034,6 +1034,7 @@ public void BruteForceTestArm64()
10341034
// credit: based on code from Google Fuchsia (Apache Licensed)
10351035
public static bool ValidateUtf8Fuschia(byte[] data)
10361036
{
1037+
if(data == null) return false;
10371038
int pos = 0;
10381039
int len = data.Length;
10391040
uint codePoint;
@@ -1104,13 +1105,14 @@ private bool InvalidateUtf8(byte[] utf8, int badindex,Utf8ValidationDelegate utf
11041105
int utf16CodeUnitCountAdjustment, scalarCountAdjustment;
11051106
byte* dotnetResult = DotnetRuntime.Utf8Utility.GetPointerToFirstInvalidByte(pInput, utf8.Length, out utf16CodeUnitCountAdjustment, out scalarCountAdjustment);
11061107
int dotnetOffset = (int)(dotnetResult - pInput);
1108+
var message = "Suprisingly, scalarResult != simdResult {0} != {1}, badindex = {2}, length = {3}";
11071109
if (scalarOffset != simdOffset)
11081110
{
1109-
Console.WriteLine("Suprisingly, scalarResult != simdResult {0} != {1}, badindex = {2}, length = {3}", scalarOffset, simdOffset, badindex, utf8.Length);
1111+
Console.WriteLine(message, scalarOffset, simdOffset, badindex, utf8.Length);
11101112
}
11111113
if (dotnetOffset != simdOffset)
11121114
{
1113-
Console.WriteLine("Suprisingly, dotnetOffset != simdResult {0} != {1}, badindex = {2}, length = {3}", dotnetOffset, simdOffset, badindex, utf8.Length);
1115+
Console.WriteLine(message, dotnetOffset, simdOffset, badindex, utf8.Length);
11141116
}
11151117
return (scalarResult == simdResult) && (simdResult == dotnetResult);
11161118
}
@@ -1151,7 +1153,7 @@ private bool ValidateUtf8(byte[] utf8,Utf8ValidationDelegate utf8ValidationDeleg
11511153
}
11521154

11531155
// Helper method to calculate the actual offset and length from a Range
1154-
private (int offset, int length) GetOffsetAndLength(int totalLength, Range range)
1156+
private static (int offset, int length) GetOffsetAndLength(int totalLength, Range range)
11551157
{
11561158
var start = range.Start.GetOffset(totalLength);
11571159
var end = range.End.GetOffset(totalLength);
@@ -1167,6 +1169,10 @@ public bool ValidateCount(byte[] utf8, Utf8ValidationDelegate utf8ValidationDele
11671169
{
11681170
int dotnetUtf16Adjustment, dotnetScalarCountAdjustment;
11691171
int simdUnicodeUtf16Adjustment, simdUnicodeScalarCountAdjustment;
1172+
if(utf8 == null || utf8ValidationDelegate == null)
1173+
{
1174+
return false;
1175+
}
11701176

11711177
var isDefaultRange = range.Equals(default(Range));
11721178
var (offset, length) = isDefaultRange ? (0, utf8.Length) : GetOffsetAndLength(utf8.Length, range);

test/helpers/randomutf8.cs

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
namespace tests;
12
using System;
23
using System.Collections.Generic;
34
using System.Linq;
@@ -9,27 +10,12 @@ public class RandomUtf8
910
private double[] probabilities;
1011
private const int maxByteLength = 4;
1112

12-
public RandomUtf8(uint seed, int prob_1byte, int prob_2bytes, int prob_3bytes, int prob_4bytes)
13+
public RandomUtf8(uint seed, int prob1byte, int prob2bytes, int prob3bytes, int prob4bytes)
1314
{
1415
gen = new Random((int)seed);
15-
probabilities = new double[maxByteLength] { prob_1byte, prob_2bytes, prob_3bytes, prob_4bytes };
16+
probabilities = new double[maxByteLength] { prob1byte, prob2bytes, prob3bytes, prob4bytes };
1617
}
1718

18-
// public byte[] Generate(int howManyUnits, int? byteCountInUnit = null)
19-
// {
20-
// var result = new List<byte>();
21-
// while (result.Count < howManyUnits)
22-
// {
23-
// int count = byteCountInUnit ?? PickRandomByteCount();
24-
// int codePoint = GenerateCodePoint(count);
25-
// byte[] utf8Bytes = Encoding.UTF8.GetBytes(char.ConvertFromUtf32(codePoint));
26-
27-
// result.AddRange(utf8Bytes);
28-
// if (result.Count + utf8Bytes.Length > howManyUnits)
29-
// break;
30-
// }
31-
// return result.ToArray();
32-
// }
3319

3420
public List<byte> Generate(int howManyUnits, int? byteCountInUnit = null)
3521
{
@@ -47,54 +33,6 @@ public List<byte> Generate(int howManyUnits, int? byteCountInUnit = null)
4733
return result;
4834
}
4935

50-
// public List<byte> Generate(int howManyUnits, int? byteCountInUnit = null)
51-
// {
52-
// var result = new List<byte>();
53-
// var unitsAdded = 0; // Track the number of characters added.
54-
55-
// while (unitsAdded < howManyUnits)
56-
// {
57-
// int count = byteCountInUnit ?? PickRandomByteCount();
58-
// int codePoint = GenerateCodePoint(count);
59-
// byte[] utf8Bytes = Encoding.UTF8.GetBytes(char.ConvertFromUtf32(codePoint));
60-
61-
// // Ensure adding the new character won't exceed the howManyUnits limit.
62-
// if (unitsAdded + 1 > howManyUnits)
63-
// break;
64-
65-
// result.AddRange(utf8Bytes);
66-
// unitsAdded++; // Increment the units (characters) count.
67-
// }
68-
69-
// return result;
70-
// }
71-
72-
73-
// public object Generate(int howManyUnits, int? byteCountInUnit = null, bool returnAsList = false)
74-
// {
75-
// var result = new List<byte>();
76-
// while (result.Count < howManyUnits)
77-
// {
78-
// int count = byteCountInUnit ?? PickRandomByteCount();
79-
// int codePoint = GenerateCodePoint(count);
80-
// byte[] utf8Bytes = Encoding.UTF8.GetBytes(char.ConvertFromUtf32(codePoint));
81-
82-
// if (result.Count + utf8Bytes.Length > howManyUnits)
83-
// break;
84-
85-
// result.AddRange(utf8Bytes);
86-
// }
87-
88-
// if (returnAsList)
89-
// {
90-
// return result;
91-
// }
92-
// else
93-
// {
94-
// return result.ToArray();
95-
// }
96-
// }
97-
9836
private int GenerateCodePoint(int byteCount)
9937
{
10038
switch (byteCount)

0 commit comments

Comments
 (0)