<commit_before>;;; -*- mode: Lisp; Syntax: Common-Lisp; -*-
;;;
;;; Copyright (c) 2008 by the authors.
;;;
;;; See COPYING for details.

(in-package :cl-walker-test)

(defsuite* (test/lexenv :in test))

;; TODO would be better to use macroexpand-all for this, because stefil's errors get to cl:compile
;; which aborts at the first failure and skips the other assertions
(defun compile* (form)
  (handler-bind ((warning #'muffle-warning)
                 #+sbcl (sb-ext:compiler-note #'muffle-warning))
    (compile nil `(lambda ()
                    ,form)))
  (values))

(defun sort-by-symbol-name (sequence)
  (sort (copy-seq sequence)
        #'string< :key #'symbol-name))

(defsuite* (test/lexenv/query :in test/lexenv))

(deftest test/lexenv/query/variables ()
  (compile*
   `(symbol-macrolet ((a 42)
                      (b 43))
      (flet ((f1 () 1)
             (f2 () 2))
        (macrolet ((m1 () 1)
                   (m2 () 2))
          (let ((x 1)
                (y 2)
                (z 3))
            (declare (ignore z))
            (macrolet ((dummy (&environment env)
                         (is (equal '(x y)
                                    (sort-by-symbol-name
                                     (collect-variables-in-lexenv env))))
                         (is (equal '(x y z)
                                    (sort-by-symbol-name
                                     (collect-variables-in-lexenv env :include-ignored t))))
                         (is (find-variable-in-lexenv 'x env))
                         (is (not (find-variable-in-lexenv 'z env)))
                         (is (not (find-variable-in-lexenv 'a env)))
                         (is (not (find-variable-in-lexenv 'f1 env)))
                         (is (not (find-variable-in-lexenv 'm1 env)))
                         (is (find-variable-in-lexenv 'z env :include-ignored t))
                         nil))
              (dummy))))))))

(deftest test/lexenv/query/functions ()
  (compile*
   `(symbol-macrolet ((a 42)
                      (b 43))
      (flet ((f1 () 1)
             (f2 () 2))
        (macrolet ((m1 () 1)
                   (m2 () 2))
          (let ((x 1)
                (y 2)
                (z 3))
            (declare (ignore z))
            (macrolet ((dummy (&environment env)
                         (is (equal '(f1 f2)
                                    (sort-by-symbol-name
                                     (collect-functions-in-lexenv env))))
                         (is (find-function-in-lexenv 'f1 env))
                         (is (not (find-function-in-lexenv 'foo env)))
                         (is (not (find-function-in-lexenv 'a env)))
                         (is (not (find-function-in-lexenv 'm1 env)))
                         (is (not (find-function-in-lexenv 'dummy env)))
                         nil))
              (dummy))))))))

(deftest test/lexenv/query/macros ()
  (compile*
   `(symbol-macrolet ((a 42)
                      (b 43))
      (flet ((f1 () 1)
             (f2 () 2))
        (macrolet ((m1 () 1)
                   (m2 () 2))
          (let ((x 1)
                (y 2)
                (z 3))
            (declare (ignore z))
            (macrolet ((dummy (&environment env)
                         (is (equal '(dummy m1 m2)
                                    (sort-by-symbol-name
                                     (collect-macros-in-lexenv env))))
                         (is (find-macro-in-lexenv 'm1 env))
                         (is (not (find-macro-in-lexenv 'f1 env)))
                         (is (not (find-macro-in-lexenv 'a env)))
                         (is (not (find-macro-in-lexenv 'x env)))
                         nil))
              (dummy))))))))

(deftest test/lexenv/query/symbol-macros ()
  (compile*
   `(symbol-macrolet ((a 42)
                      (b 43))
      (flet ((f1 () 1)
             (f2 () 2))
        (macrolet ((m1 () 1)
                   (m2 () 2))
          (let ((x 1)
                (y 2)
                (z 3))
            (declare (ignore z))
            (macrolet ((dummy (&environment env)
                         (is (equal '(a b)
                                    (sort-by-symbol-name
                                     (collect-symbol-macros-in-lexenv env))))
                         (is (find-symbol-macro-in-lexenv 'a env))
                         (is (not (find-symbol-macro-in-lexenv 'm1 env)))
                         (is (not (find-symbol-macro-in-lexenv 'f1 env)))
                         (is (not (find-symbol-macro-in-lexenv 'x env)))
                         nil))
              (dummy))))))))

(defsuite* (test/lexenv/augment :in test/lexenv))

<commit_msg>added test for do- stuff<commit_after>;;; -*- mode: Lisp; Syntax: Common-Lisp; -*-
;;;
;;; Copyright (c) 2008 by the authors.
;;;
;;; See COPYING for details.

(in-package :cl-walker-test)

(defsuite* (test/lexenv :in test))

;; TODO would be better to use macroexpand-all for this, because stefil's errors get to cl:compile
;; which aborts at the first failure and skips the other assertions
(defun compile* (form)
  (handler-bind ((warning #'muffle-warning)
                 #+sbcl (sb-ext:compiler-note #'muffle-warning))
    (compile nil `(lambda ()
                    ,form)))
  (values))

(defun sort-by-symbol-name (sequence)
  (sort (copy-seq sequence)
        #'string< :key #'symbol-name))

(defsuite* (test/lexenv/query :in test/lexenv))

(deftest test/lexenv/query/variables ()
  (compile*
   `(symbol-macrolet ((a 42)
                      (b 43))
      (flet ((f1 () 1)
             (f2 () 2))
        (macrolet ((m1 () 1)
                   (m2 () 2))
          (let ((x 1)
                (y 2)
                (z 3))
            (declare (ignore z))
            (macrolet ((dummy (&environment env)
                         (is (equal '(x y)
                                    (sort-by-symbol-name
                                     (collect-variables-in-lexenv env))))
                         (bind ((ignored 0)
                                (non-ignored 0))
                           (do-variables-in-lexenv (env name ignored?)
                             (is (and (symbolp name)
                                      (eq (symbol-package name) ,*package*)))
                             (if ignored?
                                 (incf ignored)
                                 (incf non-ignored)))
                           (is (= ignored 1))
                           (is (= non-ignored 2)))
                         (is (equal '(x y z)
                                    (sort-by-symbol-name
                                     (collect-variables-in-lexenv env :include-ignored t))))
                         (is (find-variable-in-lexenv 'x env))
                         (is (not (find-variable-in-lexenv 'z env)))
                         (is (not (find-variable-in-lexenv 'a env)))
                         (is (not (find-variable-in-lexenv 'f1 env)))
                         (is (not (find-variable-in-lexenv 'm1 env)))
                         (is (find-variable-in-lexenv 'z env :include-ignored t))
                         nil))
              (dummy))))))))

(deftest test/lexenv/query/functions ()
  (compile*
   `(symbol-macrolet ((a 42)
                      (b 43))
      (flet ((f1 () 1)
             (f2 () 2))
        (macrolet ((m1 () 1)
                   (m2 () 2))
          (let ((x 1)
                (y 2)
                (z 3))
            (declare (ignore z))
            (macrolet ((dummy (&environment env)
                         (is (equal '(f1 f2)
                                    (sort-by-symbol-name
                                     (collect-functions-in-lexenv env))))
                         (bind ((functions 0))
                           (do-functions-in-lexenv (env name)
                             (is (and (symbolp name)
                                      (eq (symbol-package name) ,*package*)))
                             (incf functions))
                           (is (= functions 2)))
                         (is (find-function-in-lexenv 'f1 env))
                         (is (not (find-function-in-lexenv 'foo env)))
                         (is (not (find-function-in-lexenv 'a env)))
                         (is (not (find-function-in-lexenv 'm1 env)))
                         (is (not (find-function-in-lexenv 'dummy env)))
                         nil))
              (dummy))))))))

(deftest test/lexenv/query/macros ()
  (compile*
   `(symbol-macrolet ((a 42)
                      (b 43))
      (flet ((f1 () 1)
             (f2 () 2))
        (macrolet ((m1 () 1)
                   (m2 () 2))
          (let ((x 1)
                (y 2)
                (z 3))
            (declare (ignore z))
            (macrolet ((dummy (&environment env)
                         (is (equal '(dummy m1 m2)
                                    (sort-by-symbol-name
                                     (collect-macros-in-lexenv env))))
                         (bind ((macros 0))
                           (do-macros-in-lexenv (env name fn)
                             (is (and (symbolp name)
                                      (eq (symbol-package name) ,*package*)))
                             (is (functionp fn))
                             (incf macros))
                           (is (= macros 3)))
                         (is (find-macro-in-lexenv 'm1 env))
                         (is (not (find-macro-in-lexenv 'f1 env)))
                         (is (not (find-macro-in-lexenv 'a env)))
                         (is (not (find-macro-in-lexenv 'x env)))
                         nil))
              (dummy))))))))

(deftest test/lexenv/query/symbol-macros ()
  (compile*
   `(symbol-macrolet ((a 42)
                      (b 43))
      (flet ((f1 () 1)
             (f2 () 2))
        (macrolet ((m1 () 1)
                   (m2 () 2))
          (let ((x 1)
                (y 2)
                (z 3))
            (declare (ignore z))
            (macrolet ((dummy (&environment env)
                         (is (equal '(a b)
                                    (sort-by-symbol-name
                                     (collect-symbol-macros-in-lexenv env))))
                         (bind ((symbol-macros 0))
                           (do-symbol-macros-in-lexenv (env name fn)
                             (is (and (symbolp name)
                                      (eq (symbol-package name) ,*package*)))
                             (is (not (functionp fn)))
                             (incf symbol-macros))
                           (is (= symbol-macros 2)))
                         (is (find-symbol-macro-in-lexenv 'a env))
                         (is (not (find-symbol-macro-in-lexenv 'm1 env)))
                         (is (not (find-symbol-macro-in-lexenv 'f1 env)))
                         (is (not (find-symbol-macro-in-lexenv 'x env)))
                         nil))
              (dummy))))))))

(defsuite* (test/lexenv/augment :in test/lexenv))


{'fraction_non_alphanumeric': 0.1369160140426681, 'fraction_numerical': 0.014582770726438023, 'mean_word_length': 1.0112237509051412, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 37, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '761620', 'n_tokens_mistral': 3328, 'n_tokens_neox': 3044, 'n_words': 789}