protected void RunTest(TextTestData <T> test, ValueConverter <T> converter = null) { switch (test.Type) { case TestType.FailRead: Assert.Throws <SerializationException>(() => _serializer.ReadUtf16 <T>(test.String, converter)); Assert.Throws <SerializationException>(() => _serializer.ReadUtf16 <T>(' ' + test.String + ' ', converter)); break; case TestType.FailWrite: Assert.Throws <SerializationException>(() => _serializer.WriteUtf16String(test.Value, converter)); break; case TestType.Read: Assert.Equal(test.Value, _serializer.ReadUtf16 <T>(test.String, converter), _comparer); Assert.True(TestSkip(test.String)); Assert.Equal(test.Value, _serializer.ReadUtf16 <T>(' ' + test.String, converter), _comparer); Assert.True(TestSkip(' ' + test.String)); Assert.Equal(test.Value, _serializer.ReadUtf16 <T>(test.String + ' ', converter), _comparer); Assert.True(TestSkip(test.String + ' ')); Assert.Equal(test.Value, _serializer.ReadUtf16 <T>(' ' + test.String + ' ', converter), _comparer); Assert.True(TestSkip(' ' + test.String + ' ')); break; case TestType.Write: Assert.Equal(test.String, _serializer.WriteUtf16String(test.Value, converter)); Assert.True(TestSkip(test.String)); break; case TestType.ReadWrite: Assert.Equal(test.Value, _serializer.ReadUtf16 <T>(test.String, converter), _comparer); Assert.True(TestSkip(test.String)); Assert.Equal(test.Value, _serializer.ReadUtf16 <T>(' ' + test.String, converter), _comparer); Assert.True(TestSkip(' ' + test.String)); Assert.Equal(test.Value, _serializer.ReadUtf16 <T>(test.String + ' ', converter), _comparer); Assert.True(TestSkip(test.String + ' ')); Assert.Equal(test.Value, _serializer.ReadUtf16 <T>(' ' + test.String + ' ', converter), _comparer); Assert.True(TestSkip(' ' + test.String + ' ')); Assert.Equal(test.String, _serializer.WriteUtf16String(test.Value, converter)); break; } }
protected void RunQuoteTest(TextTestData <T> test, ValueConverter <T> converter = null, bool onlyReads = false) { switch (test.Type) { case TestType.FailRead: Assert.Throws <SerializationException>(() => _serializer.ReadUtf16 <T>('"' + test.String + '"', converter)); break; case TestType.FailWrite: Assert.Throws <SerializationException>(() => _serializer.WriteUtf16String(test.Value, converter)); break; case TestType.Read: Assert.Equal(test.Value, _serializer.ReadUtf16 <T>('"' + test.String + '"', converter), _comparer); Assert.True(TestSkip('"' + test.String + '"')); Assert.Equal(test.Value, _serializer.ReadUtf16 <T>(" \"" + test.String + "\" ", converter), _comparer); Assert.True(TestSkip(" \"" + test.String + "\" ")); Assert.Throws <SerializationException>(() => _serializer.ReadUtf16 <T>('"' + test.String, converter)); // Unclosed quote Assert.Throws <SerializationException>(() => _serializer.ReadUtf16 <T>(" \"" + test.String + ' ', converter)); // Unclosed quote break; case TestType.ReadWrite: Assert.Equal(test.Value, _serializer.ReadUtf16 <T>('"' + test.String + '"', converter), _comparer); Assert.True(TestSkip('"' + test.String + '"')); Assert.Equal(test.Value, _serializer.ReadUtf16 <T>(" \"" + test.String + "\" ", converter), _comparer); Assert.True(TestSkip(" \"" + test.String + "\" ")); Assert.Throws <SerializationException>(() => _serializer.ReadUtf16 <T>('"' + test.String, converter)); // Unclosed quote Assert.Throws <SerializationException>(() => _serializer.ReadUtf16 <T>(" \"" + test.String + ' ', converter)); // Unclosed quote if (!onlyReads) { Assert.Equal('"' + test.String + '"', _serializer.WriteUtf16String(test.Value, converter)); } break; case TestType.Write: if (!onlyReads) { Assert.Equal('"' + test.String + '"', _serializer.WriteUtf16String(test.Value, converter)); } break; } }
public void Format_N(TextTestData <ushort> data) => RunQuoteTest(data, new UInt16JsonConverter('N'));
public void Number(TextTestData <double> data) => RunTest(data);
public void Format_X(TextTestData <byte> data) => RunQuoteTest(data, new ByteJsonConverter('X'));
public void Format_F(TextTestData <double> data) => RunQuoteTest(data, new DoubleJsonConverter('F'));
public void Array(TextTestData <int[]> data) => RunTest(data);
public void Format_X(TextTestData <uint> data) => RunQuoteTest(data, new UInt32JsonConverter('X'));
public void Format_D(TextTestData <ulong> data) => RunQuoteTest(data, new UInt53JsonConverter(), onlyReads: true);
public void Format_X(TextTestData <short> data) => RunQuoteTest(data, new Int16JsonConverter('X'));
public void Format_N(TextTestData <int> data) => RunQuoteTest(data, new Int32JsonConverter('N'));
public void Format_N(TextTestData <sbyte> data) => RunQuoteTest(data, new SByteJsonConverter('N'));
public void Number(TextTestData <short> data) => RunTest(data);
public void Format_D(TextTestData <long> data) => RunQuoteTest(data);
public void String(TextTestData <string> data) => RunQuoteTest(data);
public void Format_N(TextTestData <Guid> data) => RunQuoteTest(data, new GuidJsonConverter('N'));
public void Number(TextTestData <uint> data) => RunTest(data);
public void Test(TextTestData <int?> data) => RunTest(data);
public void Format_D(TextTestData <uint> data) => RunQuoteTest(data, onlyReads: true);
public void Boolean(TextTestData <bool> data) => RunTest(data);
public void Number(TextTestData <ulong> data) => RunTest(data, new UInt53JsonConverter());
public void Format_G(TextTestData <bool> data) => RunQuoteTest(data, new BooleanJsonConverter('G'));
public void Format_X(TextTestData <ulong> data) => RunQuoteTest(data, new UInt53JsonConverter('X'));
public void Format_LittleG(TextTestData <double> data) => RunQuoteTest(data, onlyReads: true);
public void Format_LittleL(TextTestData <bool> data) => RunQuoteTest(data, onlyReads: true);
public void Format_N(TextTestData <ulong> data) => RunQuoteTest(data, new UInt64JsonConverter('N'));
public void Array(TextTestData <List <int> > data) => RunTest(data);
public void Number(TextTestData <byte> data) => RunTest(data);
public void Object(TextTestData <Dictionary <string, int> > data) => RunTest(data);
public void Format_LittleE(TextTestData <float> data) => RunQuoteTest(data, new SingleJsonConverter('e'));