dart-sdk/tests/lib/convert/chunked_conversion2_test.dart
Lasse R.H. Nielsen f6ac970290 Reland "Add class modifiers to dart:convert." again.
This is a reland of commit 608934e330

Can be landed when Flutter with https://github.com/flutter/flutter/pull/123211
has been rolled into internal repository.



Original change's description:
> Reland "Add class modifiers to `dart:convert`."
>
> This is a reland of commit b2f4cf3e01
>
> Commented out deprecation for now.
>
> Original change's description:
> > Add class modifiers to `dart:convert`.
> >
> > The usual approach:
> > Pure interfaces marked `interface`.
> > Pure implementation classes marked `final`.
> > Base classes marked `base` or nothing, and `mixin class` if reasonable.
> > Combined X/XBase/XMixin where possible.
> >
> > CoreLibraryReviewExempt: Aske is away
> > Change-Id: I927f9bd488fb385ff9c17c8fc94920a1f5076347
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289200
> > Reviewed-by: Stephen Adams <sra@google.com>
> > Reviewed-by: Slava Egorov <vegorov@google.com>
> > Reviewed-by: Nate Bosch <nbosch@google.com>
> > Commit-Queue: Lasse Nielsen <lrn@google.com>
>
> CoreLibraryReviewExempt: Approved in original.
> Change-Id: I1bc14f99b742567e2634dcfcbc52f332dbcc5364
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290521
> Reviewed-by: Nate Bosch <nbosch@google.com>
> Commit-Queue: Lasse Nielsen <lrn@google.com>

CoreLibraryReviewExempt: Approved in original.
Change-Id: If157e1ef2339d7a06e99a1e402f2f8ac93550b83
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290960
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2023-03-29 16:54:23 +00:00

55 lines
1.3 KiB
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:convert';
import 'package:expect/expect.dart';
// Test that the String and ByteConversionSinks make a copy when they need to
// adapt.
class MyByteSink extends ByteConversionSink {
var accumulator = [];
add(List<int> bytes) {
accumulator.add(bytes);
}
close() {}
}
void testBase() {
var byteSink = new MyByteSink();
var bytes = [1];
byteSink.addSlice(bytes, 0, 1, false);
bytes[0] = 2;
byteSink.addSlice(bytes, 0, 1, true);
Expect.equals(1, byteSink.accumulator[0][0]);
Expect.equals(2, byteSink.accumulator[1][0]);
}
class MyChunkedSink implements ChunkedConversionSink<List<int>> {
var accumulator = [];
add(List<int> bytes) {
accumulator.add(bytes);
}
close() {}
}
void testAdapter() {
var chunkedSink = new MyChunkedSink();
var byteSink = new ByteConversionSink.from(chunkedSink);
var bytes = [1];
byteSink.addSlice(bytes, 0, 1, false);
bytes[0] = 2;
byteSink.addSlice(bytes, 0, 1, true);
Expect.equals(1, chunkedSink.accumulator[0][0]);
Expect.equals(2, chunkedSink.accumulator[1][0]);
}
void main() {
testBase();
testAdapter();
}