nc-photos/codegen_build/test/np_log_test.dart

64 lines
1.4 KiB
Dart
Raw Permalink Normal View History

import 'package:np_codegen_build/src/np_log_generator.dart';
2022-12-16 16:01:04 +01:00
import 'package:test/test.dart';
2024-05-20 18:47:11 +02:00
import 'util.dart';
2022-12-16 16:01:04 +01:00
// dummy class to free us from importing the actual logger library
class Logger {
Logger(String name);
}
2024-05-20 18:47:11 +02:00
void main() async {
await resolveCompilationUnit("test/src/np_log.dart");
tearDown(() {
// Increment this after each test so the next test has it's own package
_pkgCacheCount++;
});
2022-12-16 16:01:04 +01:00
test("NpLog", () async {
2024-05-20 18:47:11 +02:00
final src = _genSrc("""
@npLog
class Foo {}
""");
final expected = _genExpected(r"""
extension _$FooNpLog on Foo {
2022-12-16 16:01:04 +01:00
// ignore: unused_element
2023-02-23 17:26:35 +01:00
Logger get _log => log;
2024-05-20 18:47:11 +02:00
static final log = Logger("test.Foo");
2022-12-16 16:01:04 +01:00
}
2024-05-20 18:47:11 +02:00
""");
return _buildTest(src, expected);
2022-12-16 16:01:04 +01:00
});
}
2024-05-20 18:47:11 +02:00
String _genSrc(String src) {
return """
import 'package:np_codegen/np_codegen.dart';
part 'test.g.dart';
$src
""";
}
String _genExpected(String src) {
return """// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'test.dart';
// **************************************************************************
// NpLogGenerator
// **************************************************************************
$src""";
}
Future _buildTest(String src, String expected) => buildTest(
generators: [const NpLogGenerator()],
pkgName: _pkgName,
src: src,
expected: expected,
);
String get _pkgName => 'pkg$_pkgCacheCount';
int _pkgCacheCount = 1;