| 1 |
;; |
| 2 |
;; testing text.tr |
| 3 |
;; |
| 4 |
|
| 5 |
(test-section "text.tr") |
| 6 |
|
| 7 |
(use text.tr) |
| 8 |
(test-module 'text.tr) |
| 9 |
|
| 10 |
(test* "basic" "hELLO, wORLD!" |
| 11 |
(string-tr "Hello, World!" "A-Za-z" "a-zA-Z")) |
| 12 |
(test* "repeat" "h????, w????!" |
| 13 |
(string-tr "Hello, World!" "A-Za-z" "a-z?*")) |
| 14 |
(test* "repeat" "h????, w????!" |
| 15 |
(string-tr "Hello, World!" "A-Za-z" "a-z?*0")) |
| 16 |
(test* "repeat" "h???!, w!!??!" |
| 17 |
(string-tr "Hello, World!" "A-Za-z" "a-z?*13!*13")) |
| 18 |
(test* "repeat - error" *test-error* |
| 19 |
(string-tr "Hello, World!" "A*10" "a-z?*13!*13")) |
| 20 |
(test* "delete" ", !" |
| 21 |
(string-tr "Hello, World!" "A-Za-z" "" :delete #t)) |
| 22 |
(test* "delete" "H, W!" |
| 23 |
(string-tr "Hello, World!" "a-z" "" :delete #t)) |
| 24 |
(test* "delete" "h, w!" |
| 25 |
(string-tr "Hello, World!" "A-Za-z" "a-z" :delete #t)) |
| 26 |
(test* "complement" "Hello??World?" |
| 27 |
(string-tr "Hello, World!" "A-Za-z" "?*" :complement #t)) |
| 28 |
(test* "complement" "Hello??World?" |
| 29 |
(string-tr "Hello, World!" "a-zA-Z" "?*" :complement #t)) |
| 30 |
(test* "complement" "H??????W?????" |
| 31 |
(string-tr "Hello, World!" "A-Z" "?*" :complement #t)) |
| 32 |
(test* "complement & delete" "HelloWorld" |
| 33 |
(string-tr "Hello, World!" "A-Za-z" "" |
| 34 |
:complement #t :delete #t)) |
| 35 |
(test* "complement & delete" "HelloWorld" |
| 36 |
(string-tr "Hello, World!" "a-zA-Z" "" |
| 37 |
:complement #t :delete #t)) |
| 38 |
(test* "squeeze" "helo, world!!!!" |
| 39 |
(string-tr "Hello, World!!!!" "A-Za-z" "a-z" :squeeze #t)) |
| 40 |
(test* "squeeze & complement" "Hello, World!" |
| 41 |
(string-tr "Hello, World!!!!" "A-Za-z" "" |
| 42 |
:squeeze #t :complement #t)) |
| 43 |
|
| 44 |
(test* "spec edge case (-)" "-bacdaef" |
| 45 |
(string-tr "Ab-cd-ef" "A-" "-a")) |
| 46 |
(test* "spec edge case (\\)" "a/b" |
| 47 |
(string-tr "a\\b" "\\\\" "/")) |
| 48 |
(test* "spec edge case (\\)" (test-error) |
| 49 |
(string-tr "a\\b" "\\" "/")) |
| 50 |
|
| 51 |
;; https://github.com/shirok/Gauche/issues/1051 |
| 52 |
(test* "spec edge case (3-\\)" (test-error) |
| 53 |
(string-tr "\\" "\\\\\\" "abc")) |
| 54 |
(test* "spec edge case (4-\\)" "a" |
| 55 |
(string-tr "\\" "\\\\\\\\" "abc")) |
| 56 |
(test* "spec edge case (mid-\\)" "b" |
| 57 |
(string-tr "\\" "x\\\\y" "abc")) |
| 58 |
(test* "spec edge case (mid-\\)" (test-error) |
| 59 |
(string-tr "\\" "x\\\\\\" "abc")) |
| 60 |
|
| 61 |
|
| 62 |
;; whole test over smaller table size |
| 63 |
(test* "basic, table-size" "hELLO, wORLD!" |
| 64 |
(string-tr "Hello, World!" "A-Za-z" "a-zA-Z" :table-size 65)) |
| 65 |
(test* "repeat, table-size" "h????, w????!" |
| 66 |
(string-tr "Hello, World!" "A-Za-z" "a-z?*" :table-size 66)) |
| 67 |
(test* "repeat, table-size" "h????, w????!" |
| 68 |
(string-tr "Hello, World!" "A-Za-z" "a-z?*0" :table-size 98)) |
| 69 |
(test* "repeat, table-size" "h???!, w!!??!" |
| 70 |
(string-tr "Hello, World!" "A-Za-z" "a-z?*13!*13" :table-size 99)) |
| 71 |
(test* "delete, table-size" ", !" |
| 72 |
(string-tr "Hello, World!" "A-Za-z" "" |
| 73 |
:delete #t :table-size 32)) |
| 74 |
(test* "delete, table-size" "H, W!" |
| 75 |
(string-tr "Hello, World!" "a-z" "" |
| 76 |
:delete #t :table-size 64)) |
| 77 |
(test* "delete, table-size" "h, w!" |
| 78 |
(string-tr "Hello, World!" "A-Za-z" "a-z" |
| 79 |
:delete #t :table-size 68)) |
| 80 |
(test* "complement, table-size" "Hello??World?" |
| 81 |
(string-tr "Hello, World!" "A-Za-z" "?*" |
| 82 |
:complement #t :table-size 87)) |
| 83 |
(test* "complement, table-size" "H??????W?????" |
| 84 |
(string-tr "Hello, World!" "A-Z" "?*" |
| 85 |
:complement #t :table-size 2)) |
| 86 |
(test* "complement & delete, table-size" "HelloWorld" |
| 87 |
(string-tr "Hello, World!" "A-Za-z" "" |
| 88 |
:complement #t :delete #t :table-size 70)) |
| 89 |
(test* "squeeze, table-size" "helo, world!!!!" |
| 90 |
(string-tr "Hello, World!!!!" "A-Za-z" "a-z" |
| 91 |
:squeeze #t :table-size 65)) |
| 92 |
(test* "squeeze & complement, table-size" "Hello, World!" |
| 93 |
(string-tr "Hello, World!!!!" "A-Za-z" "" |
| 94 |
:squeeze #t :complement #t :table-size 103)) |
| 95 |
|
| 96 |
(test* "escape in spec" "*ello, World!" |
| 97 |
(string-tr "Hello,-World!" "A\\-H" "_ \\*")) |