<commit_before>
(cond-expand
 (modules (import (chibi io) (only (chibi test) test-begin test test-end)))
 (else #f))

(test-begin "io")

(define long-string (make-string 2000 #\a))

(test "input-string-port" 1025
  (call-with-input-string (substring long-string 0 1025)
    (lambda (in)
      (let loop ((c (read-char in)) (i 0))
        (cond ((eof-object? c) i)
              ((> i 1025) (error "read past eof"))
              (else (loop (read-char in) (+ i 1))))))))

(test "read-line" '("abc" "def")
  (call-with-input-string "abc\ndef\n"
    (lambda (in) (let ((line (read-line in))) (list line (read-line in))))))

(test "read-line-to-eof" '("abc" "def")
  (call-with-input-string "abc\ndef"
    (lambda (in) (let ((line (read-line in))) (list line (read-line in))))))

(test "null-output-port" #t
  (let ((out (make-null-output-port)))
    (write 1 out)
    (close-output-port out)
    #t))

(test "null-input-port" #t
  (let ((in (make-concatenated-port)))
    (let ((res (eof-object? (read-char in))))
      (close-input-port in)
      res)))

(define (string-upcase str)
  (list->string (map char-upcase (string->list str))))

(test "upcase-input-port" "ABC"
  (call-with-input-string "abc"
    (lambda (in)
      (let ((in (make-filtered-input-port string-upcase in)))
        (let ((res (read-line in)))
          (close-input-port in)
          res)))))

(test "upcase-output-port" "ABC"
  (call-with-output-string
    (lambda (out)
      (let ((out (make-filtered-output-port string-upcase out)))
        (display "abc" out)
        (close-output-port out)))))

(test-end)
<commit_msg>Making custom port tests optional.<commit_after>
(cond-expand
 (modules (import (chibi io) (only (chibi test) test-begin test test-end)))
 (else #f))

(test-begin "io")

(define long-string (make-string 2000 #\a))

(test "input-string-port" 1025
  (call-with-input-string (substring long-string 0 1025)
    (lambda (in)
      (let loop ((c (read-char in)) (i 0))
        (cond ((eof-object? c) i)
              ((> i 1025) (error "read past eof"))
              (else (loop (read-char in) (+ i 1))))))))

(test "read-line" '("abc" "def")
  (call-with-input-string "abc\ndef\n"
    (lambda (in) (let ((line (read-line in))) (list line (read-line in))))))

(test "read-line-to-eof" '("abc" "def")
  (call-with-input-string "abc\ndef"
    (lambda (in) (let ((line (read-line in))) (list line (read-line in))))))

;; Custom ports are only supported with string streams (i.e. either
;; GNU fopencookie or BSD funopen).

(cond-expand
 (string-streams

  (test "null-output-port" #t
    (let ((out (make-null-output-port)))
      (write 1 out)
      (close-output-port out)
      #t))

  (test "null-input-port" #t
    (let ((in (make-concatenated-port)))
      (let ((res (eof-object? (read-char in))))
        (close-input-port in)
        res)))

  (define (string-upcase str)
    (list->string (map char-upcase (string->list str))))

  (test "upcase-input-port" "ABC"
    (call-with-input-string "abc"
      (lambda (in)
        (let ((in (make-filtered-input-port string-upcase in)))
          (let ((res (read-line in)))
            (close-input-port in)
            res)))))

  (test "upcase-output-port" "ABC"
    (call-with-output-string
      (lambda (out)
        (let ((out (make-filtered-output-port string-upcase out)))
          (display "abc" out)
          (close-output-port out)))))))

(test-end)

{'fraction_non_alphanumeric': 0.1971252566735113, 'fraction_numerical': 0.011733646230566148, 'mean_word_length': 2.7846836847946728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '764397', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1237, 'n_words': 333}