Skip to content

Commit

Permalink
Formatted and fixed lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Lesches committed Jan 13, 2025
1 parent 29536dc commit 4f0391a
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 28 deletions.
2 changes: 0 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,3 @@ linter:
use_super_parameters: true
# jni rules
prefer_const_declarations: true
# native_assets_builder rules
prefer_expression_function_bodies: true
2 changes: 1 addition & 1 deletion pkgs/ffi/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void main() {

// Use the Utf8 helper to encode zero-terminated UTF-8 strings in native
// memory.
final myString = '😎👿💬';
const myString = '😎👿💬';
final charPointer = myString.toNativeUtf8();
print('First byte is: ${charPointer.cast<Uint8>().value}');
print(charPointer.toDartString());
Expand Down
4 changes: 2 additions & 2 deletions pkgs/ffi/test/allocation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ void main() async {

test('testPointerAllocateTooLarge', () {
// Try to allocate something that doesn't fit in 64 bit address space.
final maxInt = 9223372036854775807; // 2^63 - 1
const maxInt = 9223372036854775807; // 2^63 - 1
expect(() => calloc<Uint8>(maxInt), throwsA(isA<ArgumentError>()));

// Try to allocate almost the full 64 bit address space.
final maxInt1_8 = 1152921504606846975; // 2^60 -1
const maxInt1_8 = 1152921504606846975; // 2^60 -1
expect(() => calloc<Uint8>(maxInt1_8), throwsA(isA<ArgumentError>()));
});

Expand Down
14 changes: 7 additions & 7 deletions pkgs/ffi/test/utf16_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:test/test.dart';

void main() {
test('toUtf16 ASCII', () {
final start = 'Hello World!\n';
const start = 'Hello World!\n';
final converted = start.toNativeUtf16().cast<Uint16>();
final end = converted.asTypedList(start.codeUnits.length + 1);
final matcher = equals(start.codeUnits.toList()..add(0));
Expand All @@ -18,7 +18,7 @@ void main() {
});

test('toUtf16 emoji', () {
final start = '😎';
const start = '😎';
final converted = start.toNativeUtf16().cast();
final length = start.codeUnits.length;
final end = converted.cast<Uint16>().asTypedList(length + 1);
Expand All @@ -28,38 +28,38 @@ void main() {
});

test('from Utf16 ASCII', () {
final string = 'Hello World!\n';
const string = 'Hello World!\n';
final utf16Pointer = string.toNativeUtf16();
final stringAgain = utf16Pointer.toDartString();
expect(stringAgain, string);
calloc.free(utf16Pointer);
});

test('from Utf16 emoji', () {
final string = '😎';
const string = '😎';
final utf16Pointer = string.toNativeUtf16();
final stringAgain = utf16Pointer.toDartString();
expect(stringAgain, string);
calloc.free(utf16Pointer);
});

test('zero bytes', () {
final string = 'Hello\x00World!\n';
const string = 'Hello\x00World!\n';
final utf16Pointer = string.toNativeUtf16();
final stringAgain = utf16Pointer.toDartString(length: 13);
expect(stringAgain, string);
calloc.free(utf16Pointer);
});

test('length', () {
final string = 'Hello';
const string = 'Hello';
final utf16Pointer = string.toNativeUtf16();
expect(utf16Pointer.length, 5);
calloc.free(utf16Pointer);
});

test('fromUtf8 with negative length', () {
final string = 'Hello';
const string = 'Hello';
final utf16 = string.toNativeUtf16();
expect(() => utf16.toDartString(length: -1), throwsRangeError);
calloc.free(utf16);
Expand Down
8 changes: 4 additions & 4 deletions pkgs/ffi/test/utf8_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Pointer<Uint8> _bytesFromList(List<int> ints) {

void main() {
test('toUtf8 ASCII', () {
final start = 'Hello World!\n';
const start = 'Hello World!\n';
final converted = start.toNativeUtf8().cast<Uint8>();
final end = converted.asTypedList(start.length + 1);
final matcher = equals(
Expand All @@ -36,7 +36,7 @@ void main() {
});

test('toUtf8 emoji', () {
final start = '😎👿💬';
const start = '😎👿💬';
final converted = start.toNativeUtf8().cast<Utf8>();
final length = converted.length;
final end = converted.cast<Uint8>().asTypedList(length + 1);
Expand Down Expand Up @@ -100,7 +100,7 @@ void main() {
});

test('length', () {
final string = 'Hello';
const string = 'Hello';
final utf8Pointer = string.toNativeUtf8();
expect(utf8Pointer.length, 5);
calloc.free(utf8Pointer);
Expand All @@ -117,7 +117,7 @@ void main() {
});

test('zero terminated', () {
final string = 'Hello';
const string = 'Hello';
final utf8Pointer = string.toNativeUtf8();
final charPointer = utf8Pointer.cast<Char>();
expect(charPointer[utf8Pointer.length], 0);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/lib/src/code_generator/writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Writer {

/// Finding a unique prefix for Array Helper Classes and store into
/// [_arrayHelperClassPrefix].
final base = 'ArrayHelper';
const base = 'ArrayHelper';
_arrayHelperClassPrefix = base;
var suffixInt = 0;
for (var i = 0; i < allNameSet.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void _compoundMembersVisitor(
// Anonymous members are always unnamed. To avoid environment-
// dependent naming issues with the generated code, we explicitly
// use the empty string as spelling.
final spelling = '';
const spelling = '';

parsed.compound.members.add(
CompoundMember(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ late Set<String> _macroVarNames;
/// Creates a temporary file for parsing macros in current directory.
File createFileForMacros() {
final fileNameBase = p.normalize(p.join(strings.tmpDir, 'temp_for_macros'));
final fileExt = 'hpp';
const fileExt = 'hpp';

// Find a filename which doesn't already exist.
var file = File('$fileNameBase.$fileExt');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ void main() {
});

test('Adds Native symbol on mismatch', () {
final nativeConfig = const FfiNativeConfig(enabled: true);
const nativeConfig = FfiNativeConfig(enabled: true);
final library = Library(
name: 'init_dylib',
header:
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/test/config_tests/compiler_opts_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import '../test_utils.dart';
void main() {
group('compiler_opts_test', () {
test('Compiler Opts', () {
final opts =
const opts =
'''--option value "in double quotes" 'in single quotes' -tab=separated''';
final list = compilerOptsToList(opts);
expect(
Expand Down
4 changes: 2 additions & 2 deletions pkgs/ffigen/test/native_test/native_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ void main() {
});

test('Enum1 is a Dart enum', () {
final enum1 = Enum1.enum1Value1;
const enum1 = Enum1.enum1Value1;
final result = bindings.funcWithEnum1(enum1);
expect(enum1, isA<Enum1>());
expect(enum1.value, isA<int>());
expect(result, enum1);
});

test('Enum2 is a Dart integer', () {
final enum2 = Enum2.enum2Value1;
const enum2 = Enum2.enum2Value1;
final result = bindings.funcWithEnum2(enum2);
expect(enum2, isA<int>());
expect(result, enum2);
Expand Down
8 changes: 4 additions & 4 deletions pkgs/ffigen/test/rename_tests/rename_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import 'package:test/test.dart';
import '../test_utils.dart';

late Library actual, expected;
final functionPrefix = 'fff';
final structPrefix = 'sss';
final enumPrefix = 'eee';
final macroPrefix = 'mmm';
const functionPrefix = 'fff';
const structPrefix = 'sss';
const enumPrefix = 'eee';
const macroPrefix = 'mmm';

void main() {
group('rename_test', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:test/test.dart';

void main() {
Uri? tempDirUri;
final projectName = 'test_project';
const projectName = 'test_project';

setUp(() async {
tempDirUri = (await Directory.current.createTemp('.temp_test_')).uri;
Expand Down

0 comments on commit 4f0391a

Please sign in to comment.