1
+ Rebol [
2
+ Title: "Rebol3 enbase/debase test script"
3
+ Author: "Oldes, Peter W A Wood"
4
+ File: %enbase-test.red
5
+ Tabs: 4
6
+ ]
7
+
8
+ do %../quick-test.r3
9
+
10
+ ~~~start-file~~~ "enbase"
11
+
12
+ ===start-group=== "enbase basic"
13
+ ;from https://tools.ietf.org/html/rfc4648#section-10
14
+ --test-- "enbase-1" --assert "" = enbase ""
15
+ --test-- "enbase-2" --assert "Zg==" = enbase "f"
16
+ --test-- "enbase-3" --assert "Zm8=" = enbase "fo"
17
+ --test-- "enbase-4" --assert "Zm9v" = enbase "foo"
18
+ --test-- "enbase-5" --assert "Zm9vYg==" = enbase "foob"
19
+ --test-- "enbase-6" --assert "Zm9vYmE=" = enbase "fooba"
20
+ --test-- "enbase-7" --assert "Zm9vYmFy" = enbase "foobar"
21
+
22
+ --test-- "enbase-8" --assert "" = enbase /base "" 16
23
+ --test-- "enbase-9" --assert "66" = enbase /base "f" 16
24
+ --test-- "enbase-10" --assert "666F" = enbase /base "fo" 16
25
+ --test-- "enbase-11" --assert "666F6F" = enbase /base "foo" 16
26
+ --test-- "enbase-12" --assert "666F6F62" = enbase /base "foob" 16
27
+ --test-- "enbase-13" --assert "666F6F6261" = enbase /base "fooba" 16
28
+ --test-- "enbase-14" --assert "666F6F626172" = enbase /base "foobar" 16
29
+ ===end-group===
30
+
31
+ ===start-group=== "debase 64"
32
+
33
+ --test-- "debase 64 1"
34
+ --assert strict-equal? "A simple string" to string! debase "QSBzaW1wbGUgc3RyaW5n"
35
+ --test-- "debase 64 2"
36
+ --assert strict-equal? "A multi-line\nstring" to string! debase "QSBtdWx0aS1saW5lXG5zdHJpbmc="
37
+ --test-- "debase 64 3"
38
+ --assert strict-equal? "A simple string" to string! debase /base "QSBzaW1wbGUgc3RyaW5n" 64
39
+ --test-- "debase 64 4"
40
+ --assert strict-equal? "A multi-line\nstring" to string! debase /base "QSBtdWx0aS1saW5lXG5zdHJpbmc=" 64
41
+
42
+ ===end-group===
43
+
44
+ ===start-group=== "debase 64 - safe URL variant"
45
+
46
+ --test-- "debase 64 url 1"
47
+ --assert binary? try [debase /url {
48
+ cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7
49
+ AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4
50
+ BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K
51
+ 0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqv
52
+ hJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrB
53
+ p0igcN_IoypGlUPQGe77Rw
54
+ } ]
55
+ --assert binary? try [debase {
56
+ cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7
57
+ AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4
58
+ BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K
59
+ 0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqv
60
+ hJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrB
61
+ p0igcN_IoypGlUPQGe77Rw
62
+ } ]
63
+ --test-- "debase 64 url 2 - missing padding in the input"
64
+ ;should be ok with the padding
65
+ --assert binary? try [debase {
66
+ eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt
67
+ cGxlLmNvbS9pc19yb290Ijp0cnVlfQ==
68
+ } ]
69
+ ;should throw error when missing padding and not /url refinement is used
70
+ --assert error? try [debase {
71
+ eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt
72
+ cGxlLmNvbS9pc19yb290Ijp0cnVlfQ
73
+ } ]
74
+ --assert binary? try [debase /url {
75
+ eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt
76
+ cGxlLmNvbS9pc19yb290Ijp0cnVlfQ
77
+ } ]
78
+ --test-- "debase 64 url 3"
79
+ key1: "qL8R4QIcQ_ZsRqOAbeRfcZhilN_MksRtDaErMA=="
80
+ bin: try [debase /url key1]
81
+ --assert true? all [binary? bin key1 = enbase /url bin]
82
+ ;debase is working also when input is missing the padding
83
+ key2: "qL8R4QIcQ_ZsRqOAbeRfcZhilN_MksRtDaErMA"
84
+ --assert bin = try [debase /url key2]
85
+
86
+ ===end-group===
87
+
88
+ ===start-group=== "debase 16"
89
+
90
+ --test-- "debase 16 1"
91
+ --assert strict-equal?
92
+ "A simple string"
93
+ to string! debase /base "412073696d706c6520737472696e67" 16
94
+ --test-- "debase 16 2"
95
+ --assert strict-equal?
96
+ "A multi-line\nstring"
97
+ to string! debase /base "41206d756c74692d6c696e655c6e737472696e67" 16
98
+
99
+ ===end-group===
100
+
101
+ ===start-group=== "debase 2"
102
+
103
+ --test-- "debase 2 1"
104
+ --assert strict-equal?
105
+ "^(04)^(01) "
106
+ to string! debase /base "0000010000000001" 2
107
+
108
+ ===end-group===
109
+
110
+ ~~~end-file~~~
0 commit comments