-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.lisp
74 lines (62 loc) · 2.8 KB
/
tests.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
(defpackage #:translate/test
(:use #:cl #:5am #:translate))
(in-package :translate/test)
(def-suite :translate-tests :description "Tests for translate library.")
(in-suite :translate-tests)
;; 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)))
;; dispatch macro character tests
(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")))
;; translations for defined language
(test translation.language
"Single language definition"
(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"))))
(test translation.lexically-scoped-languages
"Multiple languages per lexical scope"
(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")))))
(test translation.missing-phrases
"Missing phrases removal"
(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)))))