Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1282)

Unified Diff: test/base64_test.dart

Issue 1169453002: Add an option for percent-encoding of the padding character to Base64Codec (Closed) Base URL: https://github.com/dart-lang/crypto.git@master
Patch Set: Fix formatting according to issue comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/base64.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/base64_test.dart
diff --git a/test/base64_test.dart b/test/base64_test.dart
index 725ac3fef3005a91d6dfb325bf0814fe9c3e0799..76b586e23d8cbdb00ffb635be572b562ac9cf411 100644
--- a/test/base64_test.dart
+++ b/test/base64_test.dart
@@ -19,6 +19,8 @@ void main() {
test('url safe encode-decode', _testUrlSafeEncodeDecode);
test('consistent safe/unsafe character decoding',
_testConsistentSafeUnsafeDecode);
+ test('percent-encoded padding character encode-decode',
+ _testPaddingCharacter);
test('streaming encoder', _testStreamingEncoder);
test('streaming decoder', _testStreamingDecoder);
test('streaming decoder for malformed input',
@@ -29,6 +31,8 @@ void main() {
_testStreamingDecoderForDecompositions);
test('consistent safe/unsafe character streaming decoding',
_testConsistentSafeUnsafeStreamDecode);
+ test('streaming for encoded padding character',
+ _testStreamingForEncodedPadding);
test('old api', _testOldApi);
test('url safe streaming encoder/decoder', _testUrlSafeStreaming);
test('performance', _testPerformance);
@@ -41,6 +45,9 @@ const _INPUTS =
const [ '', 'f', 'fo', 'foo', 'foob', 'fooba', 'foobar'];
const _RESULTS =
const [ '', 'Zg==', 'Zm8=', 'Zm9v', 'Zm9vYg==', 'Zm9vYmE=', 'Zm9vYmFy'];
+
+const _PADDING_INPUT = const [2, 8];
+
var _STREAMING_ENCODER_INPUT =
[[102, 102], [111, 102],
[111, 111, 102, 111, 111, 98, 102, 111,
@@ -148,6 +155,12 @@ void _testDecoder() {
expect(new String.fromCharCodes(longLineResultNoBreak), _LONG_LINE);
}
+void _testPaddingCharacter() {
+ var encoded = BASE64.encode(_PADDING_INPUT, encodePaddingCharacter: true);
+ expect(encoded, 'Agg%3D');
+ expect(BASE64.decode(encoded), _PADDING_INPUT);
+}
+
Future _testStreamingEncoder() async {
expect(
await new Stream.fromIterable(_STREAMING_ENCODER_INPUT)
@@ -237,6 +250,15 @@ Future _testConsistentSafeUnsafeStreamDecode() {
throwsFormatException);
}
+Future _testStreamingForEncodedPadding() async {
+ List<String> withEncodedPadding = ['AA%', '3D', '%', '3', 'DEFGZ'];
+ List<int> decoded = BASE64.decode('AA==EFGZ');
+ var streamedResult = await new Stream.fromIterable(withEncodedPadding)
+ .transform(BASE64.decoder).expand((x) => x).toList();
+
+ expect(streamedResult, decoded);
+}
+
void _testUrlSafeEncodeDecode() {
List<int> decUrlSafe = BASE64.decode('-_A=');
List<int> dec = BASE64.decode('+/A=');
« no previous file with comments | « lib/src/base64.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698