// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'dart:typed_data';

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

void main() {
  group('ObjectExtension ', () {
    test('isNull returns true on null object', () {
      const int? myObject = null;
      expect(myObject.isNull, true);
    });
    test('isNull returns false on non-null object', () {
      // ignore: unnecessary_nullable_for_final_variable_declarations
      const int? myObject = 123;
      expect(myObject.isNull, false);
    });
    test('isNotNull returns false on null object', () {
      const int? myObject = null;
      expect(myObject.isNotNull, false);
    });
    test('isNotNull returns true on non-null object', () {
      // ignore: unnecessary_nullable_for_final_variable_declarations
      const int? myObject = 123;
      expect(myObject.isNotNull, true);
    });
  });

  group('IterableExtension ', () {
    test('isNullOrEmpty returns true on null List', () {
      const List<int>? myIterable = null;
      expect(myIterable.isNullOrEmpty, true);
    });
    test('isNullOrEmpty returns true on empty List', () {
      const List<int> myIterable = [];
      expect(myIterable.isNullOrEmpty, true);
    });
    test('isNotNullOrEmpty returns false on null List', () {
      const List<int>? myIterable = null;
      expect(myIterable.isNotNullOrEmpty, false);
    });
    test('isNotNullOrEmpty returns true on empty List', () {
      const List<int> myIterable = [];
      expect(myIterable.isNotNullOrEmpty, false);
    });
  });

  group('IterableIntExtension ', () {
    test('toTypedList() returns right Uint8List on [1, 2]', () {
      const List<int> myIterable = [1, 2];
      expect(myIterable.toTypedList(), Uint8List.fromList([1, 2]));
    });
    test('toTypedList() returns empty Uint8List on []', () {
      const List<int> myIterable = [];
      expect(myIterable.toTypedList(), Uint8List(0));
    });
    test('toStr() returns "abc" on [97,98,99]', () {
      const List<int> myIterable = [97, 98, 99];
      expect(myIterable.toStr(), 'abc');
    });

    test('toStr() returns empty String on []', () {
      const List<int> myIterable = [];
      expect(myIterable.toStr(), '');
    });
  });

  group('StringExtension ', () {
    test('isNullOrEmpty returns true on null String', () {
      const String? myString = null;
      expect(myString.isNullOrEmpty, true);
    });
    test('isNullOrEmpty returns true on empty String', () {
      const String myString = '';
      expect(myString.isNullOrEmpty, true);
    });
    test('isNotNullOrEmpty returns false on null String', () {
      const String? myString = null;
      expect(myString.isNotNullOrEmpty, false);
    });
    test('isNotNullOrEmpty returns true on empty String', () {
      const String myString = '';
      expect(myString.isNotNullOrEmpty, false);
    });
    test('toBytes() returns right Uint8List on "abc"', () {
      const String myString = 'abc';
      expect(myString.toBytes(), Uint8List.fromList([97, 98, 99]));
    });
    test('toBytes() returns empty Uint8List on empty String', () {
      const String myString = '';
      expect(myString.toBytes(), Uint8List(0));
    });
  });

  group('DateTimeExtension ', () {
    test('format() with [dd, mm, yy] works', () {
      final DateTime date = DateTime(1999, 6, 30);
      expect(date.format([dd, '/', mm, '/', yy]), '30/06/99');
    });
  });
}
