tests.lisp 2.8 KB
Newer Older
1

2
(defpackage #:translate/test
3
  (:use #:cl #:5am #:translate))
4 5

(in-package :translate/test)
6

7 8
(def-suite :translate-tests :description "Tests for translate library.")
(in-suite :translate-tests)
9

10 11 12 13 14 15 16 17
 ;; Fixtures
(def-fixture time/lang (time lang)
  "Creates null translation environment with specified resolution time
and language"
  (let ((translate::*translations*   nil)
        (translate:*resolution-time* time)
        (translate:*language*        lang))
    (&body)))
18

19
 ;; dispatch macro character tests
20

21 22 23 24 25 26 27 28 29 30 31 32
(test resolution-time.reader
      "Test dispatch macro character with different resolution times"
      (with-fixture time/lang (:run-time nil)
                    (is (equal "phrase"
                               (eval (read-from-string "#t\"phrase\""))))
                    (is (equal '(translate:translate "phrase")
                               (read-from-string "#t\"phrase\""))))
      (with-fixture time/lang (:load-time nil)
                    (is (equal "phrase"
                               (read-from-string "#t\"phrase\""))))
      (signals simple-type-error
               (read-from-string "#t bah")))
33 34 35

 ;; translations for defined language

36
(test translation.language
37
      "Single language definition"
38 39 40 41 42 43 44 45 46
      (with-fixture time/lang (:run-time 'en)
                    (translate:define-language 'en
                        "phrase-1" "Phrase one")
                    (is (equal "Phrase one" #t"phrase-1"))
                    (is (equal "{phrase-2}" #t"phrase-2"))
                    (is (equal "Phrase two"
                               (add-single-translation
                                'en "phrase-2" "Phrase two")))
                    (is (equal "Phrase two" #t"phrase-2"))))
47

48
(test translation.lexically-scoped-languages
49
      "Multiple languages per lexical scope"
50 51 52 53 54 55 56 57 58 59 60 61
      (with-fixture time/lang (:run-time nil)
                    (translate:define-language 'en
                        "phrase" "Phrase")
                    (translate:define-language 'pl
                        "phrase" "Fraza")
                    (is (equal "phrase" #t"phrase"))
                    (is (equal "Phrase"
                               (let ((*language* 'en))
                                 #t"phrase")))
                    (is (equal "Fraza"
                               (let ((*language* 'pl))
                                 #t"phrase")))))
62

63
(test translation.missing-phrases
64
      "Missing phrases removal"
65 66 67 68 69 70 71 72
      (with-fixture time/lang (:run-time 'en)
                    (translate:define-language 'en)
                    (is (equal "{phrase}" #t"phrase"))
                    (is (missing-translations))
                    (is (equal "Phrase"
                               (add-single-translation
                                'en "phrase" "Phrase")))
                    (is (null (missing-translations)))))
73 74