Files
sdk/tests/lib_strong/convert/codec2_test.dart
T
Bob Nystrom 6c757957db Move the dev_compiler strong mode tests into sdk/tests/.
DDC's codegen test copies those files to a local "gen" directory so
that it can do stuff like splitting out the multitests before it
compiles them to JS.

I left all of that alone, so the rest of DDC's test infrastructure is
unchanged. The very first step that builds the "gen" directory just
copies from sdk/tests/..._strong/... instead and the rest is good to go.

I did not move not_yet_strong_tests.dart somewhere more accessible yet
because I'm not sure if kernel needs it or where it should go.

I did not create any status files because DDC doesn't need them and
there are no test suites for the new directories for the other
platforms.
2016-12-09 11:09:55 -08:00

43 lines
1.4 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';
main() {
final RAW = '["122ç",50,50,231]';
final ENCODED = const [91, 34, 49, 50, 50, 195, 167, 34, 44,
53, 48, 44, 53, 48, 44, 50, 51, 49, 93];
Expect.listEquals(ENCODED, UTF8.encode(RAW));
Expect.equals(RAW, UTF8.decode(ENCODED));
Expect.listEquals([], UTF8.encode(""));
Expect.equals("", UTF8.decode([]));
final JSON_ENCODED = RAW;
Expect.equals(JSON_ENCODED, JSON.encode(["122ç", 50, 50, 231]));
Expect.listEquals(["122ç", 50, 50, 231], JSON.decode(JSON_ENCODED));
// Test that the reviver is passed to the decoder.
var decoded = JSON.decode('{"p": 5}', reviver: (k, v) {
if (k == null) return v;
return v * 2;
});
Expect.equals(10, decoded["p"]);
var jsonWithReviver = new JsonCodec.withReviver((k, v) {
if (k == null) return v;
return v * 2;
});
decoded = jsonWithReviver.decode('{"p": 5}');
Expect.equals(10, decoded["p"]);
// Test example from comments.
final JSON_TO_BYTES = JSON.fuse(UTF8);
List<int> bytes = JSON_TO_BYTES.encode(["json-object"]);
decoded = JSON_TO_BYTES.decode(bytes);
Expect.isTrue(decoded is List);
Expect.equals("json-object", (decoded as List)[0]);
}