Skip to content

Commit

Permalink
Add test for utf8 & base64
Browse files Browse the repository at this point in the history
  • Loading branch information
kodjodevf committed Nov 15, 2023
1 parent d409d3d commit 2e7a188
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions test/convert_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@TestOn('vm')

import 'package:dart_eval/dart_eval.dart';
import 'package:dart_eval/dart_eval_bridge.dart';
import 'package:test/test.dart';

void main() {
Expand Down Expand Up @@ -78,5 +79,97 @@ void main() {
),
1);
});
test('utf8.encode()', () async {
final runtime = compiler.compileWriteAndLoad({
'example': {
'main.dart': '''
import 'dart:convert';
List<int> main() {
return utf8.encode("Hello world");
}
'''
}
});

expect(
runtime
.executeLib(
'package:example/main.dart',
'main',
)
.map((e) => (e is $Value ? e.$reified : e) as int)
.toList(),
[72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]);
});

test('utf8.decode()', () async {
final runtime = compiler.compileWriteAndLoad({
'example': {
'main.dart': '''
import 'dart:convert';
String main() {
return utf8.decode([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]);
}
'''
}
});

expect(
runtime
.executeLib(
'package:example/main.dart',
'main',
)
.$reified,
"Hello world");
});
test('base64.encode()', () async {
final runtime = compiler.compileWriteAndLoad({
'example': {
'main.dart': '''
import 'dart:convert';
String main() {
return base64.encode(utf8.encode("Hello world"));
}
'''
}
});

expect(
(runtime
.executeLib(
'package:example/main.dart',
'main',
)
as $Value).$reified,
'SGVsbG8gd29ybGQ=');
});

test('base64.decode()', () async {
final runtime = compiler.compileWriteAndLoad({
'example': {
'main.dart': '''
import 'dart:convert';
List<int> main() {
return base64.decode("SGVsbG8gd29ybGQ=");
}
'''
}
});

expect(
runtime
.executeLib(
'package:example/main.dart',
'main',
)
.map((e) => (e is $Value ? e.$reified : e) as int)
.toList(),
[72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]);
});
});
}

0 comments on commit 2e7a188

Please sign in to comment.