
    <e                         d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	  G d d          Z
 G d d	e
e          Z G d
 de
e          ZdS )    N)StringIO)OrderedDict)PyTestCTest)supportc                   \    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd ZdS )
TestDecodec                     |                      dt          j                  }|                     t	          |t          j                             |                     |t          j        d                     d S )Nz1.1)parse_float)loadsdecimalDecimal
assertTrue
isinstanceassertEqualselfrvals     1/usr/lib/python3.11/test/test_json/test_decode.pytest_decimalzTestDecode.test_decimal	   s]    zz%W_z==
499:::wu5566666    c                     |                      dt                    }|                     t          |t                               |                     |d           d S )N1)	parse_intg      ?)r   floatr   r   r   r   s     r   
test_floatzTestDecode.test_float   sO    zz#z//
4//000s#####r   c                     |                      |                     d          i            |                      |                     d          g            |                      |                     d          d           d S )N{}z[]z"" )r   r   )r   s    r   test_empty_objectszTestDecode.test_empty_objects   sn    D))2...D))2...D))2.....r   c                    d}g d}|                      |                     |          t          |                     |                      |                     |d           |           |                      | j                            t          |          d           |           |                     |t                    }|                      |t          |                     |                      t          |          t                     |                      |                     |t          d           t          |                     |                      |                     dt                    t                                 |                      |                     d	t                    t          d
t                      fg                     d S )Nz?{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}))xkd   )kcw   )art   )hxm   )qrt   )pad   )hoy   c                     | S N xs    r   <lambda>z3TestDecode.test_object_pairs_hook.<locals>.<lambda>   s    1 r   )object_pairs_hookc                     | S r1   r2   r3   s    r   r5   z3TestDecode.test_object_pairs_hook.<locals>.<lambda>   s    A r   c                     d S r1   r2   r3   s    r   r5   z3TestDecode.test_object_pairs_hook.<locals>.<lambda>%   s    $ r   )r6   object_hookr   z{"empty": {}}empty)r   r   evaljsonloadr   r   type)r   spods       r   test_object_pairs_hookz!TestDecode.test_object_pairs_hook   s   M1 1 1AQ000AEEqIII:E+ ( G GHI	K 	K 	KZZ[Z99[^^,,,b;///A0> $ @ @$Q	) 	) 	) 	DKHH$	( 	( 	(O6A $ C C$w&>%?@@	B 	B 	B 	B 	Br   c                 b    |                      d          }|                     |ddd           d S )Nz,{   "key"    :    "value"    ,  "k":"v"    }valuev)keyk)r   r   r   s     r   test_decoder_optimizationsz%TestDecode.test_decoder_optimizations.   s:     zzHIIg37788888r   c                      ||          }t          |d                   t          |d                   c\  }}\  }}|                     ||           |                     ||           d S )Nr   r#   )sortedassertIs)r   sourcer   r   abcds           r   check_keys_reusezTestDecode.check_keys_reuse5   sd    uV}}Q&a//AAaar   c                     d}|                      || j                   | j        j                                        }|                      ||j                   |                     |j                   d S )Nu2   [{"a_key": 1, "b_é": 2}, {"a_key": 3, "b_é": 4}])rQ   r   r<   decoderJSONDecoderdecodeassertFalsememo)r   r?   rS   s      r   test_keys_reusezTestDecode.test_keys_reuse;   si    Da,,,)#//11a000&&&&&r   c                 R    d}d}|                      | j        || j        |           d S )Nz
[1, 2, 3]5z
Extra dataassertRaisesRegexJSONDecodeErrorr   r   r?   msgs      r   test_extra_datazTestDecode.test_extra_dataB   s1    t3S$*aHHHHHr   c                 R    d}d}|                      | j        || j        |           d S )Nz	["abc\y"]escaperZ   r]   s      r   test_invalid_escapezTestDecode.test_invalid_escapeG   s1    t3S$*aHHHHHr   c                 b    d}ddg i d fD ]$}|                      t          || j        |           %d S )Nzthe JSON object must be strr#   gQ	@)r[   	TypeErrorr   )r   r^   rD   s      r   test_invalid_input_typez"TestDecode.test_invalid_input_typeL   sN    +r2t, 	F 	FE""9c4:uEEEE	F 	Fr   c                 t   d                     d                              d          }|                     | j                  5 }|                     |           d d d            n# 1 swxY w Y   |                     dt          |j                             |                     | j                  5 }| j        	                    t          |                     d d d            n# 1 swxY w Y   |                     dt          |j                             d                    d                     d                              d                    }|                     |                     |          d           |                     | j        	                    t          |                    d           d S )Nz[1,2,3]z	utf-8-sigzutf-8BOMz"{}"r   u   ﻿)encoderU   assertRaisesr\   r   assertInstr	exceptionr<   r=   r   formatr   )r   bom_jsoncm
bom_in_strs       r   test_string_with_utf8_bomz$TestDecode.test_string_with_utf8_bomQ   s   ##K0077@@t344 	!JJx   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!eS..///t344 	/INN8H--...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/eS..///]]299[#9#9#@#@#I#IJJ
J//:::(<(<==xHHHHHs$   A%%A),A)2(C&&C*-C*c                 |    | j                                         }|                     t          |j        dd           d S )N*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaai<)r<   rT   ri   
ValueError
raw_decode)r   rP   s     r   test_negative_indexzTestDecode.test_negative_index_   s7    I!!##*alFFCCCCCr   c                 .   d}t          j        |          5  |                     d|z             |                     t                    5  |                     d|dz   z             d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Ni  r   r#   )r   adjust_int_max_str_digitsr   ri   rt   )r   	maxdigitss     r   test_limit_intzTestDecode.test_limit_intc   s   	.y99 	2 	2JJsY'''"":.. 2 2

3)a-01112 2 2 2 2 2 2 2 2 2 2 2 2 2 2	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s5   3B

A2&B
2A6	6B
9A6	:B

BBN)__name__
__module____qualname__r   r   r    rB   rH   rQ   rX   r_   rb   re   rq   rv   rz   r2   r   r   r	   r	      s        7 7 7
$ $ $
/ / /
B B B,9 9 9  ' ' 'I I I
I I I
F F F
I I ID D D2 2 2 2 2r   r	   c                       e Zd ZdS )TestPyDecodeNr{   r|   r}   r2   r   r   r   r   k             r   r   c                       e Zd ZdS )TestCDecodeNr   r2   r   r   r   r   l   r   r   r   )r   ior   collectionsr   test.test_jsonr   r   testr   r	   r   r   r2   r   r   <module>r      s           # # # # # # ( ( ( ( ( ( ( (      `2 `2 `2 `2 `2 `2 `2 `2F - , , , ,:v , , , * * * * **e * * * * *r   