|
| 1 | +// 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 | + |
| 5 | +import 'package:test/test.dart'; |
| 6 | +import 'package:protobuf/src/protobuf/permissive_compare.dart'; |
| 7 | + |
| 8 | +void 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 | +} |
0 commit comments