Stage 0: the package datekeys and its test data at spec-v0.11
A pure Dart package, without Flutter, for the app that the author will
write in Flutter (docs/PLAN_dart.md, stage 0):
- pubspec.yaml: the package datekeys, unpublished, for Dart 3.13; at run
time only package:crypto, and in development only package:test, which
the author approved on 5 October.
- testdata/ vendored from datekeys-go at the tag spec-v0.11 (ae33434),
124 files, with the same testdata/SOURCE.json that datekeys-ts writes for
that commit.
- tool/sync_testdata.dart, the port of scripts/sync-testdata.mjs, and
test/testdata_test.dart, which checks the copy and that every file names
specVersion; test/version_test.dart keeps pubspec.yaml and
lib/src/version.dart in step.
- tool/check.sh, the local gate: format, analysis with every info fatal,
tests, and the copy against ../datekeys-go.
- The licence, Apache-2.0, as the other two implementations.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 days ago
|
|
|
// The tests run whatever testdata/ holds, so the shared Go vectors are only as
|
|
|
|
|
// good as their integrity: a truncated or edited file must fail here rather
|
|
|
|
|
// than pass with fewer cases. The check is the one of tool/sync_testdata.dart:
|
|
|
|
|
// every file matches the SHA-256 recorded in testdata/SOURCE.json for the
|
|
|
|
|
// pinned datekeys-go commit, with none missing and none extra. And every file
|
|
|
|
|
// names the specification that this package implements.
|
Stage 1: the normative errors of section 69 and the byte helpers
- lib/src/errors.dart, the port of errors.go: ErrorCode, the 19 codes in
the order of section 69, and DateKeysException, which carries one of
them with the message of the reference, the context and then the code.
wrap and withContext are fmt.Errorf("prefix: %w"), errorCode is
datekeys.Code. test/errors_spec_test.dart reads section 69 from
../datekeys-go at the tag spec-v0.11 and compares its ERR_ lines with
the catalogue; it is skipped when that repository is missing.
- lib/src/bytes.dart, as bytes.ts of datekeys-ts: hexadecimal,
comparison and concatenation; strict UTF-8 that keeps a leading
U+FEFF, which the Utf8Decoder of dart:convert drops on the VM and on
the web; Go's utf8.DecodeRune; and Go's %q, with the table of
strconv.IsPrint of Go 1.26 copied from datekeys-ts and the SHA-256 of
the whole rune set pinned. A lone surrogate, which a Dart String may
hold, is written in generalized UTF-8, which is not UTF-8.
- lib/datekeys.dart exports the errors and the byte functions that a
user needs.
- The tests that read files are marked @TestOn('vm'), those of stage 0
included, so that the others also run compiled to JavaScript with
dart test -p node.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 days ago
|
|
|
@TestOn('vm')
|
|
|
|
|
library;
|
Stage 0: the package datekeys and its test data at spec-v0.11
A pure Dart package, without Flutter, for the app that the author will
write in Flutter (docs/PLAN_dart.md, stage 0):
- pubspec.yaml: the package datekeys, unpublished, for Dart 3.13; at run
time only package:crypto, and in development only package:test, which
the author approved on 5 October.
- testdata/ vendored from datekeys-go at the tag spec-v0.11 (ae33434),
124 files, with the same testdata/SOURCE.json that datekeys-ts writes for
that commit.
- tool/sync_testdata.dart, the port of scripts/sync-testdata.mjs, and
test/testdata_test.dart, which checks the copy and that every file names
specVersion; test/version_test.dart keeps pubspec.yaml and
lib/src/version.dart in step.
- tool/check.sh, the local gate: format, analysis with every info fatal,
tests, and the copy against ../datekeys-go.
- The licence, Apache-2.0, as the other two implementations.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 days ago
|
|
|
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:datekeys/datekeys.dart';
|
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
|
|
import '../tool/sync_testdata.dart' as testdata;
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
final root = Directory.current;
|
|
|
|
|
|
|
|
|
|
test('testdata/ matches SOURCE.json byte for byte, with no missing or extra file', () {
|
|
|
|
|
final r = testdata.check(root);
|
|
|
|
|
expect(r.errors, isEmpty);
|
|
|
|
|
expect(r.module, testdata.module);
|
|
|
|
|
expect(r.commit, matches(RegExp(r'^[0-9a-f]{40}$')));
|
|
|
|
|
expect(r.files, greaterThan(100));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('every JSON of testdata/ with a spec field names specVersion', () {
|
|
|
|
|
var named = 0;
|
|
|
|
|
final files = Directory('${root.path}/testdata')
|
|
|
|
|
.listSync(recursive: true)
|
|
|
|
|
.whereType<File>();
|
|
|
|
|
for (final f in files.where(
|
|
|
|
|
(f) => f.path.endsWith('.json') && !f.path.endsWith('SOURCE.json'),
|
|
|
|
|
)) {
|
|
|
|
|
final json = jsonDecode(f.readAsStringSync());
|
|
|
|
|
if (json is Map<String, Object?> && json.containsKey('spec')) {
|
|
|
|
|
expect(json['spec'], specVersion, reason: f.path);
|
|
|
|
|
named++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// The vectors and the record of every fixture carry it.
|
|
|
|
|
expect(named, greaterThan(40));
|
|
|
|
|
});
|
|
|
|
|
}
|