text_span_test.dart 1.81 KB
Newer Older
Adam Barth's avatar
Adam Barth committed
1 2 3 4 5 6 7 8 9
// 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';

import 'package:test/test.dart';

void main() {
10
  test('TextSpan equals', () {
11 12 13 14 15
    final String text = 'a'; // we want these instances to be separate instances so that we're not just checking with a single object
    final TextSpan a1 = new TextSpan(text: text);
    final TextSpan a2 = new TextSpan(text: text);
    final TextSpan b1 = new TextSpan(children: <TextSpan>[ a1 ]);
    final TextSpan b2 = new TextSpan(children: <TextSpan>[ a2 ]);
16
    String nullText; // we want these instances to be separate instances so that we're not just checking with a single object
17 18
    final TextSpan c1 = new TextSpan(text: nullText);
    final TextSpan c2 = new TextSpan(text: nullText);
Adam Barth's avatar
Adam Barth committed
19 20 21 22 23 24 25 26 27 28 29 30 31

    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);
  });
32

33
  test('TextSpan', () {
34
    final TextSpan test = const TextSpan(
35
      text: 'a',
36
      style: const TextStyle(
37 38
        fontSize: 10.0
      ),
39 40
      children: const <TextSpan>[
        const TextSpan(
41
          text: 'b',
42 43
          children: const <TextSpan>[
            const TextSpan()
44 45 46
          ]
        ),
        null,
47
        const TextSpan(
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
          text: 'c'
        ),
      ]
    );
    expect(test.toString(), equals(
      'TextSpan:\n'
      '  inherit: true\n'
      '  size: 10.0\n'
      '  "a"\n'
      '  TextSpan:\n'
      '    "b"\n'
      '    TextSpan:\n'
      '      (empty)\n'
      '  <null>\n'
      '  TextSpan:\n'
      '    "c"\n'
    ));
  });
Adam Barth's avatar
Adam Barth committed
66
}