Skip to content

Commit

Permalink
Issue 62 - final fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shamblett committed Jun 30, 2024
1 parent e90af73 commit a561c30
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/src/value/internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ mixin CborValueMixin implements CborValue {
toJsonInternal(
{},
ToJsonOptions(
encoding: JsonBytesEncoding.base64Url,
encoding: JsonBytesEncoding.base16,
allowMalformedUtf8: allowMalformedUtf8,
substituteValue: substituteValue,
),
);

JsonBytesEncoding? get expectedConversion {
var retVal = JsonBytesEncoding.base64Url;
var retVal = JsonBytesEncoding.base16;
for (final tag in tags.reversed) {
switch (tag) {
case CborTag.expectedConversionToBase16:
Expand Down
18 changes: 8 additions & 10 deletions test/issue62/issue62_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import 'package:cbor/cbor.dart';
import 'package:test/test.dart';

void main() {
test(
'Weird JSON conversion',
() async {
final currDir = Directory.current.path;
final f = File('$currDir/test/issue62/raw.txt');
final decoded = await f.openRead().transform(cbor.decoder).single;
expect(decoded.toString().isNotEmpty, isTrue);
final jsonEncoder = CborJsonEncoder();
final json = jsonEncoder.convert(decoded);
print(json);
test('Weird JSON conversion', () async {
final currDir = Directory.current.path;
final f = File('$currDir/test/issue62/raw.txt');
final decoded = await f.openRead().transform(cbor.decoder).single;
expect(decoded.toString().isNotEmpty, isTrue);
final jsonEncoder = CborJsonEncoder();
final json = jsonEncoder.convert(decoded);
print(json);
});
}
14 changes: 9 additions & 5 deletions test/json_encoder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@ void main() {
});

test('18446744073709551615', () {
expect(encode(BigInt.parse('18446744073709551615')), '"__________8"');
expect(
encode(BigInt.parse('18446744073709551615')), '"FFFFFFFFFFFFFFFF"');
});

test('18446744073709551616', () {
expect(encode(BigInt.parse('18446744073709551616')), '"AQAAAAAAAAAA"');
expect(
encode(BigInt.parse('18446744073709551616')), '"010000000000000000"');
});

test('-18446744073709551616', () {
expect(encode(BigInt.parse('-18446744073709551616')), '"~__________8"');
expect(
encode(BigInt.parse('-18446744073709551616')), '"~FFFFFFFFFFFFFFFF"');
});

test('-18446744073709551617', () {
expect(encode(BigInt.parse('-18446744073709551617')), '"~AQAAAAAAAAAA"');
expect(encode(BigInt.parse('-18446744073709551617')),
'"~010000000000000000"');
});

test('-1', () {
Expand Down Expand Up @@ -113,7 +117,7 @@ void main() {
});

test('4 bytes', () {
expect(encode(Uint8List.fromList([0x1, 0x2, 0x3, 0x4])), '"AQIDBA"');
expect(encode(Uint8List.fromList([0x1, 0x2, 0x3, 0x4])), '"01020304"');
});

test('Quoted backslash', () {
Expand Down

0 comments on commit a561c30

Please sign in to comment.