@@ -244,6 +244,8 @@ class TestNSData: LoopbackServerTest {
244
244
( " test_base64EncodedDataWithOptionToInsertCarriageReturnContainsCarriageReturn " , test_base64EncodedDataWithOptionToInsertCarriageReturnContainsCarriageReturn) ,
245
245
( " test_base64EncodedDataWithOptionToInsertLineFeedsContainsLineFeed " , test_base64EncodedDataWithOptionToInsertLineFeedsContainsLineFeed) ,
246
246
( " test_base64EncodedDataWithOptionToInsertCarriageReturnAndLineFeedContainsBoth " , test_base64EncodedDataWithOptionToInsertCarriageReturnAndLineFeedContainsBoth) ,
247
+ ( " test_base64EncodeDoesNotAddLineSeparatorsWhenStringFitsInLine " , test_base64EncodeDoesNotAddLineSeparatorsWhenStringFitsInLine) ,
248
+ ( " test_base64EncodeAddsLineSeparatorsWhenStringDoesNotFitInLine " , test_base64EncodeAddsLineSeparatorsWhenStringDoesNotFitInLine) ,
247
249
( " test_base64EncodedStringGetsEncodedText " , test_base64EncodedStringGetsEncodedText) ,
248
250
( " test_initializeWithBase64EncodedStringGetsDecodedData " , test_initializeWithBase64EncodedStringGetsDecodedData) ,
249
251
( " test_base64DecodeWithPadding1 " , test_base64DecodeWithPadding1) ,
@@ -814,6 +816,36 @@ class TestNSData: LoopbackServerTest {
814
816
XCTAssertEqual ( encodedTextResult, encodedText)
815
817
}
816
818
819
+ func test_base64EncodeDoesNotAddLineSeparatorsWhenStringFitsInLine( ) {
820
+
821
+ XCTAssertEqual (
822
+ Data ( repeating: 0 , count: 48 ) . base64EncodedString ( options: . lineLength64Characters) ,
823
+ " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " ,
824
+ " each 3 byte is converted into 4 characterss. 48 / 3 * 4 <= 64, therefore result should not have line separator. "
825
+ )
826
+
827
+ XCTAssertEqual (
828
+ Data ( repeating: 0 , count: 57 ) . base64EncodedString ( options: . lineLength76Characters) ,
829
+ " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " ,
830
+ " each 3 byte is converted into 4 characterss. 57 / 3 * 4 <= 76, therefore result should not have line separator. "
831
+ )
832
+ }
833
+
834
+ func test_base64EncodeAddsLineSeparatorsWhenStringDoesNotFitInLine( ) {
835
+
836
+ XCTAssertEqual (
837
+ Data ( repeating: 0 , count: 49 ) . base64EncodedString ( options: . lineLength64Characters) ,
838
+ " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA \r \n AA== " ,
839
+ " each 3 byte is converted into 4 characterss. 49 / 3 * 4 > 64, therefore result should have lines with separator. "
840
+ )
841
+
842
+ XCTAssertEqual (
843
+ Data ( repeating: 0 , count: 58 ) . base64EncodedString ( options: . lineLength76Characters) ,
844
+ " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA \r \n AA== " ,
845
+ " each 3 byte is converted into 4 characterss. 58 / 3 * 4 > 76, therefore result should have lines with separator. "
846
+ )
847
+ }
848
+
817
849
func test_base64EncodedStringGetsEncodedText( ) {
818
850
let plainText = " Revocate animos, maestumque timorem mittite: forsan et haec olim meminisse iuvabit. "
819
851
let encodedText = " UmV2b2NhdGUgYW5pbW9zLCBtYWVzdHVtcXVlIHRpbW9yZW0gbWl0dGl0ZTogZm9yc2FuIGV0IGhhZWMgb2xpbSBtZW1pbmlzc2UgaXV2YWJpdC4= "
0 commit comments