strip IndefiniteLength suffix from write methods
authorEirik Tsarpalis <eirik.tsarpalis@gmail.com>
Tue, 28 Apr 2020 21:26:39 +0000 (22:26 +0100)
committerEirik Tsarpalis <eirik.tsarpalis@gmail.com>
Wed, 29 Apr 2020 14:30:13 +0000 (15:30 +0100)
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor.Tests/CborWriterTests.Helpers.cs
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor.Tests/CborWriterTests.Map.cs
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor.Tests/CborWriterTests.String.cs
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor.Tests/CborWriterTests.Tag.cs
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor.Tests/CborWriterTests.cs
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor/CborWriter.Array.cs
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor/CborWriter.Map.cs
src/libraries/System.Security.Cryptography.Encoding/tests/Cbor/CborWriter.String.cs

index 337756a..039ff0a 100644 (file)
@@ -92,7 +92,7 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
                 }
                 else
                 {
-                    writer.WriteStartArrayIndefiniteLength();
+                    writer.WriteStartArray();
                 }
 
                 foreach (object value in values)
@@ -116,7 +116,7 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
                 }
                 else
                 {
-                    writer.WriteStartMapIndefiniteLength();
+                    writer.WriteStartMap();
                 }
 
                 foreach (object value in keyValuePairs.Skip(1))
@@ -129,22 +129,22 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
 
             public static void WriteChunkedByteString(CborWriter writer, byte[][] chunks)
             {
-                writer.WriteStartByteStringIndefiniteLength();
+                writer.WriteStartByteString();
                 foreach (byte[] chunk in chunks)
                 {
                     writer.WriteByteString(chunk);
                 }
-                writer.WriteEndByteStringIndefiniteLength();
+                writer.WriteEndByteString();
             }
 
             public static void WriteChunkedTextString(CborWriter writer, string[] chunks)
             {
-                writer.WriteStartTextStringIndefiniteLength();
+                writer.WriteStartTextString();
                 foreach (string chunk in chunks)
                 {
                     writer.WriteTextString(chunk);
                 }
-                writer.WriteEndTextStringIndefiniteLength();
+                writer.WriteEndTextString();
             }
 
             public static void ExecOperation(CborWriter writer, string op)
@@ -154,12 +154,12 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
                     case nameof(writer.WriteInt64): writer.WriteInt64(42); break;
                     case nameof(writer.WriteByteString): writer.WriteByteString(Array.Empty<byte>()); break;
                     case nameof(writer.WriteTextString): writer.WriteTextString(""); break;
-                    case nameof(writer.WriteStartTextStringIndefiniteLength): writer.WriteStartTextStringIndefiniteLength(); break;
-                    case nameof(writer.WriteStartByteStringIndefiniteLength): writer.WriteStartByteStringIndefiniteLength(); break;
-                    case nameof(writer.WriteStartArray): writer.WriteStartArrayIndefiniteLength(); break;
-                    case nameof(writer.WriteStartMap): writer.WriteStartMapIndefiniteLength(); break;
-                    case nameof(writer.WriteEndByteStringIndefiniteLength): writer.WriteEndByteStringIndefiniteLength(); break;
-                    case nameof(writer.WriteEndTextStringIndefiniteLength): writer.WriteEndTextStringIndefiniteLength(); break;
+                    case nameof(writer.WriteStartTextString): writer.WriteStartTextString(); break;
+                    case nameof(writer.WriteStartByteString): writer.WriteStartByteString(); break;
+                    case nameof(writer.WriteStartArray): writer.WriteStartArray(); break;
+                    case nameof(writer.WriteStartMap): writer.WriteStartMap(); break;
+                    case nameof(writer.WriteEndByteString): writer.WriteEndByteString(); break;
+                    case nameof(writer.WriteEndTextString): writer.WriteEndTextString(); break;
                     case nameof(writer.WriteEndArray): writer.WriteEndArray(); break;
                     case nameof(writer.WriteEndMap): writer.WriteEndMap(); break;
                     default: throw new Exception($"Unrecognized CborWriter operation name {op}");
