# Path: grappa/operators/empty.py
# class EmptyOperator(Operator):
#     """
#     Asserts if a given subject is an empty object.
# 
#     A subject is considered empty if it's ``None``, ``0`` or ``len(subject)``
#     is equals to ``0``.
# 
#     Example::
# 
#         # Should style
#         [] | should.be.empty
# 
#         # Should style - negation form
#         [1, 2, 3] | should.not_be.empty
# 
#         # Expect style
#         tuple() | expect.to.be.empty
# 
#         # Expect style - negation form
#         (1, 2, 3) | expect.to_not.be.empty
#     """
# 
#     # Is the operator a keyword
#     kind = Operator.Type.ACCESSOR
# 
#     # Disable diff report
#     show_diff = False
# 
#     # Operator keywords
#     operators = ('empty',)
# 
#     # Expected template message
#     expected_message = Operator.Dsl.Message(
#         'a value that is not "None" and its length is higher than zero'
#     )
# 
#     # Subject template message
#     subject_message = Operator.Dsl.Message(
#         'an object with type "{type}" which its length cannot be measured'
#     )
# 
#     # Assertion information
#     information = (
#         Operator.Dsl.Help(
#             Operator.Dsl.Description(
#                 'An empty object can be "None", "0" or "len(x) == 0".',
#                 'Most objects in Python can be tested via "len(x)"',
#                 'such as str, list, tuple, dict, generator...',
#                 'as well as any object that implements "__len__()" method.',
#             ),
#             Operator.Dsl.Reference(
#                 'https://docs.python.org/3/library/functions.html#len'
#             ),
#         ),
#     )
# 
#     def match(self, subject):
#         if subject is None or subject is 0:  # noqa F632
#             return True
# 
#         if subject in (True, False):
#             return False
# 
#         if isinstance(subject, numbers.Number) and subject != 0:
#             return False
# 
#         try:
#             return len(subject) == 0
#         except TypeError:
#             try:
#                 next(subject)
#             except StopIteration:
#                 return True
#             except Exception:
#                 return True
#         return False


import pytest
from grappa.operators.empty import EmptyOperator
        iter([1, 2, 3]) | expect.to.be.empty


def test_empty_operator(ctx):
    assert EmptyOperator(ctx).match(0) is True
    assert EmptyOperator(ctx).match(None) is True
    assert EmptyOperator(ctx).match('') is True
    assert EmptyOperator(ctx).match(iter([])) is True

    assert EmptyOperator(ctx).match(True) is False
    assert EmptyOperator(ctx).match(False) is False
    assert EmptyOperator(ctx).match('foo') is False
    assert EmptyOperator(ctx).match(123) is False
    assert EmptyOperator(ctx).match(0.2321) is False
    assert EmptyOperator(ctx).match(iter([1, 2, 3])) is False


def test_empty_operator_properties(should):
    (EmptyOperator
        | should.have.property('kind')
        > should.be.equal.to('accessor'))

    (EmptyOperator
        | should.have.property('operators')
        > should.have.length.of(1)
        > should.be.equal.to(('empty',)))

    EmptyOperator | should.have.property('aliases') > should.be.empty

    EmptyOperator | should.have.property('expected_message')

# Path: grappa/operators/empty.py
# class EmptyOperator(Operator):
#     """
#     Asserts if a given subject is an empty object.
# 
#     A subject is considered empty if it's ``None``, ``0`` or ``len(subject)``
#     is equals to ``0``.
# 
#     Example::
# 
#         # Should style
#         [] | should.be.empty
# 
#         # Should style - negation form
#         [1, 2, 3] | should.not_be.empty
# 
#         # Expect style
#         tuple() | expect.to.be.empty
# 
#         # Expect style - negation form
#         (1, 2, 3) | expect.to_not.be.empty
#     """
# 
#     # Is the operator a keyword
#     kind = Operator.Type.ACCESSOR
# 
#     # Disable diff report
#     show_diff = False
# 
#     # Operator keywords
#     operators = ('empty',)
# 
#     # Expected template message
#     expected_message = Operator.Dsl.Message(
#         'a value that is not "None" and its length is higher than zero'
#     )
# 
#     # Subject template message
#     subject_message = Operator.Dsl.Message(
#         'an object with type "{type}" which its length cannot be measured'
#     )
# 
#     # Assertion information
#     information = (
#         Operator.Dsl.Help(
#             Operator.Dsl.Description(
#                 'An empty object can be "None", "0" or "len(x) == 0".',
#                 'Most objects in Python can be tested via "len(x)"',
#                 'such as str, list, tuple, dict, generator...',
#                 'as well as any object that implements "__len__()" method.',
#             ),
#             Operator.Dsl.Reference(
#                 'https://docs.python.org/3/library/functions.html#len'
#             ),
#         ),
#     )
# 
#     def match(self, subject):
#         if subject is None or subject is 0:  # noqa F632
#             return True
# 
#         if subject in (True, False):
#             return False
# 
#         if isinstance(subject, numbers.Number) and subject != 0:
#             return False
# 
#         try:
#             return len(subject) == 0
#         except TypeError:
#             try:
#                 next(subject)
#             except StopIteration:
#                 return True
#             except Exception:
#                 return True
#         return False


# Path: tests/operators/empty_test.py
import pytest
from grappa.operators.empty import EmptyOperator

        iter([1, 2, 3]) | expect.to.be.empty


def test_empty_operator(ctx):
    assert EmptyOperator(ctx).match(0) is True
    assert EmptyOperator(ctx).match(None) is True
    assert EmptyOperator(ctx).match('') is True
    assert EmptyOperator(ctx).match(iter([])) is True

    assert EmptyOperator(ctx).match(True) is False
    assert EmptyOperator(ctx).match(False) is False
    assert EmptyOperator(ctx).match('foo') is False
    assert EmptyOperator(ctx).match(123) is False
    assert EmptyOperator(ctx).match(0.2321) is False
    assert EmptyOperator(ctx).match(iter([1, 2, 3])) is False


def test_empty_operator_properties(should):
    (EmptyOperator
        | should.have.property('kind')
        > should.be.equal.to('accessor'))

    (EmptyOperator
        | should.have.property('operators')
        > should.have.length.of(1)
        > should.be.equal.to(('empty',)))

    EmptyOperator | should.have.property('aliases') > should.be.empty

    EmptyOperator | should.have.property('expected_message')

    EmptyOperator | should.have.property('subject_message')