o
    .j
                     @  sl   d Z ddlmZ ddlZddlmZ ddlmZ G dd dZG dd	 d	Z	G d
d dZ
G dd dZdS )z/Tests for vCard N (Name) property per RFC 6350.    )annotationsN)vN)NFieldsc                   @  s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )TestVNCreationz"Test vN creation and field access.c                 C  s(   t d}|jtddddddksJ dS )	z Create N from tuple of 5 fields.DoeJohnM.Dr.Jr.r   r   r	   r
   r   )familygiven
additionalprefixsuffixN)r   fieldsr   selfn r   [/home/thesage/.local/lib/python3.10/site-packages/icalendar/tests/rfc_6350_vcard/test_vN.pytest_n_creation_with_tuple   s   z)TestVNCreation.test_n_creation_with_tuplec                 C  s    t g d}|jjdksJ dS )zCreate N from list of 5 fields.r   r   N)r   r   r   r   r   r   r   test_n_creation_with_list   s   z(TestVNCreation.test_n_creation_with_listc                 C  s,   t d}|jjdksJ |jjdksJ dS )z"Create N from vCard format string.Doe;John;M.;Dr.;Jr.r   r   N)r   r   r   r   r   r   r   r   test_n_creation_with_string      z*TestVNCreation.test_n_creation_with_stringc                 C  s*   t ddddd}t|}|j|u sJ dS )z"Create N from NFields named tuple.r   r   r	   r
   r   N)r   r   r   )r   r   r   r   r   r   test_n_creation_with_nfields$   s   z+TestVNCreation.test_n_creation_with_nfieldsc                 C  s<   t jtdd td W d   dS 1 sw   Y  dS )zN must have exactly 5 fields.zexactly 5 fields)match)toofewN)pytestraises
ValueErrorr   )r   r   r   r   test_n_requires_5_fields*   s   
"z'TestVNCreation.test_n_requires_5_fieldsc                 C  s\   t d}|jjdksJ |jjdksJ |jjdksJ |jjdks$J |jjdks,J dS )zAccess N fields by name.)r   r   Michaelr
   r   r   r   r$   r
   r   N)r   r   r   r   r   r   r   r   r   r   r   test_n_named_field_access/   s   z(TestVNCreation.test_n_named_field_accessN)
__name__
__module____qualname____doc__r   r   r   r   r#   r%   r   r   r   r   r      s    r   c                   @  (   e Zd ZdZdd Zdd Zdd ZdS )	TestVNSerializationzTest vN to_ical and from_ical.c                 C  s    t d}| }|dksJ dS )z/N to_ical generates semicolon-separated format.r   s   Doe;John;M.;Dr.;Jr.N)r   to_ical)r   r   resultr   r   r   test_n_to_ical<   s   z"TestVNSerialization.test_n_to_icalc                 C  s4   t d}t|tsJ |tdddddksJ dS )zParse N from vCard format.r   r   r   r	   r
   r   N)r   	from_ical
isinstancer   )r   r-   r   r   r   test_n_from_icalB   s   
z$TestVNSerialization.test_n_from_icalc                 C  s:   t ddddd}t|}| }t|}||ksJ dS )z4N survives round-trip through to_ical and from_ical.r   r   r$   r
   r   N)r   r   r,   r/   )r   originalr   icalparsedr   r   r   test_n_round_tripH   s
   
z%TestVNSerialization.test_n_round_tripN)r&   r'   r(   r)   r.   r1   r5   r   r   r   r   r+   9   s
    r+   c                   @  r*   )	TestVNEscapingzTest vN escaping behavior.c                 C  s2   t d}| }d|vsJ |ddksJ dS )z2Semicolons in N are field separators, not escaped.r   s   \;   ;   N)r   r,   count)r   r   r3   r   r   r   +test_n_semicolons_not_escaped_as_separatorsT   s   z:TestVNEscaping.test_n_semicolons_not_escaped_as_separatorsc                 C  sH   t d}| }t |}|jdksJ |jdksJ |jdks"J dS )z Empty fields are preserved in N.)r   r    r;   r;   r;   N)r   r,   r/   r   r   r   r   r   r3   r4   r   r   r   test_n_empty_fields_preserved[   s   
z,TestVNEscaping.test_n_empty_fields_preservedc                 C  s8   t d}| }d|v sJ t |}|jdksJ dS )z0Commas within N fields ARE escaped per RFC 6350.)r   r   r	   r
   Jr.,M.D.,A.C.P.s   \,r>   N)r   r,   r/   r   r<   r   r   r   test_n_commas_in_suffix_escapedd   s
   
z.TestVNEscaping.test_n_commas_in_suffix_escapedN)r&   r'   r(   r)   r:   r=   r?   r   r   r   r   r6   Q   s
    	r6   c                   @  s   e Zd ZdZdd ZdS )TestVNIcalValuezTest vN ical_value property.c                 C  s,   t d}|j|jksJ t|jtsJ dS )z(ical_value property returns the NFields.r   N)r   
ical_valuer   r0   r   r   r   r   r   test_ical_value_returns_fieldsq   r   z.TestVNIcalValue.test_ical_value_returns_fieldsN)r&   r'   r(   r)   rB   r   r   r   r   r@   n   s    r@   )r)   
__future__r   r    icalendar.propr   icalendar.prop.nr   r   r+   r6   r@   r   r   r   r   <module>   s    .