o
    q!ågÑ  ã                   @   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)ÚselfÚexpr1Úexpr2Úmsg© r   ú]/mnt/skqttb/ctump_chatbot/chatbot/lib/python3.10/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   óP   |   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   ó   zTestDecode.test_empty_stringsc                 C   r4   )Nz''r5   z['']r6   r7   r   r   r   Ú%test_empty_strings_with_single_quotes7   r9   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)rG   )Úindexr   r   r   )r   r%   Ú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)ÚonceÚtwiceÚthree_times3)rD   rE   rF   Ú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@   rC   r    rO   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.   r2   r3   r8   r:   r<   rJ   rP   rQ   r   r   r   r   r      s     

r   )Ú
__future__r   r   Úunittestr   r   r   r   r   r   r   Ú<module>   s
    