You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2026/06/24 05:00:27 UTC
(lucenenet) branch master updated: Added `SpanTools.ValueStringBuilder.Generator` Reference (#1390)
This is an automated email from the ASF dual-hosted git repository.
NightOwl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
The following commit(s) were added to refs/heads/master by this push:
new d7af24e84 Added `SpanTools.ValueStringBuilder.Generator` Reference (#1390)
d7af24e84 is described below
commit d7af24e8427e35c2fb911f044b3884c5eb5f15fb
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Wed Jun 24 12:00:22 2026 +0700
Added `SpanTools.ValueStringBuilder.Generator` Reference (#1390)
---
.build/dependencies.props | 1 +
.../Support/Text/TestValueStringBuilder.cs | 108 +++++++++++++++++++++
src/Lucene.Net/Lucene.Net.csproj | 10 +-
3 files changed, 118 insertions(+), 1 deletion(-)
diff --git a/.build/dependencies.props b/.build/dependencies.props
index 74728c75e..44bddbbd1 100644
--- a/.build/dependencies.props
+++ b/.build/dependencies.props
@@ -70,6 +70,7 @@
<NUnitPackageVersion>3.14.0</NUnitPackageVersion>
<RandomizedTestingGeneratorsPackageVersion>2.7.8</RandomizedTestingGeneratorsPackageVersion>
<SharpZipLibPackageVersion>1.4.2</SharpZipLibPackageVersion>
+ <SpanToolsValueStringBuilderGeneratorPackageVersion>1.0.0-alpha.113</SpanToolsValueStringBuilderGeneratorPackageVersion>
<Spatial4nPackageVersion>0.4.1.1</Spatial4nPackageVersion>
<SystemMemoryPackageVersion>4.6.3</SystemMemoryPackageVersion>
<SystemNetHttpPackageVersion>4.3.4</SystemNetHttpPackageVersion>
diff --git a/src/Lucene.Net.Tests/Support/Text/TestValueStringBuilder.cs b/src/Lucene.Net.Tests/Support/Text/TestValueStringBuilder.cs
new file mode 100644
index 000000000..b3aa12780
--- /dev/null
+++ b/src/Lucene.Net.Tests/Support/Text/TestValueStringBuilder.cs
@@ -0,0 +1,108 @@
+using J2N.Globalization;
+using Lucene.Net.Attributes;
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System;
+using Assert = Lucene.Net.TestFramework.Assert;
+
+namespace Lucene.Net.Text
+{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /// <summary>
+ /// Smoke tests for <see cref="ValueStringBuilder"/> to ensure it has been generated with
+ /// the configured values. More thorough tests are performed in SpanTools
+ /// <a href="https://www.nuget.org/packages/SpanTools.ValueStringBuilder.Generator">
+ /// https://www.nuget.org/packages/SpanTools.ValueStringBuilder.Generator</a>
+ /// </summary>
+ [TestFixture, LuceneNetSpecific]
+ public class TestValueStringBuilder : LuceneTestCase
+ {
+ [Test]
+ public void TestJavaStyleLastIndexOf()
+ {
+ using ValueStringBuilder sb = new(stackalloc char[8]);
+ sb.Append("aaaaa");
+ Assert.AreEqual(2, sb.LastIndexOf("aa", 2));
+ }
+
+ [Test]
+ public void TestJavaStyleFormatting()
+ {
+ using CultureContext context = new("pt");
+ using ValueStringBuilder sb = new(stackalloc char[8]);
+ sb.Append(123d);
+ Assert.AreEqual("123.0", sb.ToString());
+ }
+
+ // Tests MaxLength tracking
+ [Test]
+ public void TestFitsIntialBuffer_BeyondInitialBuffer_ReturnsMaxLength()
+ {
+ using ValueStringBuilder sb = new(stackalloc char[8]);
+ sb.Append("Hello");
+ sb.Append("World");
+ Assert.IsFalse(sb.FitsInitialBuffer(out int charsLength));
+ Assert.AreEqual(10, charsLength);
+ }
+
+ [Test]
+ public void TestFitsIntialBuffer_WithinInitialBuffer_ReturnsLength()
+ {
+ using ValueStringBuilder sb = new(stackalloc char[8]);
+ sb.Append("Hello");
+ sb.Append("W");
+ Assert.IsTrue(sb.FitsInitialBuffer(out int charsLength));
+ Assert.AreEqual(6, charsLength);
+ Assert.AreEqual(6, sb.Length);
+ }
+
+ [Test]
+ public void TestAsMemory()
+ {
+ using ValueStringBuilder sb = new(8);
+ sb.Append("Hello");
+ ReadOnlyMemory<char> memory = sb.AsMemory();
+ sb.Append("World");
+ Assert.AreNotEqual("HelloWorld", memory.Span.ToString()); // This is guaranteed not to be the same memory as otherMemory
+ ReadOnlyMemory<char> otherMemory = sb.AsMemory();
+ Assert.AreEqual("HelloWorld", otherMemory.Span.ToString());
+ }
+
+ [Test]
+ public void TestPreload()
+ {
+ Span<char> destination = stackalloc char[10];
+ "Hello".AsSpan().CopyTo(destination);
+ ValueStringBuilder sb = new(destination);
+ try
+ {
+ sb.Length = 5; // "Consume" the preloaded value
+ sb.Append("World");
+ Assert.AreEqual("HelloWorld", sb.ToString());
+ Assert.IsTrue(sb.FitsInitialBuffer(out int charsLength));
+ Assert.AreEqual(10, charsLength);
+ Assert.AreEqual(10, sb.Length);
+ }
+ finally
+ {
+ sb.Dispose(); // Technically not required; best practice to call this
+ }
+ }
+ }
+}
diff --git a/src/Lucene.Net/Lucene.Net.csproj b/src/Lucene.Net/Lucene.Net.csproj
index 0a9fee95f..07b845a4f 100644
--- a/src/Lucene.Net/Lucene.Net.csproj
+++ b/src/Lucene.Net/Lucene.Net.csproj
@@ -36,7 +36,14 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
-
+ <PropertyGroup Label="SpanTools.ValueStringBuilder.Generator Settings">
+ <ValueStringBuilder_Namespace>Lucene.Net.Text</ValueStringBuilder_Namespace>
+ <ValueStringBuilder_IncludeMaxLengthTracking>true</ValueStringBuilder_IncludeMaxLengthTracking>
+ <ValueStringBuilder_IncludeAsMemoryMethods>true</ValueStringBuilder_IncludeAsMemoryMethods>
+ <ValueStringBuilder_IncludeCodepointSupport>true</ValueStringBuilder_IncludeCodepointSupport>
+ <ValueStringBuilder_UseJavaStyleFormatting>true</ValueStringBuilder_UseJavaStyleFormatting>
+ <ValueStringBuilder_UseJavaStyleIndexOf>true</ValueStringBuilder_UseJavaStyleIndexOf>
+ </PropertyGroup>
<PropertyGroup Label="NuGet Package File Paths">
<LuceneNetDotNetDir>$(SolutionDir)src\dotnet\</LuceneNetDotNetDir>
@@ -56,6 +63,7 @@
<ItemGroup>
<PackageReference Include="J2N" Version="$(J2NPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="$(MicrosoftExtensionsConfigurationAbstractionsPackageVersion)" />
+ <PackageReference Include="SpanTools.ValueStringBuilder.Generator" Version="$(SpanToolsValueStringBuilderGeneratorPackageVersion)" PrivateAssets="all" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">