blob: 5571f68441cb1ed6c57224ab24acf68864583466 [file] [log] [blame]
Sigurd Meldgaardf66c7ea2020-01-16 15:27:08 +01001// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
Sigurd Meldgaardf66c7ea2020-01-16 15:27:08 +01005import 'package:protobuf/src/protobuf/permissive_compare.dart';
Kevin Moorec7e5ddf2021-07-26 15:21:14 -07006import 'package:test/test.dart';
Sigurd Meldgaardf66c7ea2020-01-16 15:27:08 +01007
8void main() {
9 void symmetric(String a, String b, bool expected) {
10 expect(permissiveCompare(a, b), expected);
11 expect(permissiveCompare(b, a), expected);
12 }
13
14 List<String> variationsFromSeed(String seed) {
15 final result = [
16 seed,
17 seed.toUpperCase(),
18 '-$seed',
19 '-${seed.toUpperCase()}',
20 '_$seed',
21 '_${seed.toUpperCase()}',
22 '$seed-',
23 '${seed}_',
24 ];
25 if (2 <= seed.length) {
26 result.add('${seed.substring(0, 1)}_${seed.substring(1)}');
27 result.add('${seed.substring(0, 1)}-${seed.substring(1)}');
28 result.add('${seed.substring(0, 1).toUpperCase()}${seed.substring(1)}');
29 result.add('${seed.substring(0, 1)}${seed.substring(1).toUpperCase()}');
30 }
31 return result;
32 }
33
34 test('permissive compare', () {
35 final seeds = ['', 'a', 'b', 'aa', 'ab', 'bb', 'aaaa'];
36 for (final a in seeds) {
37 for (final aVariant in variationsFromSeed(a)) {
38 for (final b in seeds) {
39 for (final bVariant in variationsFromSeed(b)) {
40 symmetric(aVariant, bVariant, a == b);
41 }
42 }
43 }
44 }
45 });
46}