Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed test for Utf8JsonReaderExtensions #414

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

using System.Text.Json;

namespace MorganStanley.ComposeUI.Messaging.Protocol.Json;

internal static class ThrowHelper
{
public static InvalidOperationException StringExpected() => new InvalidOperationException("String expected");
public static InvalidOperationException StringExpected(JsonTokenType actualTokenType) => new InvalidOperationException($"String expected (actual: {actualTokenType})");

public static ArgumentException DestinationTooShort(string paramName) =>
new ArgumentException("The destination buffer is too short", paramName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static int CopyString(this ref Utf8JsonReader reader, Span<byte> utf8Dest
{
if (reader.TokenType is not (JsonTokenType.String or JsonTokenType.PropertyName))
{
throw ThrowHelper.StringExpected();
throw ThrowHelper.StringExpected(reader.TokenType);
}

var valueLength = reader.HasValueSequence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace MorganStanley.ComposeUI.Messaging.Protocol.Json;

public class Utf8JsonReaderExtensionsTests
{
[Theory(Skip ="ci fail")]
[Theory]
[ClassData(typeof(CopyStringTheoryData))]
public void CopyString_writes_the_unescaped_UTF8_string_to_the_buffer(CopyStringTestData testData)
{
Expand Down Expand Up @@ -55,10 +55,10 @@ public Utf8JsonReader CreateReader()
reader = new Utf8JsonReader(MemoryHelper.CreateMultipartSequence(_utf8Buffers));
}

Debug.Assert(reader.Read());
Debug.Assert(reader.TokenType == JsonTokenType.StartArray);
Debug.Assert(reader.Read());
Debug.Assert(reader.TokenType == JsonTokenType.String);
reader.Read().Should().Be(true);
reader.TokenType.Should().Be(JsonTokenType.StartArray);
reader.Read().Should().Be(true);
reader.TokenType.Should().Be(JsonTokenType.String);

return reader;
}
Expand Down
Loading