| 1 | module scheme |
| 2 | |
| 3 | import os |
| 4 | import rand |
| 5 | |
| 6 | fn test_goops_file_port_class_identity_persists_across_transcoding_and_close() { |
| 7 | dir := os.join_path(os.vtmp_dir(), 'vile-class-of-' + rand.ulid()) |
| 8 | os.mkdir_all(dir) or { panic(err) } |
| 9 | defer { os.rmdir_all(dir) or {} } |
| 10 | mut vm := new() |
| 11 | vm.define('path', string_value(os.join_path(dir, 'stream'))) or { panic(err) } |
| 12 | result := vm.eval("(define binary (open-file-input/output-port path)) |
| 13 | (define text (transcoded-port binary (make-transcoder (utf-8-codec)))) |
| 14 | (define memory (open-output-string)) |
| 15 | (define (observations) |
| 16 | (list (class-name (class-of binary)) (class-name (class-of text)) |
| 17 | (is-a? text <file-port>) (is-a? text <input-port>) (is-a? text <output-port>) |
| 18 | (class-name (class-of memory)) (instance? text))) |
| 19 | (define before (observations)) (close-port text) (close-port memory) |
| 20 | (define f (open-input-file path)) (close-port f) |
| 21 | (list before (equal? before (observations)) |
| 22 | (map (lambda (p) (class-name (class-of p))) |
| 23 | (list (current-input-port) (current-output-port) (standard-input-port) |
| 24 | (standard-output-port) f)) |
| 25 | (map class-name (class-direct-supers <file-input-output-port>)))") or { panic(err) } |
| 26 | actual := write(result) or { panic(err) } |
| 27 | if actual != '((<file-input-output-port> <file-input-output-port> #t #t #t <output-port> #f) #t (<file-input-port> <file-output-port> <file-input-port> <file-output-port> <file-input-port>) (<file-port> <input-output-port>))' { |
| 28 | panic(actual) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | fn test_goops_syntax_class_bounds_and_intrinsic_applicability_exports() { |
| 33 | mut vm := new() |
| 34 | result := vm.eval("(define-library (public classes) |
| 35 | (export check) |
| 36 | (import (scheme base) (vile goops) (vile syntax-case) (vile fixnums)) |
| 37 | (begin (define (check) |
| 38 | (define g (make-generic)) |
| 39 | (define meth (method ((x <syntax>)) 17)) |
| 40 | (add-method! g meth) |
| 41 | (define obj (syntax hello)) |
| 42 | (list (class-name (class-of obj)) (instance? obj) (instance? <syntax>) |
| 43 | (is-a? <syntax> <class>) (is-a? <file-input-output-port> <class>) |
| 44 | (eq? (car (%compute-applicable-methods g (list obj))) meth) |
| 45 | (g obj) (= min-fixnum (least-fixnum)) (= max-fixnum (greatest-fixnum)))))) |
| 46 | (import (public classes)) (check)") or { panic(err) } |
| 47 | actual := write(result) or { panic(err) } |
| 48 | if actual != '(<syntax> #f #t #t #t #t 17 #t #t)' { panic(actual) } |
| 49 | } |
| 50 | |