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

Unified Diff: tests/lib/convert/base64_test.dart

Issue 1858113003: Add "url-safe" encoding to base64 in dart:convert. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix typo Created 4 years, 8 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 | « sdk/lib/convert/base64.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/convert/base64_test.dart
diff --git a/tests/lib/convert/base64_test.dart b/tests/lib/convert/base64_test.dart
index 457e330d8fc195d07a487661b0ea57fab0d95e7b..4a2c1ab8e55cd66e0c7366ac6ea76728cde748cb 100644
--- a/tests/lib/convert/base64_test.dart
+++ b/tests/lib/convert/base64_test.dart
@@ -31,16 +31,23 @@ void testRoundtrip(list, name) {
// Direct.
String encodedNormal = BASE64.encode(list);
String encodedPercent = encodedNormal.replaceAll("=", "%3D");
- String uriEncoded = encodedNormal.replaceAll("+", "-").replaceAll("/", "_");
+ String uriEncoded = BASE64URL.encode(list);
+ String expectedUriEncoded =
+ encodedNormal.replaceAll("+", "-").replaceAll("/", "_");
+ Expect.equals(expectedUriEncoded, uriEncoded);
+
List result = BASE64.decode(encodedNormal);
Expect.listEquals(list, result, name);
result = BASE64.decode(encodedPercent);
Expect.listEquals(list, result, name);
+ result = BASE64.decode(uriEncoded);
+ Expect.listEquals(list, result, name);
int increment = list.length ~/ 7 + 1;
// Chunked.
for (int i = 0; i < list.length; i += increment) {
for (int j = i; j < list.length; j += increment) {
+ // Normal
{
// Using add/close
var results;
@@ -64,6 +71,30 @@ void testRoundtrip(list, name) {
var name = "0-$i-$j-${list.length}: $list";
Expect.equals(encodedNormal, results.join(""), name);
}
+ // URI
+ {
+ // Using add/close
+ var results;
+ var sink = new ChunkedConversionSink.withCallback((v) { results = v; });
+ var encoder = BASE64URL.encoder.startChunkedConversion(sink);
+ encoder.add(list.sublist(0, i));
+ encoder.add(list.sublist(i, j));
+ encoder.add(list.sublist(j, list.length));
+ encoder.close();
+ var name = "0-$i-$j-${list.length}: list";
+ Expect.equals(uriEncoded, results.join(""), name);
+ }
+ {
+ // Using addSlice
+ var results;
+ var sink = new ChunkedConversionSink.withCallback((v) { results = v; });
+ var encoder = BASE64URL.encoder.startChunkedConversion(sink);
+ encoder.addSlice(list, 0, i, false);
+ encoder.addSlice(list, i, j, false);
+ encoder.addSlice(list, j, list.length, true);
+ var name = "0-$i-$j-${list.length}: $list";
+ Expect.equals(uriEncoded, results.join(""), name);
+ }
}
}
@@ -119,6 +150,7 @@ void testErrors() {
}
void badDecode(String string) {
Expect.throws(() => BASE64.decode(string), isFormatException, string);
+ Expect.throws(() => BASE64URL.decode(string), isFormatException, string);
badChunkDecode([string]);
badChunkDecode(["", string]);
badChunkDecode([string, ""]);
« no previous file with comments | « sdk/lib/convert/base64.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698