def expand(s, wrap=False, stdlib=False):
    data = expand_string(s)
    return pycket_json.loads(data) def _is_ascii(s):
def _is_ascii_elidable(s):
    def fromstr_utf8(s, immutable=False):
    def fromascii(s, immutable=False):
    def fromunicode(u, immutable=False):
    def make(val):
    def make_immutable(self):
    def get_strategy(self):
    def get_storage(self):
    def as_str_ascii(self):
    def as_str_utf8(self):
    def as_unicode(self):
    def as_charlist_ascii(self):
    def as_charlist_utf8(self):
    def as_unicharlist(self):
    def as_escaped_utf8(self):
    def length(self):
    def getitem(self, index):
    def getslice(self, start, stop):
    def hash_equal(self, info=None):
    def equal(self, other):
    def cmp(self, other):
    def cmp_case_insensitive(self, other):
    def upper(self):
    def lower(self):
    def __repr__(self):
    def tostring(self):
    def setitem(self, index, unichar):
    def setslice(self, index, w_from, fromstart, fromend):
    def __init__(self, strategy, storage):
    def get_strategy(self):
    def get_storage(self):
    def change_strategy(self, strategy, storage):
    def make_immutable(self):
    def immutable(self):
    def setitem(self, index, unichar):
    def setslice(self, index, w_from, fromstart, fromend):
    def __init__(self, strategy, storage):
    def make_immutable(self):
    def immutable(self):
    def get_storage(self):
    def get_strategy(self):
    def get_strategy(self):
    def make_mutable(self, w_str):
    def as_str_ascii(self, w_str):
    def as_str_utf8(self, w_str):
    def as_unicode(self, w_str):
    def as_charlist_ascii(self, w_str):
    def as_charlist_utf8(self, w_str):
    def as_unicharlist(self, w_str):
    def length(self, w_str):
    def getitem(self, w_str, index):
    def getslice(self, w_str, start, stop):
    def eq(self, w_str, w_other):
    def cmp(self, w_str, w_other):
    def cmp_case_insensitive(self, w_str, w_other):
    def hash(self, w_str):
    def upper(self, w_str):
    def lower(self, w_str):
    def setitem(self, w_str, index, unichar):
    def setslice(self, w_str, index, w_from, fromstart, fromend):
    def as_charlist_ascii(self, w_str):
    def as_charlist_utf8(self, w_str):
    def as_unicharlist(self, w_str):
    def setitem(self, w_str, index, unichar):
    def setslice(self, w_str, index, w_from, fromstart, fromend):
    def as_str_ascii(self, w_str):
    def as_str_utf8(self, w_str):
    def as_unicode(self, w_str):
    def make_mutable(self, w_str):
    def setitem(self, w_str, index, unichar):
    def setslice(self, w_str, index, w_from, fromstart, fromend):
    def make_mutable(self, w_str):
    def as_str_utf8(self, w_str):
    def as_unicode(self, w_str):
    def length(self, w_str):
    def getitem(self, w_str, index):
    def getslice(self, w_str, start, stop):
    def eq(self, w_str, w_other):
    def hash(self, w_str):
    def upper(self, w_str):
    def lower(self, w_str):
    def make_unicode(self, w_str):
    def as_charlist_utf8(self, w_str):
    def as_unicharlist(self, w_str):
    def as_str_utf8(self, w_str):
    def length(self, w_str):
    def getitem(self, w_str, index):
    def getslice(self, w_str, start, stop):
    def eq(self, w_str, w_other):
    def setitem(self, w_str, index, unichar):
    def setslice(self, w_str, index, w_from, fromstart, fromend):
    def upper(self, w_str):
    def lower(self, w_str):
    def make_mutable(self, w_str):
    def as_str_ascii(self, w_str):
    def as_str_utf8(self, w_str):
    def as_unicode(self, w_str):
    def length(self, w_str):
    def getitem(self, w_str, index):
    def getslice(self, w_str, start, stop):
    def eq(self, w_str, w_other):
    def upper(self, w_str):
    def lower(self, w_str):
    def as_charlist_ascii(self, w_str):
    def as_charlist_utf8(self, w_str):
    def as_str_utf8(self, w_str):
    def as_unicharlist(self, w_str):
    def as_unicode(self, w_str):
    def length(self, w_str):
    def getitem(self, w_str, index):
    def getslice(self, w_str, start, stop):
    def eq(self, w_str, w_other):
    def setitem(self, w_str, index, unichar):
    def setslice(self, w_str, index, w_from, fromstart, fromend):
    def upper(self, w_str):
    def lower(self, w_str):
