| 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 2015 Google Inc. All rights reserved. | 3 // Copyright 2015 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 public void Add_Sequence() | 68 public void Add_Sequence() |
| 69 { | 69 { |
| 70 var list = new RepeatedField<string>(); | 70 var list = new RepeatedField<string>(); |
| 71 list.Add(new[] { "foo", "bar" }); | 71 list.Add(new[] { "foo", "bar" }); |
| 72 Assert.AreEqual(2, list.Count); | 72 Assert.AreEqual(2, list.Count); |
| 73 Assert.AreEqual("foo", list[0]); | 73 Assert.AreEqual("foo", list[0]); |
| 74 Assert.AreEqual("bar", list[1]); | 74 Assert.AreEqual("bar", list[1]); |
| 75 } | 75 } |
| 76 | 76 |
| 77 [Test] | 77 [Test] |
| 78 public void Add_RepeatedField() | 78 public void AddRange_SlowPath() |
| 79 { |
| 80 var list = new RepeatedField<string>(); |
| 81 list.AddRange(new[] { "foo", "bar" }.Select(x => x)); |
| 82 Assert.AreEqual(2, list.Count); |
| 83 Assert.AreEqual("foo", list[0]); |
| 84 Assert.AreEqual("bar", list[1]); |
| 85 } |
| 86 |
| 87 [Test] |
| 88 public void AddRange_SlowPath_NullsProhibited_ReferenceType() |
| 89 { |
| 90 var list = new RepeatedField<string>(); |
| 91 // It's okay for this to throw ArgumentNullException if necessary. |
| 92 // It's not ideal, but not awful. |
| 93 Assert.Catch<ArgumentException>(() => list.AddRange(new[] { "foo", n
ull }.Select(x => x))); |
| 94 } |
| 95 |
| 96 [Test] |
| 97 public void AddRange_SlowPath_NullsProhibited_NullableValueType() |
| 98 { |
| 99 var list = new RepeatedField<int?>(); |
| 100 // It's okay for this to throw ArgumentNullException if necessary. |
| 101 // It's not ideal, but not awful. |
| 102 Assert.Catch<ArgumentException>(() => list.AddRange(new[] { 20, (int
?)null }.Select(x => x))); |
| 103 } |
| 104 |
| 105 [Test] |
| 106 public void AddRange_Optimized_NonNullableValueType() |
| 107 { |
| 108 var list = new RepeatedField<int>(); |
| 109 list.AddRange(new List<int> { 20, 30 }); |
| 110 Assert.AreEqual(2, list.Count); |
| 111 Assert.AreEqual(20, list[0]); |
| 112 Assert.AreEqual(30, list[1]); |
| 113 } |
| 114 |
| 115 [Test] |
| 116 public void AddRange_Optimized_ReferenceType() |
| 117 { |
| 118 var list = new RepeatedField<string>(); |
| 119 list.AddRange(new List<string> { "foo", "bar" }); |
| 120 Assert.AreEqual(2, list.Count); |
| 121 Assert.AreEqual("foo", list[0]); |
| 122 Assert.AreEqual("bar", list[1]); |
| 123 } |
| 124 |
| 125 [Test] |
| 126 public void AddRange_Optimized_NullableValueType() |
| 127 { |
| 128 var list = new RepeatedField<int?>(); |
| 129 list.AddRange(new List<int?> { 20, 30 }); |
| 130 Assert.AreEqual(2, list.Count); |
| 131 Assert.AreEqual((int?) 20, list[0]); |
| 132 Assert.AreEqual((int?) 30, list[1]); |
| 133 } |
| 134 |
| 135 [Test] |
| 136 public void AddRange_Optimized_NullsProhibited_ReferenceType() |
| 137 { |
| 138 // We don't just trust that a collection with a nullable element typ
e doesn't contain nulls |
| 139 var list = new RepeatedField<string>(); |
| 140 // It's okay for this to throw ArgumentNullException if necessary. |
| 141 // It's not ideal, but not awful. |
| 142 Assert.Catch<ArgumentException>(() => list.AddRange(new List<string>
{ "foo", null })); |
| 143 } |
| 144 |
| 145 [Test] |
| 146 public void AddRange_Optimized_NullsProhibited_NullableValueType() |
| 147 { |
| 148 // We don't just trust that a collection with a nullable element typ
e doesn't contain nulls |
| 149 var list = new RepeatedField<int?>(); |
| 150 // It's okay for this to throw ArgumentNullException if necessary. |
| 151 // It's not ideal, but not awful. |
| 152 Assert.Catch<ArgumentException>(() => list.AddRange(new List<int?> {
20, null })); |
| 153 } |
| 154 |
| 155 [Test] |
| 156 public void AddRange_AlreadyNotEmpty() |
| 157 { |
| 158 var list = new RepeatedField<int> { 1, 2, 3 }; |
| 159 list.AddRange(new List<int> { 4, 5, 6 }); |
| 160 CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5, 6 }, list); |
| 161 } |
| 162 |
| 163 [Test] |
| 164 public void AddRange_RepeatedField() |
| 79 { | 165 { |
| 80 var list = new RepeatedField<string> { "original" }; | 166 var list = new RepeatedField<string> { "original" }; |
| 81 list.Add(new RepeatedField<string> { "foo", "bar" }); | 167 list.AddRange(new RepeatedField<string> { "foo", "bar" }); |
| 82 Assert.AreEqual(3, list.Count); | 168 Assert.AreEqual(3, list.Count); |
| 83 Assert.AreEqual("original", list[0]); | 169 Assert.AreEqual("original", list[0]); |
| 84 Assert.AreEqual("foo", list[1]); | 170 Assert.AreEqual("foo", list[1]); |
| 85 Assert.AreEqual("bar", list[2]); | 171 Assert.AreEqual("bar", list[2]); |
| 86 } | 172 } |
| 87 | 173 |
| 88 [Test] | 174 [Test] |
| 89 public void RemoveAt_Valid() | 175 public void RemoveAt_Valid() |
| 90 { | 176 { |
| 91 var list = new RepeatedField<string> { "first", "second", "third" }; | 177 var list = new RepeatedField<string> { "first", "second", "third" }; |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 [Test] | 737 [Test] |
| 652 public void ToString_Struct() | 738 public void ToString_Struct() |
| 653 { | 739 { |
| 654 var message = new Struct { Fields = { { "foo", new Value { NumberVal
ue = 20 } } } }; | 740 var message = new Struct { Fields = { { "foo", new Value { NumberVal
ue = 20 } } } }; |
| 655 var list = new RepeatedField<Struct> { message }; | 741 var list = new RepeatedField<Struct> { message }; |
| 656 var text = list.ToString(); | 742 var text = list.ToString(); |
| 657 Assert.AreEqual(text, "[ { \"foo\": 20 } ]", message.ToString()); | 743 Assert.AreEqual(text, "[ { \"foo\": 20 } ]", message.ToString()); |
| 658 } | 744 } |
| 659 } | 745 } |
| 660 } | 746 } |
| OLD | NEW |