OLD | NEW |
1 #region Copyright notice and license | 1 #region Copyright notice and license |
2 // Protocol Buffers - Google's data interchange format | 2 // Protocol Buffers - Google's data interchange format |
3 // Copyright 2008 Google Inc. All rights reserved. | 3 // Copyright 2008 Google Inc. All rights reserved. |
4 // https://developers.google.com/protocol-buffers/ | 4 // https://developers.google.com/protocol-buffers/ |
5 // | 5 // |
6 // Redistribution and use in source and binary forms, with or without | 6 // Redistribution and use in source and binary forms, with or without |
7 // modification, are permitted provided that the following conditions are | 7 // modification, are permitted provided that the following conditions are |
8 // met: | 8 // met: |
9 // | 9 // |
10 // * Redistributions of source code must retain the above copyright | 10 // * Redistributions of source code must retain the above copyright |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 { | 126 { |
127 // When we parse the "valueField": null part, we remember it... basi
cally, it's one case | 127 // When we parse the "valueField": null part, we remember it... basi
cally, it's one case |
128 // where explicit default values don't fully roundtrip. | 128 // where explicit default values don't fully roundtrip. |
129 var message = new TestWellKnownTypes { ValueField = Value.ForNull()
}; | 129 var message = new TestWellKnownTypes { ValueField = Value.ForNull()
}; |
130 var json = new JsonFormatter(new JsonFormatter.Settings(true)).Forma
t(message); | 130 var json = new JsonFormatter(new JsonFormatter.Settings(true)).Forma
t(message); |
131 var parsed = JsonParser.Default.Parse<TestWellKnownTypes>(json); | 131 var parsed = JsonParser.Default.Parse<TestWellKnownTypes>(json); |
132 Assert.AreEqual(message, parsed); | 132 Assert.AreEqual(message, parsed); |
133 } | 133 } |
134 | 134 |
135 [Test] | 135 [Test] |
136 [TestCase(typeof(BoolValue), "true", true)] | |
137 [TestCase(typeof(Int32Value), "32", 32)] | 136 [TestCase(typeof(Int32Value), "32", 32)] |
138 [TestCase(typeof(Int64Value), "32", 32L)] | 137 [TestCase(typeof(Int64Value), "32", 32L)] |
139 [TestCase(typeof(Int64Value), "\"32\"", 32L)] | |
140 [TestCase(typeof(UInt32Value), "32", 32U)] | 138 [TestCase(typeof(UInt32Value), "32", 32U)] |
141 [TestCase(typeof(UInt64Value), "\"32\"", 32UL)] | |
142 [TestCase(typeof(UInt64Value), "32", 32UL)] | 139 [TestCase(typeof(UInt64Value), "32", 32UL)] |
143 [TestCase(typeof(StringValue), "\"foo\"", "foo")] | 140 [TestCase(typeof(StringValue), "\"foo\"", "foo")] |
144 [TestCase(typeof(FloatValue), "1.5", 1.5f)] | 141 [TestCase(typeof(FloatValue), "1.5", 1.5f)] |
145 [TestCase(typeof(DoubleValue), "1.5", 1.5d)] | 142 [TestCase(typeof(DoubleValue), "1.5", 1.5d)] |
146 public void Wrappers_Standalone(System.Type wrapperType, string json, ob
ject expectedValue) | 143 public void Wrappers_Standalone(System.Type wrapperType, string json, ob
ject expectedValue) |
147 { | 144 { |
148 IMessage parsed = (IMessage)Activator.CreateInstance(wrapperType); | 145 IMessage parsed = (IMessage)Activator.CreateInstance(wrapperType); |
149 IMessage expected = (IMessage)Activator.CreateInstance(wrapperType); | 146 IMessage expected = (IMessage)Activator.CreateInstance(wrapperType); |
150 JsonParser.Default.Merge(parsed, "null"); | 147 JsonParser.Default.Merge(parsed, "null"); |
151 Assert.AreEqual(expected, parsed); | 148 Assert.AreEqual(expected, parsed); |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 /// Various tests use strings which have quotes round them for parsing o
r as the result | 927 /// Various tests use strings which have quotes round them for parsing o
r as the result |
931 /// of formatting, but without those quotes being specified in the tests
(for the sake of readability). | 928 /// of formatting, but without those quotes being specified in the tests
(for the sake of readability). |
932 /// This method simply returns the input, wrapped in double quotes. | 929 /// This method simply returns the input, wrapped in double quotes. |
933 /// </summary> | 930 /// </summary> |
934 internal static string WrapInQuotes(string text) | 931 internal static string WrapInQuotes(string text) |
935 { | 932 { |
936 return '"' + text + '"'; | 933 return '"' + text + '"'; |
937 } | 934 } |
938 } | 935 } |
939 } | 936 } |
OLD | NEW |