class W_String(W_Object):
class W_MutableString(W_String):
class W_ImmutableString(W_String):
class W_AsciiImmutableString(W_ImmutableString):
class W_UnicodeImmutableString(W_ImmutableString):
class StringStrategy(object):
class ImmutableStringStrategy(StringStrategy):
class MutableStringStrategy(StringStrategy):
class AsciiStringStrategy(ImmutableStringStrategy):
class AsciiMutableStringStrategy(MutableStringStrategy):
class UnicodeStringStrategy(ImmutableStringStrategy):
class UnicodeMutableStringStrategy(MutableStringStrategy): def run(p, v=None, stdlib=False, extra="", expect_to_fail=False):
    if pytest.config.new_pycket:
        return run_expr_result(p, expect_to_fail=expect_to_fail, v=v)
    return run_mod_expr(p,v=v,stdlib=stdlib, extra=extra) def run_fix(p, v=None, stdlib=False, extra="", equal_huh=False):
    new = pytest.config.new_pycket
    if new:
        return run_expr(p, v, equal_huh=equal_huh)
    ov = run_mod_expr(p,stdlib=stdlib, extra=extra)
    assert isinstance(ov, values.W_Fixnum)
    if v is not None:
        assert ov.value == v
    return ov.value def run_flo(p, v=None, stdlib=False, extra=""):
    ov = run_mod_expr(p,stdlib=stdlib, extra=extra)
    assert isinstance(ov, values.W_Flonum)
    if v is not None:
        assert ov.value == v
    return ov.value def run_top(p, v=None, stdlib=False, extra=""):
    return run_mod_expr(p,v=v,stdlib=stdlib, wrap=True, extra=extra) def execute(p, stdlib=False, extra=""):
    return run_mod_expr(p, stdlib=stdlib, extra=extra) def run_values(p, stdlib=False):
    e = "(call-with-values (lambda () %s) list)"%p
    v = run_mod_expr(e, stdlib=stdlib)
    return values.from_list(v) def check_equal(*pairs_of_equal_stuff, **kwargs):
    code = []
    tail = []
    assert len(pairs_of_equal_stuff) % 2 == 0
    ind = 0
    for i in range(len(pairs_of_equal_stuff) // 2):
        a = pairs_of_equal_stuff[i * 2]
        b = pairs_of_equal_stuff[i * 2 + 1]
        ind += 1
        if isinstance(a, list):
            code.append("  " * ind + "(let ()")
            ind += 1
            code.extend(["  " * ind + x for x in a[:-1]])
            code.append( "  " * ind + ("(if (equal? %s %s)" % (a[-1], b)))
            ind += 1
            tail.append("  " * ind + "%s))" % i)
        else:
            snippet = "(equal? %s %s)" % (a, b)
            code.append("  " * ind + "(if %s" % snippet)
            tail.append("  " * (ind + 1) + "%s)" % i)
    code.append("  " * (ind + 1) + "#t")
    code = "\n".join(code) + "\n" + "\n".join(reversed(tail))
    try:
        print code
    except UnicodeEncodeError:
        print code.encode("ascii", 'replace')

    extra = kwargs.get("extra", "")
    res = execute(code, extra=extra)
    if res is not values.w_true:
        src = pairs_of_equal_stuff[res.value * 2]
        if isinstance(src, list):
            src = "(let ()\n" + "\n".join(src) + ")"
        wrong = execute(src, extra=extra)
        assert 0, u"%s is %s, which is different from %s" % (
            pairs_of_equal_stuff[res.value * 2], wrong.tostring(),
            pairs_of_equal_stuff[res.value * 2 + 1]) def run_mod(m, stdlib=False, srcloc=True):
    assert not stdlib
    if not pytest.config.byte_option:
        ast = parse_module(expand_string(m, srcloc=srcloc))
    else:
        ast = parse_module(expand_from_bytecode(m, srcloc), bytecode_expand=True)

    return run_ast(ast)
import pytest
from pycket.expand import expand
from pycket.interpreter import *
from pycket.values import *
from pycket import values_string
from pycket.prims import *
from pycket.test.testhelper import (run, run_fix, run_flo, run_top, execute,
        run_values, check_equal, run_mod)
    from pycket.expand    import expand_string, parse_module
    from pycket           import config
    from pycket.callgraph import LOOP_PARTICIPANT, LOOP_HEADER
    from pycket.env       import w_global_config as conf
    from pycket.expand import expand_string, parse_module
    from pycket        import config
    from pycket.env    import w_global_config as conf
    from pycket.expand import expand_string, parse_module
    from pycket        import config
    from pycket.env    import w_global_config as conf
             (eqv? f g))""",
        w_false)
    run("(eqv? (quote a) (quote a))", w_true) #racket
    # run('(eqv? "a" "a")', w_true) #racket
    run("(eqv? (quote b) (cdr (quote (a b))))", w_false) #racket
    run("""(let-values (((x) (quote a)))
           (eqv? x x))""", w_true)

def test_eqv_doc(doctest):
    """
    > (eqv? 0.0 -0.0)
    #f
    """

@pytest.mark.skipif(pytest.config.new_pycket and not pytest.config.load_expander, reason="normalizer issues")
def test_caselambda():
    run("(case-lambda [(x) 1])")
    run("(case-lambda [(x) x])")
    run("(case-lambda [() 0])")
    run("(case-lambda [() 0] [(x) x])")
    run("(case-lambda [x 0])")
    run("((case-lambda [() #f]))", w_false)
    run("((case-lambda [(x) #f]) 0)", w_false)
    run("((case-lambda [() 0] [(x) x]) #f)", w_false)
    run("((case-lambda [x #t] [(x) x]) #f)", w_true)
    run("((case-lambda [x (car x)] [(x) x]) #f #t 17)", w_false)
    run("((case-lambda [(x) x] [x (car x)]) #f #t 17)", w_false)

def test_begin0():
    run_fix("(begin0 1 2)", 1)
    run_fix("(begin0 1)", 1)
    run_fix("(begin0 1 2 3)", 1)
    v = run_values("(begin0 (values #t #f) 2 3)")
    assert v == [w_true, w_false]
    run_fix("(let-values ([(x) 1]) (begin0 x (set! x 2)))", 1)
    run_fix("(let-values ([(x) 10]) (begin0 (set! x 0) (set! x (+ x 1))) x)", 1)

def test_varref():
    run("(#%variable-reference)")
    run("(#%variable-reference add1)")
    run("(let-values ([(x) 0]) (#%variable-reference x))")
    run("(let-values ([(x) 0]) (variable-reference-constant? (#%variable-reference x)))", w_true)
    run("(let-values ([(x) 0]) (set! x 1) (variable-reference-constant? (#%variable-reference x)))", w_false)

def test_with_continuation_mark():
    m = run_mod(
    """
    #lang pycket
    (define key (make-continuation-mark-key))
    (define result
      (with-continuation-mark key "quiche"
        (with-continuation-mark key "ham"
           (continuation-mark-set-first
            (current-continuation-marks)
            key))))
    """)
    sym = W_Symbol.make("result")
    assert isinstance(m.defs[sym], values_string.W_String)
    assert m.defs[sym].as_str_utf8() == "ham"

def test_with_continuation_mark2(doctest):
    u"""
    > (with-continuation-mark 'hello 'bye (let ([x (call-with-immediate-continuation-mark 'hello (λ (x) x) #f)]) x))
    #f
    """

@pytest.mark.skipif(pytest.config.new_pycket, reason="require")
def test_with_continuation_mark3():
    m = run_mod(
    """
    #lang racket/base
    (define a 1)
    (set! a 2)
    (define result
        (let* ([extract
	        (lambda (k) (continuation-mark-set->list
	           (continuation-marks k)
	           'x))]
           [go
	        (lambda (in?)
              (lambda ()
	        	      (let ([k (with-continuation-mark 'x 10
	        			 (begin0
	        			  (with-continuation-mark 'x 11
	        			    (call/cc
	        			     (lambda (k )
	        			       (with-continuation-mark 'x 12
	        				 (if in?
	        				     (extract k)
	        				     k)))))
	        			  (+ a 3)))])
	        		(if in?
	        		    k
	        		    (extract k)))))])
        ((go #t))))
    (define valid (equal? result '(11 10)))
    """)
    sym = W_Symbol.make("valid")
    assert m.defs[sym] is w_true

def test_with_continuation_mark_impersonator():
    m = run_mod(
    """
    #lang pycket
    (define mark-key
      (impersonate-continuation-mark-key
       (make-continuation-mark-key)
       (lambda (l) (car l))
       (lambda (s) (string->list s))))
    (define result
      (with-continuation-mark mark-key "quiche"
        (continuation-mark-set-first
         (current-continuation-marks)
         mark-key)))
    """)
    sym = W_Symbol.make("result")
    assert isinstance(m.defs[sym], W_Character)
    assert m.defs[sym].value == 'q'

def test_impersonator_application_mark():

    m = run_mod(