index e5590a4..b188c40 100644 (file)
@@ -321,7 +321,7 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
         public static void EndWriteMap_IndefiniteLength_OddItems_ShouldThrowInvalidOperationException(int length)
         {
             using var writer = new CborWriter();
-            writer.WriteStartMapIndefiniteLength();
+            writer.WriteStartMap();
 
             for (int i = 1; i < length; i++)
             {
index 37d8cd0..9344920 100644 (file)
@@ -113,53 +113,53 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
         [Theory]
         [InlineData(nameof(CborWriter.WriteInt64))]
         [InlineData(nameof(CborWriter.WriteByteString))]
-        [InlineData(nameof(CborWriter.WriteStartTextStringIndefiniteLength))]
-        [InlineData(nameof(CborWriter.WriteStartByteStringIndefiniteLength))]
+        [InlineData(nameof(CborWriter.WriteStartTextString))]
+        [InlineData(nameof(CborWriter.WriteStartByteString))]
         [InlineData(nameof(CborWriter.WriteStartArray))]
         [InlineData(nameof(CborWriter.WriteStartMap))]
         public static void WriteTextString_IndefiniteLength_NestedWrites_ShouldThrowInvalidOperationException(string opName)
         {
             using var writer = new CborWriter();
-            writer.WriteStartTextStringIndefiniteLength();
+            writer.WriteStartTextString();
             Assert.Throws<InvalidOperationException>(() => Helpers.ExecOperation(writer, opName));
         }
 
         [Theory]
-        [InlineData(nameof(CborWriter.WriteEndByteStringIndefiniteLength))]
+        [InlineData(nameof(CborWriter.WriteEndByteString))]
         [InlineData(nameof(CborWriter.WriteEndArray))]
         [InlineData(nameof(CborWriter.WriteEndMap))]
         public static void WriteTextString_IndefiniteLength_ImbalancedWrites_ShouldThrowInvalidOperationException(string opName)
         {
             using var writer = new CborWriter();
-            writer.WriteStartTextStringIndefiniteLength();
+            writer.WriteStartTextString();
             Assert.Throws<InvalidOperationException>(() => Helpers.ExecOperation(writer, opName));
         }
 
         [Theory]
         [InlineData(nameof(CborWriter.WriteInt64))]
         [InlineData(nameof(CborWriter.WriteTextString))]
-        [InlineData(nameof(CborWriter.WriteStartTextStringIndefiniteLength))]
-        [InlineData(nameof(CborWriter.WriteStartByteStringIndefiniteLength))]
+        [InlineData(nameof(CborWriter.WriteStartTextString))]
+        [InlineData(nameof(CborWriter.WriteStartByteString))]
         [InlineData(nameof(CborWriter.WriteStartArray))]
         [InlineData(nameof(CborWriter.WriteStartMap))]
-        [InlineData(nameof(CborWriter.WriteEndTextStringIndefiniteLength))]
+        [InlineData(nameof(CborWriter.WriteEndTextString))]
         [InlineData(nameof(CborWriter.WriteEndArray))]
         [InlineData(nameof(CborWriter.WriteEndMap))]
         public static void WriteByteString_IndefiniteLength_NestedWrites_ShouldThrowInvalidOperationException(string opName)
         {
             using var writer = new CborWriter();
-            writer.WriteStartByteStringIndefiniteLength();
+            writer.WriteStartByteString();
             Assert.Throws<InvalidOperationException>(() => Helpers.ExecOperation(writer, opName));
         }
 
         [Theory]
-        [InlineData(nameof(CborWriter.WriteEndTextStringIndefiniteLength))]
+        [InlineData(nameof(CborWriter.WriteEndTextString))]
         [InlineData(nameof(CborWriter.WriteEndArray))]
         [InlineData(nameof(CborWriter.WriteEndMap))]
         public static void WriteByteString_IndefiniteLength_ImbalancedWrites_ShouldThrowInvalidOperationException(string opName)
         {
             using var writer = new CborWriter();
-            writer.WriteStartByteStringIndefiniteLength();
+            writer.WriteStartByteString();
             Assert.Throws<InvalidOperationException>(() => Helpers.ExecOperation(writer, opName));
         }
     }
index e16e145..f655012 100644 (file)
@@ -75,7 +75,7 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
         {
             using var writer = new CborWriter();
 
-            writer.WriteStartArrayIndefiniteLength();
+            writer.WriteStartArray();
             writer.WriteTag(CborTag.Uri);
             Assert.Throws<InvalidOperationException>(() => writer.WriteEndArray());
         }
index 275a10f..ecfa188 100644 (file)
@@ -149,10 +149,10 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
         {
             using var writer = new CborWriter(encodeIndefiniteLengths: true);
 
-            writer.WriteStartTextStringIndefiniteLength();
+            writer.WriteStartTextString();
             writer.WriteTextString("foo");
             writer.WriteEncodedValue("63626172".HexToByteArray());
-            writer.WriteEndTextStringIndefiniteLength();
+            writer.WriteEndTextString();
 
             byte[] encoding = writer.GetEncoding();
             Assert.Equal("7f63666f6f63626172ff", encoding.ByteArrayToHex().ToLower());
@@ -163,10 +163,10 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
         {
             using var writer = new CborWriter(encodeIndefiniteLengths: true);
 
-            writer.WriteStartByteStringIndefiniteLength();
+            writer.WriteStartByteString();
             writer.WriteByteString(new byte[] { 1, 1, 1 });
             writer.WriteEncodedValue("43020202".HexToByteArray());
-            writer.WriteEndByteStringIndefiniteLength();
+            writer.WriteEndByteString();
 
             byte[] encoding = writer.GetEncoding();
             Assert.Equal("5f4301010143020202ff", encoding.ByteArrayToHex().ToLower());
@@ -176,7 +176,7 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
         public static void WriteEncodedValue_BadIndefiniteLengthStringValue_ShouldThrowInvalidOperationException()
         {
             using var writer = new CborWriter();
-            writer.WriteStartTextStringIndefiniteLength();
+            writer.WriteStartTextString();
             Assert.Throws<InvalidOperationException>(() => writer.WriteEncodedValue(new byte[] { 0x01 }));
         }
 
index 79054b8..a6d58a3 100644 (file)
@@ -22,19 +22,19 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
             PushDataItem(CborMajorType.Array, definiteLength);
         }
 
-        public void WriteEndArray()
-        {
-            PopDataItem(CborMajorType.Array);
-            AdvanceDataItemCounters();
-        }
-
-        public void WriteStartArrayIndefiniteLength()
+        public void WriteStartArray()
         {
             EnsureWriteCapacity(1);
             WriteInitialByte(new CborInitialByte(CborMajorType.Array, CborAdditionalInfo.IndefiniteLength));
             PushDataItem(CborMajorType.Array, definiteLength: null);
         }
 
+        public void WriteEndArray()
+        {
+            PopDataItem(CborMajorType.Array);
+            AdvanceDataItemCounters();
+        }
+
         private void PatchIndefiniteLengthCollection(CborMajorType majorType, int count)
         {
             Debug.Assert(majorType == CborMajorType.Array || majorType == CborMajorType.Map);
index 41454a4..133a917 100644 (file)
@@ -24,6 +24,15 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
             PushDataItem(CborMajorType.Map, definiteLength: checked(2 * definiteLength));
         }
 
+        public void WriteStartMap()
+        {
+            EnsureWriteCapacity(1);
+            WriteInitialByte(new CborInitialByte(CborMajorType.Map, CborAdditionalInfo.IndefiniteLength));
+            PushDataItem(CborMajorType.Map, definiteLength: null);
+            _currentKeyOffset = _offset;
+            _currentValueOffset = null;
+        }
+
         public void WriteEndMap()
         {
             if (_itemsWritten % 2 == 1)
@@ -35,15 +44,6 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
             AdvanceDataItemCounters();
         }
 
-        public void WriteStartMapIndefiniteLength()
-        {
-            EnsureWriteCapacity(1);
-            WriteInitialByte(new CborInitialByte(CborMajorType.Map, CborAdditionalInfo.IndefiniteLength));
-            PushDataItem(CborMajorType.Map, definiteLength: null);
-            _currentKeyOffset = _offset;
-            _currentValueOffset = null;
-        }
-
         //
         // Map encoding conformance
         //
index 1459f7e..6b373d3 100644 (file)
@@ -64,7 +64,7 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
             AdvanceDataItemCounters();
         }
 
-        public void WriteStartByteStringIndefiniteLength()
+        public void WriteStartByteString()
         {
             if (!EncodeIndefiniteLengths)
             {
@@ -79,13 +79,13 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
             PushDataItem(CborMajorType.ByteString, definiteLength: null);
         }
 
-        public void WriteEndByteStringIndefiniteLength()
+        public void WriteEndByteString()
         {
             PopDataItem(CborMajorType.ByteString);
             AdvanceDataItemCounters();
         }
 
-        public void WriteStartTextStringIndefiniteLength()
+        public void WriteStartTextString()
         {
             if (!EncodeIndefiniteLengths)
             {
@@ -100,7 +100,7 @@ namespace System.Security.Cryptography.Encoding.Tests.Cbor
             PushDataItem(CborMajorType.TextString, definiteLength: null);
         }
 
-        public void WriteEndTextStringIndefiniteLength()
+        public void WriteEndTextString()
         {
             PopDataItem(CborMajorType.TextString);
             AdvanceDataItemCounters();