licenses_test.dart 5.03 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
6
import 'package:flutter_test/flutter_test.dart';
7 8 9 10 11

void main() {
  test('LicenseEntryWithLineBreaks - most cases', () {
    // There's some trailing spaces in this string.
    // To avoid IDEs stripping them, I've escaped them as \u0020.
12
    final List<LicenseParagraph> paragraphs = const LicenseEntryWithLineBreaks(<String>[], '''
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
A
A
A
  B
B
B
   C
C
C
                  D
D
D

E
E
 F
  G
 G
G

[H
 H
 H]
\u0020\u0020
37 38
I\u000cJ
\u000cK
39
K
40
\u000c
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
L
L L
L  L
L   L
L    L
L     L

   M
M\u0020\u0020\u0020
M\u0020\u0020\u0020\u0020

N

O
O


P



QQQ

RR RRR RRRR RRRRR
R

S

   T

      U
         V

        W

       X
\u0020\u0020\u0020\u0020\u0020\u0020
      Y''').paragraphs.toList();

    int index = 0;
    expect(paragraphs[index].text, 'A A A');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'B B B');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'C C C');
    expect(paragraphs[index].indent, 1);
    index += 1;
    expect(paragraphs[index].text, 'D D D');
    expect(paragraphs[index].indent, LicenseParagraph.centeredIndent);
    index += 1;
    expect(paragraphs[index].text, 'E E');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'F');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'G G G');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, '[H H H]');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'I');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'J');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'K K');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'L L L L  L L   L L    L L     L');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'M M    M    ');
    expect(paragraphs[index].indent, 1);
    index += 1;
    expect(paragraphs[index].text, 'N');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'O O');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'P');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'QQQ');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'RR RRR RRRR RRRRR R');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'S');
    expect(paragraphs[index].indent, 0);
    index += 1;
    expect(paragraphs[index].text, 'T');
    expect(paragraphs[index].indent, 1);
    index += 1;
    expect(paragraphs[index].text, 'U');
    expect(paragraphs[index].indent, 2);
    index += 1;
    expect(paragraphs[index].text, 'V');
    expect(paragraphs[index].indent, 3);
    index += 1;
    expect(paragraphs[index].text, 'W');
    expect(paragraphs[index].indent, 2);
    index += 1;
    expect(paragraphs[index].text, 'X');
    expect(paragraphs[index].indent, 2);
    index += 1;
    expect(paragraphs[index].text, 'Y');
    expect(paragraphs[index].indent, 2);
    index += 1;
    expect(paragraphs, hasLength(index));
  });

  test('LicenseEntryWithLineBreaks - leading and trailing whitespace', () {
160 161
    expect(const LicenseEntryWithLineBreaks(<String>[], '    \n\n    ').paragraphs.toList(), isEmpty);
    expect(const LicenseEntryWithLineBreaks(<String>[], '    \r\n\r\n    ').paragraphs.toList(), isEmpty);
162 163 164

    List<LicenseParagraph> paragraphs;

165
    paragraphs = const LicenseEntryWithLineBreaks(<String>[], '    \nA\n    ').paragraphs.toList();
166 167 168 169
    expect(paragraphs[0].text, 'A');
    expect(paragraphs[0].indent, 0);
    expect(paragraphs, hasLength(1));

170
    paragraphs = const LicenseEntryWithLineBreaks(<String>[], '\n\n\nA\n\n\n').paragraphs.toList();
171 172 173 174 175
    expect(paragraphs[0].text, 'A');
    expect(paragraphs[0].indent, 0);
    expect(paragraphs, hasLength(1));
  });

Ian Hickson's avatar
Ian Hickson committed
176 177 178
  test('LicenseRegistry', () async {
    expect(await LicenseRegistry.licenses.toList(), isEmpty);
    LicenseRegistry.addLicense(() async* {
179 180
      yield const LicenseEntryWithLineBreaks(<String>[], 'A');
      yield const LicenseEntryWithLineBreaks(<String>[], 'B');
181
    });
Ian Hickson's avatar
Ian Hickson committed
182
    LicenseRegistry.addLicense(() async* {
183 184
      yield const LicenseEntryWithLineBreaks(<String>[], 'C');
      yield const LicenseEntryWithLineBreaks(<String>[], 'D');
185
    });
Ian Hickson's avatar
Ian Hickson committed
186
    expect(await LicenseRegistry.licenses.toList(), hasLength(4));
187
    final List<LicenseEntry> licenses = await LicenseRegistry.licenses.toList();
188 189 190 191 192 193 194
    expect(licenses, hasLength(4));
    expect(licenses[0].paragraphs.single.text, 'A');
    expect(licenses[1].paragraphs.single.text, 'B');
    expect(licenses[2].paragraphs.single.text, 'C');
    expect(licenses[3].paragraphs.single.text, 'D');
  });
}