Skip to content
This repository has been archived by the owner on Feb 24, 2025. It is now read-only.

Commit

Permalink
tool/stats.dart --update-files updates all configs by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Apr 16, 2019
1 parent 600a1f4 commit 239ca0b
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions tool/stats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import 'package:path/path.dart' as p;

import 'stats_lib.dart';

final _configs =
List<Config>.unmodifiable([Config.commonMarkConfig, Config.gfmConfig]);

Future main(List<String> args) async {
final parser = ArgParser()
..addOption('section',
Expand All @@ -27,9 +30,7 @@ Future main(List<String> args) async {
defaultsTo: false,
help: 'Print details for "loose" matches.',
negatable: false)
..addOption('flavor',
allowed: [Config.commonMarkConfig.prefix, Config.gfmConfig.prefix],
defaultsTo: Config.commonMarkConfig.prefix)
..addOption('flavor', allowed: _configs.map((c) => c.prefix))
..addFlag('help', defaultsTo: false, negatable: false);

ArgResults options;
Expand Down Expand Up @@ -61,37 +62,47 @@ Future main(List<String> args) async {
return;
}

final testPrefix = options['flavor'] as String;

Config config;
switch (testPrefix) {
case 'gfm':
config = Config.gfmConfig;
break;
case 'common_mark':
config = Config.commonMarkConfig;
break;
default:
throw ArgumentError('Does not support `$testPrefix`.');
var testPrefix = options['flavor'] as String;
if (!updateFiles) {
testPrefix = _configs.first.prefix;
}

final testPrefixes =
testPrefix == null ? _configs.map((c) => c.prefix) : <String>[testPrefix];

for (var testPrefix in testPrefixes) {
await _processConfig(testPrefix, raw, updateFiles, verbose,
specifiedSection, verboseLooseMatch);
}
}

Future<void> _processConfig(
String testPrefix,
bool raw,
bool updateFiles,
bool verbose,
String specifiedSection,
bool verboseLooseMatch,
) async {
final config = _configs.singleWhere((c) => c.prefix == testPrefix);

var sections = loadCommonMarkSections(testPrefix);

var scores = SplayTreeMap<String, SplayTreeMap<int, CompareLevel>>(
compareAsciiLowerCaseNatural);

sections.forEach((section, examples) {
if (specifiedSection != null && section != specifiedSection) {
for (var entry in sections.entries) {
if (specifiedSection != null && entry.key != specifiedSection) {
return;
}
for (var e in examples) {
var nestedMap =
scores.putIfAbsent(section, () => SplayTreeMap<int, CompareLevel>());
for (var e in entry.value) {
var nestedMap = scores.putIfAbsent(
entry.key, () => SplayTreeMap<int, CompareLevel>());

nestedMap[e.example] = compareResult(config, e,
verboseFail: verbose, verboseLooseMatch: verboseLooseMatch);
}
});
}

if (raw || updateFiles) {
await _printRaw(testPrefix, scores, updateFiles);
Expand Down

0 comments on commit 239ca0b

Please sign in to comment.