text_span_test.dart 2.21 KB
Newer Older
Adam Barth's avatar
Adam Barth committed
1 2 3 4 5
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/painting.dart';
6
import 'package:flutter_test/flutter_test.dart' show nonconst;
7
import '../flutter_test_alternative.dart';
Adam Barth's avatar
Adam Barth committed
8 9

void main() {
10
  test('TextSpan equals', () {
11 12 13 14 15 16
    final TextSpan a1 = TextSpan(text: nonconst('a'));
    final TextSpan a2 = TextSpan(text: nonconst('a'));
    final TextSpan b1 = TextSpan(children: <TextSpan>[ a1 ]);
    final TextSpan b2 = TextSpan(children: <TextSpan>[ a2 ]);
    final TextSpan c1 = TextSpan(text: nonconst(null));
    final TextSpan c2 = TextSpan(text: nonconst(null));
Adam Barth's avatar
Adam Barth committed
17 18 19 20 21 22 23 24 25 26 27 28 29

    expect(a1 == a2, isTrue);
    expect(b1 == b2, isTrue);
    expect(c1 == c2, isTrue);

    expect(a1 == b2, isFalse);
    expect(b1 == c2, isFalse);
    expect(c1 == a2, isFalse);

    expect(a1 == c2, isFalse);
    expect(b1 == a2, isFalse);
    expect(c1 == b2, isFalse);
  });
30

31
  test('TextSpan toStringDeep', () {
32
    const TextSpan test = TextSpan(
33
      text: 'a',
34
      style: TextStyle(
35
        fontSize: 10.0,
36
      ),
37 38
      children: <TextSpan>[
        TextSpan(
39
          text: 'b',
40 41
          children: <TextSpan>[
            TextSpan(),
42
          ],
43 44
        ),
        null,
45
        TextSpan(
46
          text: 'c',
47
        ),
48
      ],
49
    );
50
    expect(test.toStringDeep(), equals(
51 52 53 54 55 56 57 58
      'TextSpan:\n'
      '  inherit: true\n'
      '  size: 10.0\n'
      '  "a"\n'
      '  TextSpan:\n'
      '    "b"\n'
      '    TextSpan:\n'
      '      (empty)\n'
59
      '  <null child>\n'
60 61 62 63
      '  TextSpan:\n'
      '    "c"\n'
    ));
  });
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

  test('TextSpan toPlainText', () {
    const TextSpan textSpan = TextSpan(
      text: 'a',
      children: <TextSpan>[
        TextSpan(text: 'b'),
        TextSpan(text: 'c'),
      ],
    );
    expect(textSpan.toPlainText(), 'abc');
  });

  test('TextSpan toPlainText with semanticsLabel', () {
    const TextSpan textSpan = TextSpan(
      text: 'a',
      children: <TextSpan>[
        TextSpan(text: 'b', semanticsLabel: 'foo'),
        TextSpan(text: 'c'),
      ],
    );
    expect(textSpan.toPlainText(), 'afooc');
    expect(textSpan.toPlainText(includeSemanticsLabels: false), 'abc');
  });
Adam Barth's avatar
Adam Barth committed
87
}