Skip to content

Commit 186c55c

Browse files
committed
fix: failing tests on value range compiler
1 parent 536a5eb commit 186c55c

File tree

4 files changed

+79
-56
lines changed

4 files changed

+79
-56
lines changed

src/Ubiety.Stringprep.Core/ProhibitedValueStep.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public class ProhibitedValueStep(IValueRangeTable table) : IPreparationProcess
4646
/// <exception cref="ProhibitedValueException">Thrown when input is prohibited.</exception>
4747
public string Run(string input)
4848
{
49-
var item = input.Where(value => table.Contains(value)).FirstOrDefault();
50-
if (item != null)
49+
var item = input.FirstOrDefault(value => table.Contains(value));
50+
if (item != default(char))
5151
{
5252
throw new ProhibitedValueException(item);
5353
}

src/Ubiety.Stringprep.Core/ValueRangeCompiler.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,34 @@ private static List<int> DoInclude(List<int> list, IList<int> inclusions)
180180

181181
private static List<int> DoRemove(List<int> list, IList<int> removals)
182182
{
183+
/* for (var i = 0; i < removals.Count; i += 2)
184+
{
185+
var j = 0;
186+
while (j < list.Count)
187+
{
188+
if (removals[i] == list[j] || (removals[i] < list[j] && (i == 0 || removals[i] > list[j - 1])))
189+
{
190+
list.RemoveAt(j--);
191+
CloseRemove(list, removals, ref i, ref j);
192+
}
193+
else if (removals[i] > list[j] && removals[i] < list[j + 1])
194+
{
195+
list.Insert(++j, removals[i] - 1);
196+
CloseRemove(list, removals, ref i, ref j);
197+
}
198+
else
199+
{
200+
j += 2;
201+
}
202+
}
203+
}
204+
205+
return list; */
183206
for (var i = 0; i < removals.Count; i += 2)
184207
{
185-
var j = 0;
186-
while (j < list.Count)
208+
for (var j = 0; j < list.Count; j += 2)
187209
{
188-
if (removals[i] == list[j] || (removals[i] < list[j] && (i == 0 || removals[i] > list[j - 1])))
210+
if (removals[i] == list[j])
189211
{
190212
list.RemoveAt(j--);
191213
CloseRemove(list, removals, ref i, ref j);
@@ -195,9 +217,10 @@ private static List<int> DoRemove(List<int> list, IList<int> removals)
195217
list.Insert(++j, removals[i] - 1);
196218
CloseRemove(list, removals, ref i, ref j);
197219
}
198-
else
220+
else if (removals[i] < list[j] && (i == 0 || removals[i] > list[j - 1]))
199221
{
200-
j += 2;
222+
list.RemoveAt(j--);
223+
CloseRemove(list, removals, ref i, ref j);
201224
}
202225
}
203226
}

tests/Ubiety.Stringprep.Tests/Ubiety.Stringprep.Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
12+
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
1313
<PrivateAssets>all</PrivateAssets>
1414
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1515
</PackageReference>
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
17-
<PackageReference Include="Shouldly" Version="4.2.1" />
18-
<PackageReference Include="xunit" Version="2.8.1" />
19-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
17+
<PackageReference Include="Shouldly" Version="4.3.0" />
18+
<PackageReference Include="xunit" Version="2.9.3" />
19+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
2020
<PrivateAssets>all</PrivateAssets>
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
</PackageReference>

tests/Ubiety.Stringprep.Tests/ValueRangeCompilerTest.cs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,41 @@ public class ValueRangeCompilerTest
1111
[Fact]
1212
public void WillCompileSingleTable()
1313
{
14-
var a = new List<int> {1, 1};
15-
var result = ValueRangeCompiler.Compile(new[] {a}, new int[0], new int[0]);
14+
var a = new List<int> { 1, 1 };
15+
var result = ValueRangeCompiler.Compile(new[] { a }, new int[0], new int[0]);
1616

17-
result.ShouldBe(new[] {1, 1});
17+
result.ShouldBe(new[] { 1, 1 });
1818
}
1919

2020
[Fact]
2121
public void WillSortSingleTable()
2222
{
23-
var a = new List<int> {3, 7, 18, 22, 1, 1, 9, 13};
24-
var result = ValueRangeCompiler.Compile(new[] {a}, new int[0], new int[0]);
23+
var a = new List<int> { 3, 7, 18, 22, 1, 1, 9, 13 };
24+
var result = ValueRangeCompiler.Compile(new[] { a }, new int[0], new int[0]);
2525

26-
result.ShouldBe(new[] {1, 1, 3, 7, 9, 13, 18, 22});
26+
result.ShouldBe(new[] { 1, 1, 3, 7, 9, 13, 18, 22 });
2727
}
2828

2929
[Fact]
3030
public void WillCompileTwoTables()
3131
{
32-
var a = new List<int> {3, 7, 22, 25};
33-
var b = new List<int> {9, 15, 18, 20};
32+
var a = new List<int> { 3, 7, 22, 25 };
33+
var b = new List<int> { 9, 15, 18, 20 };
3434

35-
var result = ValueRangeCompiler.Compile(new[] {a, b}, new int[0], new int[0]);
36-
result.ShouldBe(new[] {3, 7, 9, 15, 18, 20, 22, 25});
35+
var result = ValueRangeCompiler.Compile(new[] { a, b }, new int[0], new int[0]);
36+
result.ShouldBe(new[] { 3, 7, 9, 15, 18, 20, 22, 25 });
3737
}
3838

3939
[Fact]
4040
public void WillCombineTablesOfDifferentLengths()
4141
{
42-
var a = new List<int> {1, 2};
43-
var b = new List<int> {75, 75, 42, 46, 13, 15};
44-
var c = new List<int> {33, 35, 77, 79};
45-
var d = new List<int> {4, 10, 99, 99, 101, 105, 303, 307};
42+
var a = new List<int> { 1, 2 };
43+
var b = new List<int> { 75, 75, 42, 46, 13, 15 };
44+
var c = new List<int> { 33, 35, 77, 79 };
45+
var d = new List<int> { 4, 10, 99, 99, 101, 105, 303, 307 };
4646

47-
var result = ValueRangeCompiler.Compile(new[] {a, b, c, d}, new int[0], new int[0]);
48-
result.ShouldBe(new[] {1, 2, 4, 10, 13, 15, 33, 35, 42, 46, 75, 75, 77, 79, 99, 99, 101, 105, 303, 307});
47+
var result = ValueRangeCompiler.Compile(new[] { a, b, c, d }, new int[0], new int[0]);
48+
result.ShouldBe(new[] { 1, 2, 4, 10, 13, 15, 33, 35, 42, 46, 75, 75, 77, 79, 99, 99, 101, 105, 303, 307 });
4949
}
5050

5151
[Fact]
@@ -59,9 +59,9 @@ public void WillReduceOverlappingValueRanges()
5959
15, 18
6060
};
6161

62-
var result = ValueRangeCompiler.Compile(new[] {a}, new int[0], new int[0]);
62+
var result = ValueRangeCompiler.Compile(new[] { a }, new int[0], new int[0]);
6363
result.ShouldBe(
64-
new[] {1, 12, 14, 18});
64+
new[] { 1, 12, 14, 18 });
6565
}
6666

