mirror of
https://gitlab.com/TheOneWithTheBraid/dart_pkpass.git
synced 2025-07-05 12:58:47 +00:00
chore: initial commit
Signed-off-by: The one with the braid <the-one@with-the-braid.cf>
This commit is contained in:
commit
cf9609d699
20 changed files with 1483 additions and 0 deletions
130
test/pkpass_test.dart
Normal file
130
test/pkpass_test.dart
Normal file
|
@ -0,0 +1,130 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:archive/archive.dart';
|
||||
import 'package:intl/locale.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:pkpass/pkpass.dart';
|
||||
import 'package:pkpass/src/file_matcher.dart';
|
||||
|
||||
void main() {
|
||||
final archive = [
|
||||
ArchiveFile('logo.png', 0, Uint8List(0)),
|
||||
ArchiveFile('logo@2x.png', 0, Uint8List(0)),
|
||||
ArchiveFile('logo@4x.png', 0, Uint8List(0)),
|
||||
ArchiveFile('en-us.lproj/logo.png', 0, Uint8List(0)),
|
||||
ArchiveFile('en-us.lproj/logo@2x.png', 0, Uint8List(0)),
|
||||
ArchiveFile('en-us.lproj/logo@4x.png', 0, Uint8List(0)),
|
||||
ArchiveFile('fr.lproj/logo.png', 0, Uint8List(0)),
|
||||
ArchiveFile('fr.lproj/logo@2x.png', 0, Uint8List(0)),
|
||||
ArchiveFile('fr.lproj/logo@4x.png', 0, Uint8List(0)),
|
||||
];
|
||||
|
||||
// ignore: unused_local_variable
|
||||
final file = PassFile(
|
||||
PassMetadata(
|
||||
description: null,
|
||||
formatVersion: 0,
|
||||
organizationName: null,
|
||||
passTypeIdentifier: null,
|
||||
serialNumber: null,
|
||||
teamIdentifier: null,
|
||||
suppressStripShine: null,
|
||||
eventTicket: null,
|
||||
barcode: null,
|
||||
foregroundColor: null,
|
||||
locations: [],
|
||||
),
|
||||
archive,
|
||||
);
|
||||
group('FileMatcher', () {
|
||||
test('matchLocale empty locale', () {
|
||||
final localized = FileMatcher.matchLocale(
|
||||
files: archive.map((e) => e.name).toList(),
|
||||
name: 'logo',
|
||||
extension: 'png',
|
||||
);
|
||||
expect(localized.length, 3);
|
||||
expect(
|
||||
localized.every((element) => element.startsWith('logo')),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
test('matchLocale language fallback', () {
|
||||
final localized = FileMatcher.matchLocale(
|
||||
files: archive.map((e) => e.name).toList(),
|
||||
name: 'logo',
|
||||
extension: 'png',
|
||||
locale: Locale.fromSubtags(languageCode: 'fr', countryCode: 'fr'),
|
||||
);
|
||||
expect(localized.length, 3);
|
||||
expect(
|
||||
localized.every((element) => element.startsWith('fr.lproj/')),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
test('matchLocale region fallback', () {
|
||||
final localized = FileMatcher.matchLocale(
|
||||
files: archive.map((e) => e.name).toList(),
|
||||
name: 'logo',
|
||||
extension: 'png',
|
||||
locale: Locale.fromSubtags(languageCode: 'en', countryCode: 'gb'),
|
||||
);
|
||||
expect(localized.length, 3);
|
||||
expect(
|
||||
localized.every((element) => element.startsWith('en-us.lproj/')),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
test('matchLocale unlnown locale', () {
|
||||
final localized = FileMatcher.matchLocale(
|
||||
files: archive.map((e) => e.name).toList(),
|
||||
name: 'logo',
|
||||
extension: 'png',
|
||||
locale: Locale.fromSubtags(languageCode: 'tlh', countryCode: 'qs'),
|
||||
);
|
||||
expect(localized.length, 3);
|
||||
expect(
|
||||
localized.every((element) => element.startsWith('logo')),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
test('matchScale default', () {
|
||||
final localized = FileMatcher.matchLocale(
|
||||
files: archive.map((e) => e.name).toList(),
|
||||
name: 'logo',
|
||||
extension: 'png',
|
||||
);
|
||||
final scaled = FileMatcher.matchScale(
|
||||
files: localized,
|
||||
name: 'logo',
|
||||
extension: 'png',
|
||||
);
|
||||
expect(scaled, 'logo.png');
|
||||
});
|
||||
test('matchScale smallest neighbor', () {
|
||||
final localized = FileMatcher.matchLocale(
|
||||
files: archive.map((e) => e.name).toList(),
|
||||
name: 'logo',
|
||||
extension: 'png',
|
||||
);
|
||||
final scaled = FileMatcher.matchScale(
|
||||
files: localized, name: 'logo', extension: 'png', scale: 6);
|
||||
expect(scaled, 'logo@4x.png');
|
||||
});
|
||||
test('matchScale biggest neighbor', () {
|
||||
final localized = FileMatcher.matchLocale(
|
||||
files: archive.map((e) => e.name).toList(),
|
||||
name: 'logo',
|
||||
extension: 'png',
|
||||
);
|
||||
final scaled = FileMatcher.matchScale(
|
||||
files: localized,
|
||||
name: 'logo',
|
||||
extension: 'png',
|
||||
scale: 3,
|
||||
);
|
||||
expect(scaled, 'logo@4x.png');
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue