def test_system_path_convention_type(source): """(system-path-convention-type)""" result = run_mod_expr(source, wrap=True) sym = result.asciivalue() if sys.platform in ['win32', 'cygwin']: assert sym == "windows" else: assert sym == "unix"
def test_read_bytes(source): """ (let ([ip (open-input-bytes (bytes 115 101 99 114 101 116))]) (read-bytes 6 ip)) """ result = run_mod_expr(source, wrap=True) assert isinstance(result, values.W_Bytes) assert result.value == list("secret")
def test_whitebox_bytes(source): r""" (let ([ht (make-hash)] [st (bytes 65 66)]) (bytes-set! st 0 67) (hash-set! ht #"a" '(red round)) (hash-set! ht #"b" '(yellow long)) (hash-set! ht st 77) (hash-ref ht #"c" "not there") ht) """ result = run_mod_expr(source) assert result.strategy is ByteHashmapStrategy.singleton
def test_whitebox_str(source): r""" (let ([ht (make-hash)] [st (string #\a #\b)]) (string-set! st 0 #\x) (hash-set! ht "a" '(red round)) (hash-set! ht "b" '(yellow long)) (hash-set! ht st 77) (hash-ref ht "c" "not there") ht) """ result = run_mod_expr(source) assert result.strategy is StringHashmapStrategy.singleton
def test_system_type_os(source): """(cons (system-type) (system-type 'os))""" result = run_mod_expr(source, wrap=True) assert result.car() == result.cdr() sym = result.car().asciivalue() # Sadly, this can never cover all cases. if sys.platform == "darwin": assert sym == "macosx" elif sys.platform in ['win32', 'cygwin']: assert sym == "windows" else: assert sym == "unix"
def test_default_hash(source): """ (let () (make-weak-hasheq) (make-immutable-hash) (make-hash) (make-hasheq) (make-hasheqv) #t) """ result = run_mod_expr(source, wrap=True) assert result is values.w_true
def test_open_input_bytes_and_read_bytes_line(source): """ (let* ([b (string->bytes/utf-8 "ABC\nDEF\n\nGHI\n\nJKL\n\n\nMNOP\n")] [expected '(#"MNOP" #"" #"" #"JKL" #"" #"GHI" #"" #"DEF" #"ABC")] [inport (open-input-bytes b)]) (let ([res (let rev ([lines null]) (let ([line (read-bytes-line inport)]) (if (eof-object? line) lines (rev (cons line lines)))))]) (equal? res expected))) """ result = run_mod_expr(source, wrap=True) assert result == w_true
def test_open_input_and_read_line(source): u""" (let* ([b "ÄBC\nDEF\n\nGHI\n\nJKL\n\n\nMNOP\n"] [expected '("MNOP" "" "" "JKL" "" "GHI" "" "DEF" "ÄBC")] [inport (open-input-string b)]) (let ([res (let rev ([lines null]) (let ([line (read-line inport)]) (if (eof-object? line) lines (rev (cons line lines)))))]) (equal? res expected))) """ result = run_mod_expr(source, wrap=True) assert result == w_true
def test_default_hash(source): """ (let () (make-weak-hasheq) (make-immutable-hash) (make-hash) (make-hasheq) (make-hasheqv) #t) """ from pycket.test.testhelper import run_mod_expr from pycket.values import w_true result = run_mod_expr(source, wrap=True) assert result is w_true
def test_read_utf8_bytes_chars(source): ur""" (let* ([b "ÄÖÜ"] [inport (open-input-string b)] [res1 (read-byte inport)] [res2 (read-byte inport)] [res3 (read-char inport)] ) (and (equal? res1 195) (equal? res2 132) (equal? res3 #\Ö))) """ result = run_mod_expr(source, wrap=True) assert result == w_true
def test_constant_mod(): run_mod_expr("1")
def test_constant_mod_val(): ov = run_mod_expr("1") assert isinstance(ov, W_Fixnum) assert ov.value == 1