@@ -7,7 +7,7 @@ const CHARMAP_EMPTY: &'static [char] = &[];
7
7
const CHARMAP_SR_CYR : & ' static [ char ] = & [
8
8
'А' , 'Б' , 'В' , 'Г' , 'Д' , 'Ђ' , 'Е' , 'Ж' , 'З' , 'И' , 'Ј' , 'К' , 'Л' , 'Љ' , 'М' , 'Н' , 'Њ' , 'О' , 'П' ,
9
9
'Р' , 'С' , 'Т' , 'Ћ' , 'У' , 'Ф' , 'Х' , 'Ц' , 'Ч' , 'Џ' , 'Ш' , 'a' , 'б' , 'в' , 'г' , 'д' , 'ђ' , 'e' , 'ж' ,
10
- 'З ' , 'и' , 'j' , 'к' , 'л' , 'љ' , 'м' , 'н' , 'њ' , 'o' , 'п' , 'р' , 'с' , 'т' , 'ћ' , 'у' , 'ф' , 'х' , 'ц' ,
10
+ 'з ' , 'и' , 'j' , 'к' , 'л' , 'љ' , 'м' , 'н' , 'њ' , 'o' , 'п' , 'р' , 'с' , 'т' , 'ћ' , 'у' , 'ф' , 'х' , 'ц' ,
11
11
'ч' , 'џ' , 'ш' ,
12
12
] ;
13
13
@@ -239,3 +239,57 @@ fn main() -> Result<(), Error> {
239
239
unreachable ! ( )
240
240
}
241
241
}
242
+
243
+ #[ cfg( test) ]
244
+ mod tests {
245
+ use super :: * ;
246
+
247
+ #[ test]
248
+ fn process_no_changes_empty ( ) -> Result < ( ) , Error > {
249
+ let mut proc = Processor :: new ( ) ;
250
+ let input = String :: from ( "ã$âÕÝ=¼ÜyÌÈo-P©6ë1M»¡u9-ú{K=/NMd" ) ;
251
+ let mut output = Vec :: new ( ) ;
252
+ proc. process ( & mut input. as_bytes ( ) , & mut output) ?;
253
+ assert_eq ! ( input, String :: from_utf8_lossy( & output) ) ;
254
+ Ok ( ( ) )
255
+ }
256
+
257
+ #[ test]
258
+ fn process_no_changes_lat ( ) -> Result < ( ) , Error > {
259
+ let mut proc = Processor :: new ( ) ;
260
+ proc. tables ( CHARMAP_SR_LAT , CHARMAP_SR_LAT ) ?;
261
+ let input = String :: from ( "ã$âÕÝ=¼ÜyÌÈo-P©6ë1M»¡u9-ú{K=/NMd" ) ;
262
+ let mut output = Vec :: new ( ) ;
263
+ proc. process ( & mut input. as_bytes ( ) , & mut output) ?;
264
+ assert_eq ! ( input, String :: from_utf8_lossy( & output) ) ;
265
+ Ok ( ( ) )
266
+ }
267
+
268
+ #[ test]
269
+ fn process_lat_to_cyr ( ) -> Result < ( ) , Error > {
270
+ let mut proc = Processor :: new ( ) ;
271
+ proc. tables ( CHARMAP_SR_LAT , CHARMAP_SR_CYR ) ?;
272
+ let input = String :: from ( "ABVGDĐEŽZIJKLLjMNNjOPRSTĆUFHCČDžŠabvgdđežzijklljmnnjoprstćufhcčdžš" ) ;
273
+ let mut output = Vec :: new ( ) ;
274
+ proc. process ( & mut input. as_bytes ( ) , & mut output) ?;
275
+ assert_eq ! (
276
+ String :: from_utf8_lossy( & output) ,
277
+ "АБВГДЂЕЖЗИЈКЛЉМНЊОПРСТЋУФХЦЧЏШaбвгдђeжзиjклљмнњoпрстћуфхцчџш"
278
+ ) ;
279
+ Ok ( ( ) )
280
+ }
281
+
282
+ #[ test]
283
+ fn process_mixed_to_cyr ( ) -> Result < ( ) , Error > {
284
+ let mut proc = Processor :: new ( ) ;
285
+ proc. tables ( CHARMAP_SR_LAT , CHARMAP_SR_CYR ) ?;
286
+ let input = String :: from ( "ABVGDЂЕЖЗИЈКЛЉМNNjOPRСТЋУФHCČDžŠaбвгдђeжзиjклљмnnjoprstćufhcčdžš" ) ;
287
+ let mut output = Vec :: new ( ) ;
288
+ proc. process ( & mut input. as_bytes ( ) , & mut output) ?;
289
+ assert_eq ! (
290
+ String :: from_utf8_lossy( & output) ,
291
+ "АБВГДЂЕЖЗИЈКЛЉМНЊОПРСТЋУФХЦЧЏШaбвгдђeжзиjклљмнњoпрстћуфхцчџш"
292
+ ) ;
293
+ Ok ( ( ) )
294
+ }
295
+ }
0 commit comments