6767
[Fact]
@@ -75,8 +75,8 @@ public void WillReduceInclusiveValueRanges()
7575
33, 75
7676
};
7777

78-
var result = ValueRangeCompiler.Compile(new[] {a}, new int[0], new int[0]);
79-
result.ShouldBe(new[] {1, 100});
78+
var result = ValueRangeCompiler.Compile(new[] { a }, new int[0], new int[0]);
79+
result.ShouldBe(new[] { 1, 100 });
8080
}
8181

8282
[Fact]
@@ -90,8 +90,8 @@ public void WillReduceAdjacentValueRanges()
9090
48, 50
9191
};
9292

93-
var result = ValueRangeCompiler.Compile(new[] {a}, new int[0], new int[0]);
94-
result.ShouldBe(new[] {1, 50});
93+
var result = ValueRangeCompiler.Compile(new[] { a }, new int[0], new int[0]);
94+
result.ShouldBe(new[] { 1, 50 });
9595
}
9696

9797
[Fact]
@@ -102,8 +102,8 @@ public void WillIncludeValueRangesAfterBaseTable()
102102
1, 5
103103
};
104104

105-
var result = ValueRangeCompiler.Compile(new[] {a}, new[] {10, 10}, new int[0]);
106-
result.ShouldBe(new[] {1, 5, 10, 10});
105+
var result = ValueRangeCompiler.Compile(new[] { a }, new[] { 10, 10 }, new int[0]);
106+
result.ShouldBe(new[] { 1, 5, 10, 10 });
107107
}
108108

109109
[Fact]
@@ -114,8 +114,8 @@ public void WillIncludeMultipleValueRangesAfterBaseTable()
114114
1, 5
115115
};
116116

117-
var result = ValueRangeCompiler.Compile(new[] {a}, new[] {10, 10, 15, 20}, new int[0]);
118-
result.ShouldBe(new[] {1, 5, 10, 10, 15, 20});
117+
var result = ValueRangeCompiler.Compile(new[] { a }, new[] { 10, 10, 15, 20 }, new int[0]);
118+
result.ShouldBe(new[] { 1, 5, 10, 10, 15, 20 });
119119
}
120120

121121
[Fact]
@@ -126,8 +126,8 @@ public void WillIncludeValueRangesBeforeBaseTable()
126126
15, 20
127127
};
128128

129-
var result = ValueRangeCompiler.Compile(new[] {a}, new[] {4, 7}, new int[0]);
130-
result.ShouldBe(new[] {4, 7, 15, 20});
129+
var result = ValueRangeCompiler.Compile(new[] { a }, new[] { 4, 7 }, new int[0]);
130+
result.ShouldBe(new[] { 4, 7, 15, 20 });
131131
}
132132

