mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-07-08 10:15:53 +08:00
98 lines
3.8 KiB
Dart
98 lines
3.8 KiB
Dart
// Copyright 2017 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_web/services.dart';
|
|
import '../flutter_test_alternative.dart';
|
|
|
|
void main() {
|
|
group('TextInputConfiguration', () {
|
|
test('sets expected defaults', () {
|
|
const TextInputConfiguration configuration = TextInputConfiguration();
|
|
expect(configuration.inputType, TextInputType.text);
|
|
expect(configuration.obscureText, false);
|
|
expect(configuration.autocorrect, true);
|
|
expect(configuration.actionLabel, null);
|
|
expect(configuration.textCapitalization, TextCapitalization.none);
|
|
expect(configuration.keyboardAppearance, Brightness.light);
|
|
});
|
|
|
|
test('text serializes to JSON', () async {
|
|
const TextInputConfiguration configuration = TextInputConfiguration(
|
|
inputType: TextInputType.text,
|
|
obscureText: true,
|
|
autocorrect: false,
|
|
actionLabel: 'xyzzy',
|
|
);
|
|
final Map<String, dynamic> json = configuration.toJson();
|
|
expect(json['inputType'], <String, dynamic>{
|
|
'name': 'TextInputType.text',
|
|
'signed': null,
|
|
'decimal': null
|
|
});
|
|
expect(json['obscureText'], true);
|
|
expect(json['autocorrect'], false);
|
|
expect(json['actionLabel'], 'xyzzy');
|
|
});
|
|
|
|
test('number serializes to JSON', () async {
|
|
const TextInputConfiguration configuration = TextInputConfiguration(
|
|
inputType: TextInputType.numberWithOptions(decimal: true),
|
|
obscureText: true,
|
|
autocorrect: false,
|
|
actionLabel: 'xyzzy',
|
|
);
|
|
final Map<String, dynamic> json = configuration.toJson();
|
|
expect(json['inputType'], <String, dynamic>{
|
|
'name': 'TextInputType.number',
|
|
'signed': false,
|
|
'decimal': true
|
|
});
|
|
expect(json['obscureText'], true);
|
|
expect(json['autocorrect'], false);
|
|
expect(json['actionLabel'], 'xyzzy');
|
|
});
|
|
|
|
test('basic structure', () async {
|
|
const TextInputType text = TextInputType.text;
|
|
const TextInputType number = TextInputType.number;
|
|
const TextInputType number2 = TextInputType.numberWithOptions();
|
|
const TextInputType signed =
|
|
TextInputType.numberWithOptions(signed: true);
|
|
const TextInputType signed2 =
|
|
TextInputType.numberWithOptions(signed: true);
|
|
const TextInputType decimal =
|
|
TextInputType.numberWithOptions(decimal: true);
|
|
const TextInputType signedDecimal =
|
|
TextInputType.numberWithOptions(signed: true, decimal: true);
|
|
|
|
expect(text.toString(),
|
|
'TextInputType(name: TextInputType.text, signed: null, decimal: null)');
|
|
expect(number.toString(),
|
|
'TextInputType(name: TextInputType.number, signed: false, decimal: false)');
|
|
expect(signed.toString(),
|
|
'TextInputType(name: TextInputType.number, signed: true, decimal: false)');
|
|
expect(decimal.toString(),
|
|
'TextInputType(name: TextInputType.number, signed: false, decimal: true)');
|
|
expect(signedDecimal.toString(),
|
|
'TextInputType(name: TextInputType.number, signed: true, decimal: true)');
|
|
|
|
expect(text == number, false);
|
|
expect(number == number2, true);
|
|
expect(number == signed, false);
|
|
expect(signed == signed2, true);
|
|
expect(signed == decimal, false);
|
|
expect(signed == signedDecimal, false);
|
|
expect(decimal == signedDecimal, false);
|
|
|
|
expect(text.hashCode == number.hashCode, false);
|
|
expect(number.hashCode == number2.hashCode, true);
|
|
expect(number.hashCode == signed.hashCode, false);
|
|
expect(signed.hashCode == signed2.hashCode, true);
|
|
expect(signed.hashCode == decimal.hashCode, false);
|
|
expect(signed.hashCode == signedDecimal.hashCode, false);
|
|
expect(decimal.hashCode == signedDecimal.hashCode, false);
|
|
});
|
|
});
|
|
}
|