You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.2 KiB
83 lines
2.2 KiB
// The differential of the formats against the Go reference on the VM, with
|
|
// every case of test/vectors/formats_*.json and the fixtures of testdata/
|
|
// that the cases of the frame of a .dkc cut and edit. And the part of those
|
|
// files that formats_vectors.g.dart holds for the tests compiled to
|
|
// JavaScript, which must be every eighth case of each section.
|
|
@TestOn('vm')
|
|
library;
|
|
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:datekeys/src/version.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'formats_differential.dart';
|
|
import 'vectors/formats_vectors.g.dart';
|
|
|
|
const names = [
|
|
'framing',
|
|
'header',
|
|
'control',
|
|
'profile',
|
|
'extension',
|
|
'datekey',
|
|
'time',
|
|
'padding',
|
|
'body',
|
|
'encode',
|
|
];
|
|
|
|
void main() {
|
|
final files = {
|
|
for (final n in names)
|
|
n: jsonDecode(
|
|
File('test/vectors/formats_$n.json').readAsStringSync(),
|
|
) as Json,
|
|
};
|
|
|
|
test('every file is of this specification and of its generator', () {
|
|
for (final f in files.values) {
|
|
expect(f['spec'], specVersion);
|
|
expect(f['generator'], 'tool/formats_go_vectors.go');
|
|
}
|
|
});
|
|
|
|
formatsDifferential(
|
|
files,
|
|
testdata: (path) => File('testdata/$path').readAsBytesSync(),
|
|
);
|
|
|
|
group('formats_vectors.g.dart', () {
|
|
const embedded = {
|
|
'framing': formatsFramingJson,
|
|
'header': formatsHeaderJson,
|
|
'control': formatsControlJson,
|
|
'profile': formatsProfileJson,
|
|
'extension': formatsExtensionJson,
|
|
'datekey': formatsDatekeyJson,
|
|
'time': formatsTimeJson,
|
|
'padding': formatsPaddingJson,
|
|
'body': formatsBodyJson,
|
|
'encode': formatsEncodeJson,
|
|
};
|
|
for (final MapEntry(key: name, value: text) in embedded.entries) {
|
|
test('holds every eighth case of formats_$name.json', () {
|
|
final part = jsonDecode(text) as Json;
|
|
final file = files[name]!;
|
|
expect(part.keys, file.keys);
|
|
for (final key in file.keys) {
|
|
final value = file[key];
|
|
if (value is! List) {
|
|
expect(part[key], value);
|
|
continue;
|
|
}
|
|
expect(part[key], [
|
|
for (var i = 0; i < value.length; i += 8) value[i],
|
|
], reason: key);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|