<commit_before>#|
This file is a part of clta project.
Copyright (c) 2014 κeen
|#

(in-package :cl-user)
(defpackage clta-test
  (:use :cl
   :clta
        :cl-test-more)
  (:import-from :clta.backend
   :make-backend))
(in-package :clta-test)

;; NOTE: To run this test file, execute `(asdf:test-system :clta)' in your Lisp.

(defparameter *suites*
  '(("foo" () "foo" "simple string")
    ("<foo>" () "<foo>" "simple string containing html meta chars")
    ("bar {{var bar}}" (:bar "bar") "bar bar" "simple variable")
    ("bar {{var bar}}" (:bar "<bar>") "bar &lt;bar&gt;" "variable containing html meta char")
    ("bar{{repeat 3}} {{var bar}}{{endrepeat}}" (:bar "bar") "bar bar bar bar" "repeat")
    ("{{loop items as i}}<li>{{var i}}</li>{{endloop}}" (:items ("uragasumi" "hakkaisan" "dassai")) "<li>uragasumi</li><li>hakkaisan</li><li>dassai</li>" "loop")
    ("{{loop items as i}}<li>{{var i}}</li>{{endloop}}" (:items ()) "" "loop with loopee being nil")
    ("<li>{{if new-p}}New! {{endif}}blahblah</li>" (:new-p t) "<li>New! blahblah</li>" "if")
    ("<li>{{if new-p}}New! {{endif}}blahblah</li>" (:new-p nil) "<li>blahblah</li>" "if with condition being nil")
    ("<li>{{if new-p}}New! {{else}}Old! {{endif}}blahblah</li>" (:new-p t)"<li>New! blahblah</li>" "if with else")
    ("<li>{{if new-p}}New! {{else}}Old! {{endif}}blahblah</li>" (:new-p nil) "<li>Old! blahblah</li>" "if with else and condition being nil")
    ("the content of foo is {{insert foo}}" () "the content of foo is {{repeat 2 as i}}bar{{endrepeat}}" "insert")
    ("the content of var is {{insert var}}" () "the content of var is {{var bar}}" "insert with insertee cotaining template string")
    ("the content of foo is {{include foo}}" () "the content of foo is barbar" "against include")
    ("the content of var is {{include var}}" (:bar "var") "the content of var is var" "include with includee cotaining template string")))

(plan nil)
(diag "compile test with stream backend")

(loop :for (template args result description) :in *suites*
           :do (ok (compile-template-string (make-backend :stream) template ()) description))
(diag "render test with stream backend")
(loop :for (template args result description) :in *suites*
      :do (is-print (apply #'render template args) result description))


;; blah blah blah.

(finalize)
<commit_msg>add tests against string backend<commit_after>#|
This file is a part of clta project.
Copyright (c) 2014 κeen
|#

(in-package :cl-user)
(defpackage clta-test
  (:use :cl
   :clta
        :cl-test-more)
  (:import-from :clta.backend
   :make-backend))
(in-package :clta-test)

;; NOTE: To run this test file, execute `(asdf:test-system :clta)' in your Lisp.

(defparameter *suites*
  '(("foo" () "foo" "simple string")
    ("<foo>" () "<foo>" "simple string containing html meta chars")
    ("bar {{var bar}}" (:bar "bar") "bar bar" "simple variable")
    ("bar {{var bar}}" (:bar "<bar>") "bar &lt;bar&gt;" "variable containing html meta char")
    ("bar{{repeat 3}} {{var bar}}{{endrepeat}}" (:bar "bar") "bar bar bar bar" "repeat")
    ("{{loop items as i}}<li>{{var i}}</li>{{endloop}}" (:items ("uragasumi" "hakkaisan" "dassai")) "<li>uragasumi</li><li>hakkaisan</li><li>dassai</li>" "loop")
    ("{{loop items as i}}<li>{{var i}}</li>{{endloop}}" (:items ()) "" "loop with loopee being nil")
    ("<li>{{if new-p}}New! {{endif}}blahblah</li>" (:new-p t) "<li>New! blahblah</li>" "if")
    ("<li>{{if new-p}}New! {{endif}}blahblah</li>" (:new-p nil) "<li>blahblah</li>" "if with condition being nil")
    ("<li>{{if new-p}}New! {{else}}Old! {{endif}}blahblah</li>" (:new-p t)"<li>New! blahblah</li>" "if with else")
    ("<li>{{if new-p}}New! {{else}}Old! {{endif}}blahblah</li>" (:new-p nil) "<li>Old! blahblah</li>" "if with else and condition being nil")
    ("the content of foo is {{insert foo}}" () "the content of foo is {{repeat 2 as i}}bar{{endrepeat}}" "insert")
    ("the content of var is {{insert var}}" () "the content of var is {{var bar}}" "insert with insertee cotaining template string")
    ("the content of foo is {{include foo}}" () "the content of foo is barbar" "against include")
    ("the content of var is {{include var}}" (:bar "var") "the content of var is var" "include with includee cotaining template string")))

(plan nil)
(diag "compile test with stream backend")

(loop :for (template args result description) :in *suites*
      :do (ok (compile-template-string (make-backend :stream) template ()) description))

(diag "compile test with string backend")

(loop :for (template args result description) :in *suites*
      :do (ok (compile-template-string (make-backend :string) template ()) description))

(diag "render test with stream backend")
(loop :for (template args result description) :in *suites*
      :do (is-print (apply #'render template args) result description))

(diag "compile test with string backend")

(loop :for (template args result description) :in *suites*
      :do (is-print (apply #'render template (cons :backend (cons (make-backend :string) args))) result description))
;; blah blah blah.

(finalize)

{'fraction_non_alphanumeric': 0.20321064996084573, 'fraction_numerical': 0.0023492560689115116, 'mean_word_length': 4.583606557377049, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, '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': '7002994', 'n_tokens_mistral': 1808, 'n_tokens_neox': 1716, 'n_words': 596}