fluent_assertions 0.4.0 icon indicating copy to clipboard operation
fluent_assertions: ^0.4.0 copied to clipboard

Fluent Assertions library written in Dart.

example/fluent_assertions_example.dart

import 'package:fluent_assertions/fluent_assertions.dart';
import 'package:test/test.dart';

void main() {
  const adult = Person(name: 'Karol', age: 30);
  const teenager = Person(name: 'Karyna', age: 17);

  test('different persons should not be equal', () {
    adult.shouldNotBeEqualTo(teenager);
  });

  test('person name should not be null', () {
    adult.name.shouldNotBeNull();
  });

  test('person age should be integer', () {
    adult.age.shouldBeInstanceOf<int>();
  });

  test('a person over 18 should be adult', () {
    adult.isAdult.shouldBeTrue();
  });

  test('an adult person should be over 18', () {
    adult.age.shouldBeGreaterOrEqualTo(18);
  });

  test('a teenager can driver a car', () {
    teenager.age.shouldBeGreaterThan(16);
  });

  test('a teenager should be below 18', () {
    teenager.age.shouldBeLessThan(18);
  });

  test('a teenager should be below 18', () {
    teenager.age.shouldBeInRange(lowerBound: 0, upperBound: 17);
  });

  test('a person age should be positive', () {
    teenager.age.shouldBePositive();
  });

  test('a person name should not be null or blank', () {
    adult.name.shouldNotBeNullOrBlank();
  });

  test('a person name should contain only letters', () {
    adult.name.shouldMatch(RegExp('[a-zA-Z]'));
  });
}

class Person {
  final String name;
  final int age;
  bool get isAdult => age >= 18;

  const Person({
    required this.name,
    required this.age,
  });

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is Person &&
          runtimeType == other.runtimeType &&
          name == other.name &&
          age == other.age;

  @override
  int get hashCode => name.hashCode ^ age.hashCode;

  @override
  String toString() => '$name ($age)';
}
3
likes
120
pub points
64%
popularity

Publisher

verified publisher iconklisiewicz.dev

Fluent Assertions library written in Dart.

Homepage

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

test

More

Packages that depend on fluent_assertions