source: project/release/3/caketext/tags/1.1/caketext-spec.scm @ 9603

Last change on this file since 9603 was 9603, checked in by rlpowell, 14 years ago

Updated documentation.

  • Property svn:keywords set to Id
File size: 30.9 KB
Line 
1(load "caketext.scm")
2(use srfi-13)
3(require-extension testbase testbase-output-compact testbase-output-human testbase-output-html testbase-output-minimal)
4
5(define-for-syntax test::selecting #t)
6
7(define-expect-binary =)
8(define-expect-binary string=)
9
10(define pack #f)
11(define pack2 #f)
12(define pack3 #f)
13
14(define lpack-test-funcs
15  (list
16    (cons 'test (lambda (a b) (conc "seperate dump-test-func: 1. " a " 2. " b)))))
17
18(define-test
19  caketext-basic
20  "Story: Basic Translation
21  As a coder
22  I want the system to cleanly and unobtrusively translate basic strings
23  So I can use it easily"
24  (test/case
25    "Scenario: A pack with 'auto-add' set should silently re-print strings."
26    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
27    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
28    (expect-success "When: we set it to the auto-add type" (set-language-pack-config! pack 'auto-add #t))
29    (expect-string=
30      "Then: using translate with that pack and a plain string, we should get the original string back"
31      "This is a test string."
32      (caketext-translate (list pack) #f "This is a test string.")))
33  (test/case
34    "Scenario: A pack without 'auto-add' set should fail if we use an undefined string"
35    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
36    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
37    (expect-success "When: we set it to the *NOT* auto type"
38                    (set-language-pack-config! pack 'auto-add #f))
39    (expect-failure
40      "Then: using translate with that pack should fail"
41      (caketext-translate (list pack) #f "This is a test string.")))
42  (test/case
43    "Scenario: A pack with a string manually defined should be able to translate it."
44    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
45    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
46    (expect-success
47      "When: we set a simple string's translation explicitely" 
48      (set-language-pack-text! pack "This is a test string." "ti cipra jufra"))
49    (expect-string=
50      "Then: using translate with that pack and string should get the translation"
51      "ti cipra jufra"
52      (caketext-translate (list pack) #f "This is a test string.")))
53  (test/case
54    "Scenario: A pack with 'auto-add should actually add new strings when we use them."
55    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
56    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
57    (expect-success "When: we set it to the auto-add type" (set-language-pack-config! pack 'auto-add #t))
58    (expect-success "And: we use it to translate a new string" (caketext-translate (list pack) #f "This is a test string."))
59    (expect-string= "Then: we should be able to retreive that same string from the string pool."
60                    "This is a test string."
61                    (get-language-pack-text pack "This is a test string.")))
62  (test/case
63    "Scenario: A new pack should have no values at all."
64    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
65    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
66    (expect-false "Then: trying to get a string should return false" (get-language-pack-text pack "This is a test string."))
67    (expect-false "And: trying to get a function should return false" (get-language-pack-func pack 'quant))
68    (expect-false "And: trying to get a config variable should return false" (get-language-pack-config pack 'auto-add))))
69
70(define-test
71  caketext-configs
72  "Story: Configuration Variables
73  As a coder
74  I want the system deal well with configuration variables
75  So I can be protected from my own mistakes"
76  (test/case
77    "Scenario: Setting a config variable should result in that variable being gettable."
78    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
79    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
80    (expect-success "When: we set it to the auto-add type" (set-language-pack-config! pack 'auto-add #t))
81    (expect-true "Then: we can retrieve that setting" (get-language-pack-config pack 'auto-add)))
82  (test/case
83    "Scenario: Setting a config variable to a non-symbol should cause an error"
84    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
85    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
86    (expect-false "Then: setting a non-symbol config should error out" (set-language-pack-config! pack "feeble" "lob")))
87  (test/case
88    "Scenario: Trying to retrieve an undefined variable should return false (that's the effective default)"
89    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
90    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
91    (expect-false "Then: we cannot retrieve any configuration settings" (get-language-pack-config pack 'auto-add)))
92  (test/case
93    "Scenario: Setting all the config values at once should work"
94    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
95    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
96    (expect-success "When: we load a full set of config variables"
97                    (set-language-pack-configs-from-alist!
98                      pack
99                      '((auto-add . #t)
100                        (onmiss . "this is totally invalid"))))
101    (expect-true "Then: the first value should be correct"
102                 (get-language-pack-config pack 'auto-add))
103    (expect-string= "Then: the second value should be correct"
104                    "this is totally invalid"
105                    (get-language-pack-config pack 'onmiss))))
106
107(define-test
108  caketext-simple-subst-strings
109  "Story: Simple Substitution Strings
110  As a coder
111  I want to be able to translate strings with simple substitutions
112  So I can deal with dynamic text"
113  (test/case
114    "Scenario: Simple substitution on a manually added string"
115    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
116    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
117    (expect-success "When: we set a simple substitution string's translation explicitely" 
118                    (set-language-pack-text! pack "This is a test string: ~A." "ti cipra jufra to ~A toi"))
119    (expect-string= "Then: transaltions include the substituted text."
120                    "ti cipra jufra to weeble toi"
121                    (caketext-translate (list pack) #f "This is a test string: ~A." "weeble"))
122    (expect-string= "And: substituting something different also works"
123                    "ti cipra jufra to meep toi"
124                    (caketext-translate (list pack) #f "This is a test string: ~A." "meep")))
125  (test/case
126    "Scenario: Simple substitution on an auto-add string"
127    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
128    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
129    (expect-success "When: we set it to the auto-add type" (set-language-pack-config! pack 'auto-add #t))
130    (expect-string= "Then: using a simple substitution string gives correct substitution"
131                    "This is a test string: feeble."
132                    (caketext-translate (list pack) #f "This is a test string: ~A." "feeble"))
133    (expect-string= "And: substituing something different also works"
134                    "This is a test string: meepers."
135                    (caketext-translate (list pack) #f "This is a test string: ~A." "meepers"))))
136
137(define-test
138  caketext-function-subst-strings
139  "Story: Function Substitution Strings
140  As a coder
141  I want to be able to have function substitution on strings
142  So that language-specific decisions can be stored in the language pack"
143  (test/case
144    "Scenario: Function substitution on a manually added string"
145    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
146    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
147    (expect-success "When: we set a function substitution string's translation explicitely" 
148                    (set-language-pack-text!
149                      pack
150                      "This is a test string: %(test%,~A%,~A%)."
151                      "ti cipra jufra to %(test%,~A%,~A%) toi"))
152    (expect-success "And: we add the appropriate function"
153                    (set-language-pack-func! pack 'test (lambda (a b) (conc "test-func: 1. " a " 2. " b))))
154    (expect-string= "Then: transaltions include the substituted text."
155                    "ti cipra jufra to test-func: 1. weeble 2. bob toi"
156                    (caketext-translate (list pack) #f "This is a test string: %(test%,~A%,~A%)." "weeble" "bob"))
157    (expect-string= "And: substituting something different also works"
158                    "ti cipra jufra to test-func: 1. scree 2. fobby toi"
159                    (caketext-translate (list pack) #f "This is a test string: %(test%,~A%,~A%)." "scree" "fobby")))
160  (test/case
161    "Scenario: Function substitution on an auto-add string"
162    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
163    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
164    (expect-success "When: we set it to the auto-add type" (set-language-pack-config! pack 'auto-add #t))
165    (expect-success "And: we add the appropriate function"
166                    (set-language-pack-func! pack 'test (lambda (a b) (conc "test-func: 1. " a " 2. " b))))
167    (expect-string= "Then: using a function substitution string gives correct substitution"
168                    "This is a test string: test-func: 1. quazar 2. syrus."
169                    (caketext-translate (list pack) #f "This is a test string: %(test%,~A%,~A%)." "quazar" "syrus"))
170    (expect-string= "And: substituing something different also works"
171                    "This is a test string: test-func: 1. saddle 2. crax."
172                    (caketext-translate (list pack) #f "This is a test string: %(test%,~A%,~A%)." "saddle" "crax")))
173  (test/case
174    "Scenario: Function substitution when more than one function is used."
175    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
176    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
177    (expect-success "When: we set it to the auto-add type" (set-language-pack-config! pack 'auto-add #t))
178    (expect-success "And: we add a function"
179                    (set-language-pack-func! pack 'test (lambda (a b) (conc "test-func: 1. " a " 2. " b))))
180    (expect-success "And: we add another function"
181                    (set-language-pack-func! pack 'discreet (lambda (a) (conc "Well, what's " a " then?"))))
182    (expect-string= "Then: using a function substitution string gives correct substitution"
183                    "Wee: test-func: 1. book 2. chair, Well, what's rocking then?."
184                    (caketext-translate (list pack) #f "Wee: %(test%,~A%,~A%), %(discreet%,~A%)." "book" "chair" "rocking"))
185    (expect-string= "And: substituing something different also works"
186                    "Wee: Well, what's horse then?, test-func: 1. saddle 2. iron."
187                    (caketext-translate (list pack) #f "Wee: %(discreet%,~A%), %(test%,~A%,~A%)." "horse" "saddle" "iron")))
188  (test/case
189    "Scenario: Function substitution when the function is undefined should throw an exception."
190    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
191    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
192    (expect-success "When: we set it to the auto-add type" (set-language-pack-config! pack 'auto-add #t))
193    (expect-failure "Then: using a function substitution string fails"
194                    (caketext-translate (list pack) #f "Wee: %(test%,~A%,~A%), %(discreet%,~A%)." "book" "chair" "rocking")))
195  (test/case
196    "Scenario: Removing a function leads to exception if we try to use it."
197    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
198    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
199    (expect-success "And: we set it to the auto-add type" (set-language-pack-config! pack 'auto-add #t))
200    (expect-success "And: we add the appropriate function"
201                    (set-language-pack-func! pack 'test (lambda (a b) (conc "test-func: 1. " a " 2. " b))))
202    (expect-string= "And: transaltions include the substituted text."
203                    "This is a test string: test-func: 1. weeble 2. bob."
204                    (caketext-translate (list pack) #f "This is a test string: %(test%,~A%,~A%)." "weeble" "bob"))
205    (expect-success "When: we remove the function"
206                    (remove-language-pack-func pack 'test))
207    (expect-failure "Then: attempting to use that function fails"
208                    (caketext-translate (list pack) #f "This is a test string: %(test%,~A%,~A%)." "weeble" "bob")))
209  (test/case
210    "Scenario: We can still print raw ~ and %."
211    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
212    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
213    (expect-success "When: we set it to the auto-add type" (set-language-pack-config! pack 'auto-add #t))
214    (expect-string= "Then: we can still get raw ~ and % out of a translated string."
215                    "Here's a tilde: ~.  And a percent: %."
216                    (caketext-translate (list pack) #f "Here's a tilde: ~~.  And a percent: %%."))))
217
218(define-test
219  caketext-inheritance
220  "Story: Inheritance
221  As a coder
222  I want to be able to specify inheritance of language packs
223  So I can be more or less specific in my translations as appropriate"
224  (test/case
225    "Scenario: left-most pack wins."
226    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
227    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
228    (setup (set! pack3 #f)) ; *ALWAYS* start with a fresh pack
229    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
230    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
231    (expect-success "And: another new pack is created" (set! pack3 (new-language-pack)))
232    (expect-success "When: we set a string's translation explicitely for one"
233                    (set-language-pack-text!
234                      pack
235                      "This is a test string for inheritance."
236                      "ti cerda ke cipra jufra"))
237    (expect-success "And: also for the second"
238                    (set-language-pack-text!
239                      pack2
240                      "This is a test string for inheritance."
241                      "This is a test string for inheritance, eh?"))
242    (expect-success "And: also for the third"
243                    (set-language-pack-text!
244                      pack3
245                      "This is a test string for inheritance."
246                      "This is a test string for inheritance, dude."))
247    (expect-string= "Then: the leftmost pack (which is the first) wins"
248                    "ti cerda ke cipra jufra"
249                    (caketext-translate (list pack pack2 pack3) #f "This is a test string for inheritance."))
250    (expect-string= "Then: the leftmost pack (which is the second) wins"
251                    "This is a test string for inheritance, eh?"
252                    (caketext-translate (list pack2 pack pack3) #f "This is a test string for inheritance."))
253    (expect-string= "Then: the leftmost pack (which is the third) wins"
254                    "This is a test string for inheritance, dude."
255                    (caketext-translate (list pack3 pack2 pack) #f "This is a test string for inheritance.")))
256  (test/case
257    "Scenario: falling through to the third pack."
258    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
259    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
260    (setup (set! pack3 #f)) ; *ALWAYS* start with a fresh pack
261    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
262    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
263    (expect-success "And: another new pack is created" (set! pack3 (new-language-pack)))
264    (expect-success "When: we set a string's translation explicitely for the third"
265                    (set-language-pack-text!
266                      pack3
267                      "This is a test string for inheritance."
268                      "ti cerda ke cipra jufra"))
269    (expect-string= "Then: translating that string gives the third's value"
270                    "ti cerda ke cipra jufra"
271                    (caketext-translate (list pack pack2 pack3) #f "This is a test string for inheritance.")))
272  (test/case
273    "Scenario: falling through to the second pack."
274    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
275    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
276    (setup (set! pack3 #f)) ; *ALWAYS* start with a fresh pack
277    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
278    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
279    (expect-success "And: another new pack is created" (set! pack3 (new-language-pack)))
280    (expect-success "When: we set a string's translation explicitely for the third"
281                    (set-language-pack-text!
282                      pack3
283                      "This is a test string for inheritance."
284                      "ti cerda ke cipra jufra"))
285    (expect-success "When: we set a string's translation explicitely for the second"
286                    (set-language-pack-text!
287                      pack2
288                      "This is a test string for inheritance."
289                      "This is a test string for inheritance, eh?"))
290    (expect-string= "Then: translating that string gives the second's value"
291                    "This is a test string for inheritance, eh?"
292                    (caketext-translate (list pack pack2 pack3) #f "This is a test string for inheritance.")))
293  (test/case
294    "Scenario: Function substitution inheritance: string found on the second, function on the third."
295    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
296    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
297    (setup (set! pack3 #f)) ; *ALWAYS* start with a fresh pack
298    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
299    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
300    (expect-success "And: another new pack is created" (set! pack3 (new-language-pack)))
301    (expect-success "When: we set a string's translation explicitely for the second"
302                    (set-language-pack-text!
303                      pack2
304                      "This is a test string: %(test%,~A%,~A%)."
305                      "This is a test string for inheritance, %(test%,~A%,~A%), eh?"))
306    (expect-success "And: we add the appropriate function to the third"
307                    (set-language-pack-func! pack3 'test (lambda (a b) (conc "test-func: 1. " a " 2. " b))))
308    (expect-string= "Then: transaltions include the substituted text."
309                    "This is a test string for inheritance, test-func: 1. weeble 2. bob, eh?"
310                    (caketext-translate
311                      (list pack pack2 pack3)
312                      #f "This is a test string: %(test%,~A%,~A%)." "weeble" "bob"))
313    (expect-string= "And: substituting something different also works"
314                    "This is a test string for inheritance, test-func: 1. scree 2. fobby, eh?"
315                    (caketext-translate
316                      (list pack pack2 pack3)
317                      #f "This is a test string: %(test%,~A%,~A%)." "scree" "fobby")))
318  (test/case
319    "Scenario: Multiple function substitution inheritance: string found on the second, function on the first and third."
320    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
321    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
322    (setup (set! pack3 #f)) ; *ALWAYS* start with a fresh pack
323    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
324    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
325    (expect-success "And: another new pack is created" (set! pack3 (new-language-pack)))
326    (expect-success "When: we set a string's translation explicitely for the second"
327                    (set-language-pack-text!
328                      pack2
329                      "This is a test string for inheritance, %(test%,~A%,~A%) %(qux%,~A%)."
330                      "This is a test string for inheritance, %(test%,~A%,~A%) %(qux%,~A%), eh?"))
331    (expect-success "And: we add one function to the first"
332                    (set-language-pack-func! pack 'test (lambda (a b) (conc "test-func: 1. " a " 2. " b))))
333    (expect-success "And: we add another function to the third"
334                    (set-language-pack-func! pack3 'qux (lambda (a) (conc "in QU " a " X!"))))
335    (expect-string= "Then: transaltions include the substituted text."
336                    "This is a test string for inheritance, test-func: 1. weeble 2. bob in QU light X!, eh?"
337                    (caketext-translate
338                      (list pack pack2 pack3)
339                      #f "This is a test string for inheritance, %(test%,~A%,~A%) %(qux%,~A%)." "weeble" "bob" "light"))
340    (expect-string= "And: substituting something different also works"
341                    "This is a test string for inheritance, test-func: 1. scree 2. fobby in QU house X!, eh?"
342                    (caketext-translate
343                      (list pack pack2 pack3)
344                      #f "This is a test string for inheritance, %(test%,~A%,~A%) %(qux%,~A%)." "scree" "fobby" "house")))
345  (test/case
346    "Scenario: auto-add is set on the second pack."
347    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
348    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
349    (setup (set! pack3 #f)) ; *ALWAYS* start with a fresh pack
350    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
351    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
352    (expect-success "And: another new pack is created" (set! pack3 (new-language-pack)))
353    (expect-success "When: we set the second one to the auto-add type" (set-language-pack-config! pack2 'auto-add #t))
354    (expect-success "And: we use a new string"
355                    (caketext-translate
356                      (list pack pack2 pack3)
357                      #f "A never-before-used test string!"))
358    (expect-failure "Then: it should not be on the first pack"
359                    (get-language-pack-text pack "A never-before-used test string!"))
360    (expect-failure "Then: it should not be on the third pack"
361                    (get-language-pack-text pack3 "A never-before-used test string!"))
362    (expect-string= "Then: it should be on the second pack"
363                    "A never-before-used test string!"
364                    (get-language-pack-text pack2 "A never-before-used test string!")))
365  (test/case
366    "Scenario: onmiss is set on the second pack."
367    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
368    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
369    (setup (set! pack3 #f)) ; *ALWAYS* start with a fresh pack
370    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
371    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
372    (expect-success "And: another new pack is created" (set! pack3 (new-language-pack)))
373    (expect-success "When: we set the second one to have an onmiss function"
374                    (set-language-pack-config! pack2 'onmiss (lambda (pack str) "Well, shit.")))
375    (expect-string= "Then: when we use a new string, the onmiss value should be returned"
376                    "Well, shit."
377                    (caketext-translate
378                      (list pack pack2 pack3)
379                      #f "A never-before-used test string!")))
380  (test/case
381    "Scenario: onmiss is set on the second pack, auto-add on the third; onmiss should win."
382    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
383    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
384    (setup (set! pack3 #f)) ; *ALWAYS* start with a fresh pack
385    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
386    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
387    (expect-success "And: another new pack is created" (set! pack3 (new-language-pack)))
388    (expect-success "When: we set the second one to have an onmiss function"
389                    (set-language-pack-config! pack2 'onmiss (lambda (pack str) "Well, shit.")))
390    (expect-success "And: we set the third one to the auto-add type" (set-language-pack-config! pack3 'auto-add #t))
391    (expect-string= "Then: when we use a new string, the onmiss value should be returned"
392                    "Well, shit."
393                    (caketext-translate
394                      (list pack pack2 pack3)
395                      #f "A never-before-used test string!")))
396  (test/case
397    "Scenario: auto-add is set on the second pack, onmiss on the third; auto-add should win."
398    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
399    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
400    (setup (set! pack3 #f)) ; *ALWAYS* start with a fresh pack
401    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
402    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
403    (expect-success "And: another new pack is created" (set! pack3 (new-language-pack)))
404    (expect-success "When: we set the third one to have an onmiss function"
405                    (set-language-pack-config! pack3 'onmiss (lambda (pack str) "Well, shit.")))
406    (expect-success "And: we set the second one to the auto-add type" (set-language-pack-config! pack2 'auto-add #t))
407    (expect-success "And: we use a new string"
408                    (caketext-translate
409                      (list pack pack2 pack3)
410                      #f "A very never-before-used test string!"))
411    (expect-failure "Then: it should not be on the first pack"
412                    (get-language-pack-text pack "A very never-before-used test string!"))
413    (expect-failure "Then: it should not be on the third pack"
414                    (get-language-pack-text pack3 "A very never-before-used test string!"))
415    (expect-string= "Then: it should be on the second pack"
416                    "A very never-before-used test string!"
417                    (get-language-pack-text pack2 "A very never-before-used test string!"))))
418
419(define-test
420  caketext-save-and-load
421  "Story: Saving And Loading
422  As a coder
423  I want to be able to save and load language packs to/from files
424  So my translators don't have to touch the code."
425  (test/case
426    "Scenario: set a string and save first pack, load second pack, translation on the second pack should work."
427    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
428    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
429    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
430    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
431    (expect-success "When: we set a string's translation explicitely for the first"
432                    (set-language-pack-text!
433                      pack
434                      "This is a test string for dumping."
435                      "This is a test string for dumping, eh?"))
436    (expect-success "And: we dump that pack's text to a file"
437                    (dump-language-pack pack "/tmp/csltest1-strings.dump"))
438    (expect-success "And: we load that dump into the second pack"
439                    (load-language-pack pack2 "/tmp/csltest1-strings.dump" ""))
440    (expect-string= "Then: translation with that string on the second pack should work."
441                    "This is a test string for dumping, eh?"
442                    (caketext-translate
443                      (list pack2)
444                      #f "This is a test string for dumping.")))
445  (test/case
446    "Scenario: set a string and save first pack, load second pack with fuctions, translation on the second pack should work."
447    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
448    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
449    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
450    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
451    (expect-success "When: we set a string's translation explicitely for the first"
452                    (set-language-pack-text!
453                      pack
454                      "This is a test string for dumping %(test%,~A%,~A%)."
455                      "This is a test string for dumping %(test%,~A%,~A%), eh?"))
456    (expect-success "And: we put a function in the function 'dump' file"
457                    (with-output-to-file
458                      "/tmp/csltest2-func.dump"
459                      (lambda () (write-string "((test (lambda (a b) (conc \"dump-test-func: 1. \" a \" 2. \" b))))"))))
460    (expect-success "And: we dump that pack's text to a file"
461                    (dump-language-pack pack "/tmp/csltest2-strings.dump"))
462    (expect-success "And: we load that dump into the second pack"
463                    (load-language-pack pack2 "/tmp/csltest2-strings.dump" "/tmp/csltest2-func.dump"))
464    (expect-string= "Then: translating that string, which uses that function, in the second pack should work"
465                    "This is a test string for dumping dump-test-func: 1. dumper 2. trucker, eh?"
466                    (caketext-translate
467                      (list pack2)
468                      #f "This is a test string for dumping %(test%,~A%,~A%)." "dumper" "trucker")))
469  (test/case
470    "Scenario: dump/load test, with seperately defined functions"
471    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
472    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
473    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
474    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
475    (expect-success "When: we set a string's translation explicitely for the first"
476                    (set-language-pack-text!
477                      pack
478                      "This is a test string for dumping %(test%,~A%,~A%)."
479                      "This is a test string for dumping %(test%,~A%,~A%), eh?"))
480    (expect-success "And: we dump that pack's text to a file"
481                    (dump-language-pack pack "/tmp/csltest3-strings.dump"))
482    (expect-success "And: we load that dump into the second pack"
483                    (load-language-pack pack2 "/tmp/csltest3-strings.dump" ""))
484    (expect-success "And: we load our own seperate functions in"
485                    (set-language-pack-funcs-from-alist! pack2 lpack-test-funcs))
486    (expect-string= "Then: translating that string, which uses that function, in the second pack should work"
487                    "This is a test string for dumping seperate dump-test-func: 1. wow 2. hey, eh?"
488                    (caketext-translate
489                      (list pack2)
490                      #f "This is a test string for dumping %(test%,~A%,~A%)." "wow" "hey"))))
491(define-test
492  caketext-manual-edit-pack-files
493  "Story: Manual Pack File Editing
494  As a translator
495  I want to be able to manually edit packs as files
496  So I can translate without having to deal with code"
497  (test/case
498    "Scenario: dump/load test, with changes to the file between the dump and the load"
499    (setup (set! pack #f)) ; *ALWAYS* start with a fresh pack
500    (setup (set! pack2 #f)) ; *ALWAYS* start with a fresh pack
501    (expect-success "Given: a new pack is created" (set! pack (new-language-pack)))
502    (expect-success "And: another new pack is created" (set! pack2 (new-language-pack)))
503    (expect-success "When: we set a string's translation explicitely for the first"
504                    (set-language-pack-text!
505                      pack
506                      "This is a test string for dumping and editing."
507                      "This is a test string for dumping and editing, eh?"))
508    (expect-success "And: we dump that pack's text to a file"
509                    (dump-language-pack pack "/tmp/csltest4-strings.dump"))
510    (expect-success "And: we alter that file in place"
511                    (let
512                      ([newstring (string-substitute "eh\\?" "dude!" (read-all "/tmp/csltest4-strings.dump"))])
513                      (with-output-to-file
514                        "/tmp/csltest4-strings.dump"
515                        (lambda () (write-string newstring)))))
516    (expect-success "And: we load that dump into the second pack"
517                    (load-language-pack pack2 "/tmp/csltest4-strings.dump" ""))
518    (expect-string= "Then: translating that string on the second pack should yield the changed version."
519                    "This is a test string for dumping and editing, dude!"
520                    (caketext-translate
521                      (list pack2)
522                      #f "This is a test string for dumping and editing."))))
523
524
525(test::styler-set! caketext-basic test::output-style-minimal)
526(test::styler-set! caketext-configs test::output-style-minimal)
527(test::styler-set! caketext-simple-subst-strings test::output-style-minimal)
528(test::styler-set! caketext-function-subst-strings test::output-style-minimal)
529(test::styler-set! caketext-inheritance test::output-style-minimal)
530(test::styler-set! caketext-save-and-load test::output-style-minimal)
531(test::styler-set! caketext-manual-edit-pack-files test::output-style-minimal)
532
533(test::select! 'take caketext-basic)
534(test::select! 'take caketext-configs)
535(test::select! 'take caketext-simple-subst-strings)
536(test::select! 'take caketext-inheritance)
537(test::select! 'take caketext-function-subst-strings)
538(test::select! 'take caketext-save-and-load)
539(test::select! 'take caketext-manual-edit-pack-files)
540(run-test "Caketext Specification")
Note: See TracBrowser for help on using the repository browser.