コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
 public void Format_N(TextTestData <ushort> data) => RunQuoteTest(data, new UInt16JsonConverter('N'));
コード例 #4
0
 public void Number(TextTestData <double> data) => RunTest(data);
コード例 #5
0
 public void Format_X(TextTestData <byte> data) => RunQuoteTest(data, new ByteJsonConverter('X'));
コード例 #6
0
 public void Format_F(TextTestData <double> data) => RunQuoteTest(data, new DoubleJsonConverter('F'));
コード例 #7
0
 public void Array(TextTestData <int[]> data) => RunTest(data);
コード例 #8
0
 public void Format_X(TextTestData <uint> data) => RunQuoteTest(data, new UInt32JsonConverter('X'));
コード例 #9
0
 public void Format_D(TextTestData <ulong> data) => RunQuoteTest(data, new UInt53JsonConverter(), onlyReads: true);
コード例 #10
0
 public void Format_X(TextTestData <short> data) => RunQuoteTest(data, new Int16JsonConverter('X'));
コード例 #11
0
 public void Format_N(TextTestData <int> data) => RunQuoteTest(data, new Int32JsonConverter('N'));
コード例 #12
0
 public void Format_N(TextTestData <sbyte> data) => RunQuoteTest(data, new SByteJsonConverter('N'));
コード例 #13
0
 public void Number(TextTestData <short> data) => RunTest(data);
コード例 #14
0
 public void Format_D(TextTestData <long> data) => RunQuoteTest(data);
コード例 #15
0
 public void String(TextTestData <string> data) => RunQuoteTest(data);
コード例 #16
0
 public void Format_N(TextTestData <Guid> data) => RunQuoteTest(data, new GuidJsonConverter('N'));
コード例 #17
0
 public void Number(TextTestData <uint> data) => RunTest(data);
コード例 #18
0
 public void Test(TextTestData <int?> data) => RunTest(data);
コード例 #19
0
 public void Format_D(TextTestData <uint> data) => RunQuoteTest(data, onlyReads: true);
コード例 #20
0
 public void Boolean(TextTestData <bool> data) => RunTest(data);
コード例 #21
0
 public void Number(TextTestData <ulong> data) => RunTest(data, new UInt53JsonConverter());
コード例 #22
0
 public void Format_G(TextTestData <bool> data) => RunQuoteTest(data, new BooleanJsonConverter('G'));
コード例 #23
0
 public void Format_X(TextTestData <ulong> data) => RunQuoteTest(data, new UInt53JsonConverter('X'));
コード例 #24
0
 public void Format_LittleG(TextTestData <double> data) => RunQuoteTest(data, onlyReads: true);
コード例 #25
0
 public void Format_LittleL(TextTestData <bool> data) => RunQuoteTest(data, onlyReads: true);
コード例 #26
0
 public void Format_N(TextTestData <ulong> data) => RunQuoteTest(data, new UInt64JsonConverter('N'));
コード例 #27
0
 public void Array(TextTestData <List <int> > data) => RunTest(data);
コード例 #28
0
 public void Number(TextTestData <byte> data) => RunTest(data);
コード例 #29
0
 public void Object(TextTestData <Dictionary <string, int> > data) => RunTest(data);
コード例 #30
0
 public void Format_LittleE(TextTestData <float> data) => RunQuoteTest(data, new SingleJsonConverter('e'));