a
    hŃ  ć                   @   s<   d dl mZ d dlZd dlmZ d dlZG dd deZdS )é    )Śabsolute_importN)ŚTestCasec                   @   s   e Zd ZeedsdddZdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS ) Ś
TestDecodeŚassertIsNc                 C   s    |   ||u |pd||f ” d S )Nz%r is %r)Ś
assertTrue)ŚselfZexpr1Zexpr2Śmsg© r	   śc/home/qiu/health_record_app/backend/venv/lib/python3.9/site-packages/dirtyjson/tests/test_decode.pyr   
   s    zTestDecode.assertIsc                 C   s8   t jdtjd}|  t|tj” |  |t d”” d S )Nz1.1)Śparse_float)Ś	dirtyjsonŚloadsŚdecimalŚDecimalr   Ś
isinstanceŚassertEqual©r   Śrvalr	   r	   r
   Śtest_decimal   s    zTestDecode.test_decimalc                 C   s.   t jdtd}|  t|t” |  |d” d S )NŚ1)Ś	parse_intg      š?)r   r   Śfloatr   r   r   r   r	   r	   r
   Ś
test_float   s    zTestDecode.test_floatc                 C   s    t  d”}|  |ddd” d S )Nz,{   "key"    :    "value"    ,  "k":"v"    }ŚvalueŚv©ŚkeyŚk©r   r   r   r   r	   r	   r
   Śtest_decoder_optimizations   s    
z%TestDecode.test_decoder_optimizationsc                 C   sR   d}|   t |”t|” d}|   t |”t|” d}|   t |”t|” d S )Nz{}z[]ś"")r   r   r   Śeval©r   Śsr	   r	   r
   Śtest_empty_objects   s    zTestDecode.test_empty_objectsc                 C   sF   ||}t |d t |d  \}}\}}|  ||” |  ||” d S )Nr   é   )Śsortedr   )r   Śsourcer   r   ŚaŚbŚcŚdr	   r	   r
   Ścheck_keys_reuse#   s    "zTestDecode.check_keys_reusec                 C   s   d  d”}|  |tj” d S )Nõ2   [{"a_key": 1, "b_Ć©": 2}, {"a_key": 3, "b_Ć©": 4}]Śutf8)Śencoder,   r   r   r"   r	   r	   r
   Śtest_keys_reuse_str)   s    
zTestDecode.test_keys_reuse_strc                 C   s   d}|   |tj” d S )Nr-   )r,   r   r   r"   r	   r	   r
   Śtest_keys_reuse_unicode-   s    z"TestDecode.test_keys_reuse_unicodec                 C   sP   |   t d”d” |   t d”d” |   t d”dg” |   t d”dg” d S )Nr    Ś z[""]©r   r   r   ©r   r	   r	   r
   Śtest_empty_strings1   s    zTestDecode.test_empty_stringsc                 C   sP   |   t d”d” |   t d”d” |   t d”dg” |   t d”dg” d S )Nz''r2   z['']r3   r4   r	   r	   r
   Ś%test_empty_strings_with_single_quotes7   s    z0TestDecode.test_empty_strings_with_single_quotesc                 C   sf   ddd}t  d”}|  ||” t  d”}|  ||” t  d”}|  ||” t  d”}|  ||” d S )Nr   r   r   z{"key": "value", "k": "v"}z{'key': 'value', 'k': 'v'}z{key: 'value', k: 'v'}z{key: 'value', k: 'v',}r   )r   Śresultr   r	   r	   r
   Śtest_object_keys=   s    




zTestDecode.test_object_keysc                 C   s   d}|  d”}tj||d}|  |ddg d¢d” tj||d dd	}|  |g d¢” tj|dd
}|  |ddg d¢d” d S )Nz
// here are some comments
var a = 1; // here is a line of regular JS

var b = {test: 1, 'aack': 0x80, "bar": [1, 2, 3]};
console.log(b);
Ś{)Śstart_indexr%   é   ©r%   é   é   ©ŚtestŚaackŚbarT)r:   Śsearch_for_first_object)rC   )Śindexr   r   r   )r   r#   Zfirst_object_indexr   r	   r	   r
   Śtest_not_at_beginningH   s    
z TestDecode.test_not_at_beginningc              
   C   s4   d}t  |”}|  |ddg d¢ddd dd” d S )	Nan  
// here are some comments
{
    // comments inside too
    test: 1,    // and at the end of lines
    'aack': 0x80,
    "bar": [ // even inside arrays
        1,
        2,
        3, // and after trailing commas
    ],
    more: { // and inside objects
        once: true,
        twice: false,
        three_times3: null // and at the end
    }
}
console.log(b);
r%   r;   r<   TF)ŚonceZtwiceZthree_times3)r@   rA   rB   Śmorer   ©r   r#   r   r	   r	   r
   Ś test_ignore_single_line_comments[   s    
z+TestDecode.test_ignore_single_line_commentsc                 C   s*   d}t  |”}|  |ddg d¢d” d S )Na×  
/* here are some comments
 * that should all be skipped
 * right up until the terminator */ {
    /* comments inside too */
    test: 1,    /* and at the end of lines */
    'aack': 0x80,
    "bar": [ // even inside arrays
        1,
        2,
        3, // and after trailing commas
    ],
    /* comment this block out
    more: { // and inside objects
        once: true,
        twice: false,
        three_times3: null // and at the end
    } */
}
console.log(b);
r%   r;   r<   r?   r   rH   r	   r	   r
   Śtest_ignore_inline_commentsr   s    
z&TestDecode.test_ignore_inline_comments)N)Ś__name__Ś
__module__Ś__qualname__Śhasattrr   r   r   r   r   r$   r,   r0   r1   r5   r6   r8   rE   rI   rJ   r	   r	   r	   r
   r      s   

r   )Ś
__future__r   r   Zunittestr   r   r   r	   r	   r	   r
   Ś<module>   s   