"""合成离线样本检查。与同名 JSON 及文中列出的附件放在同一目录运行。"""
from pathlib import Path, PurePosixPath
import base64, hashlib, io, inspect, json, math, re, subprocess, sys, tempfile, wave, zipfile
from collections import Counter, defaultdict
from datetime import date, datetime
from decimal import Decimal
sys.dont_write_bytecode=True

def sha(b): return hashlib.sha256(b).hexdigest()
def rejected(fn):
    try: fn()
    except (ValueError,TypeError,KeyError,UnicodeError,OverflowError): return True
    return False

def git(root,*args,input=None,check=True):
    r=subprocess.run(['git','-c','core.autocrlf=false',*args],cwd=root,input=input,capture_output=True,check=check)
    return r

def verify(d,base):
    original=d['values'];source=json.dumps(original,ensure_ascii=False);parsed=json.loads(source)
    assert parsed==original;assert json.loads(json.dumps(parsed))==original
    assert len(parsed['literal'])==7 and parsed['literal'][-2:]==chr(92)+'n'
    assert chr(10) in parsed['newline'] and chr(10) not in parsed['literal']
    bad=parsed['literal'].encode('ascii').decode('unicode_escape')
    assert bad!=parsed['literal'] and chr(10) in bad
    return {'roundtrip_preserved':True,'codepoints':{k:[ord(c) for c in v] for k,v in parsed.items()},'double_decode_changed_value':True}

if __name__=='__main__':
    base=Path(__file__).resolve().parent
    data=json.loads((base/'a024.json').read_text('utf-8'))
    result=verify(data,base)
    print(json.dumps({'id':'A024','passed':True,'result':result},ensure_ascii=True))