133133
[Fact]
@@ -138,8 +138,8 @@ public void WillIncludeMultipleValueRangesBeforeBaseTable()
138138
15, 20
139139
};
140140

141-
var result = ValueRangeCompiler.Compile(new[] {a}, new[] {1, 1, 4, 7}, new int[0]);
142-
result.ShouldBe(new[] {1, 1, 4, 7, 15, 20});
141+
var result = ValueRangeCompiler.Compile(new[] { a }, new[] { 1, 1, 4, 7 }, new int[0]);
142+
result.ShouldBe(new[] { 1, 1, 4, 7, 15, 20 });
143143
}
144144

145145
[Fact]
@@ -150,8 +150,8 @@ public void WillRemoveValueRangeEqualToStartValue()
150150
10, 20
151151
};
152152

153-
var result = ValueRangeCompiler.Compile(new[] {a}, new int[0], new[] {10, 15});
154-
result.ShouldBe(new[] {16, 20});
153+
var result = ValueRangeCompiler.Compile(new[] { a }, new int[0], new[] { 10, 15 });
154+
result.ShouldBe(new[] { 16, 20 });
155155
}
156156

157157
[Fact]
@@ -162,8 +162,8 @@ public void WillRemoveValueRangeEqualToEndValue()
162162
10, 20
163163
};
164164

165-
var result = ValueRangeCompiler.Compile(new[] {a}, new int[0], new[] {15, 20});
166-
result.ShouldBe(new[] {10, 14});
165+
var result = ValueRangeCompiler.Compile(new[] { a }, new int[0], new[] { 15, 20 });
166+
result.ShouldBe(new[] { 10, 14 });
167167
}
168168

169169
[Fact]
@@ -174,8 +174,8 @@ public void WillRemoveValueRangeOverlappingStartValue()
174174
10, 20
175175
};
176176

177-
var result = ValueRangeCompiler.Compile(new[] {a}, new int[0], new[] {5, 15});
178-
result.ShouldBe(new[] {16, 20});
177+
var result = ValueRangeCompiler.Compile(new[] { a }, new int[0], new[] { 5, 15 });
178+
result.ShouldBe(new[] { 16, 20 });
179179
}
180180

181181
[Fact]
@@ -187,8 +187,8 @@ public void WillRemoveValueRangeOverlappingStartValueOnLaterRanges()
187187
30, 40
188188
};
189189

190-
var result = ValueRangeCompiler.Compile(new[] {a}, new int[0], new[] {25, 35});
191-
result.ShouldBe(new[] {10, 20, 36, 40});
190+
var result = ValueRangeCompiler.Compile(new[] { a }, new int[0], new[] { 25, 35 });
191+
result.ShouldBe(new[] { 10, 20, 36, 40 });
192192
}
193193

194194
[Fact]
@@ -199,8 +199,8 @@ public void WillRemoveValueRangeOverlappingEndValue()
199199
10, 20
200200
};
201201

202-
var result = ValueRangeCompiler.Compile(new[] {a}, new int[0], new[] {15, 25});
203-
result.ShouldBe(new[] {10, 14});
202+
var result = ValueRangeCompiler.Compile(new[] { a }, new int[0], new[] { 15, 25 });
203+
result.ShouldBe(new[] { 10, 14 });
204204
}
205205

206206
[Fact]
@@ -212,8 +212,8 @@ public void WillRemoveValueRangeOverlappingEndValueOnEarlierRanges()
212212
30, 40
213213
};
214214

215-
var result = ValueRangeCompiler.Compile(new[] {a}, new int[0], new[] {15, 25});
216-
result.ShouldBe(new[] {10, 14, 30, 40});
215+
var result = ValueRangeCompiler.Compile(new[] { a }, new int[0], new[] { 15, 25 });
216+
result.ShouldBe(new[] { 10, 14, 30, 40 });
217217
}
218218

219219
[Fact]
@@ -224,7 +224,7 @@ public void ThrowsForInvalidRange()
224224
7, 5
225225
};
226226

227-
Should.Throw<ArgumentException>(() => { ValueRangeCompiler.Compile(new[] {a}, new int[0], new int[0]); });
227+
Should.Throw<ArgumentException>(() => { ValueRangeCompiler.Compile(new[] { a }, new int[0], new int[0]); });
228228
}
229229

230230
[Fact]
@@ -236,7 +236,7 @@ public void ThrowsForOddLengthArray()
236236
4
237237
};
238238

239-
Should.Throw<ArgumentException>(() => { ValueRangeCompiler.Compile(new[] {a}, new int[0], new int[0]); });
239+
Should.Throw<ArgumentException>(() => { ValueRangeCompiler.Compile(new[] { a }, new int[0], new int[0]); });
240240
}
241241
}
242242
}

0 commit comments

Comments
 (0)