-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-composite.red
108 lines (93 loc) · 2.05 KB
/
test-composite.red
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Red []
do %composite.red
test-composite: func [input][
print [mold input "==" mold composite input]
]
test-composite-custom-err: func [input][
print [mold input "==" mold composite/err-val input "#ERR"]
]
test-bad-composite: func [input][
print [mold input "==" mold try [composite input]]
]
test-composite-marks: func [input markers][
print [mold input mold marks tab "==" mold composite/marks input markers]
]
test-composite-with: func [input ctx][
print [mold input "==" mold composite/with input ctx]
]
test-composite-with-fn: func [input [string!] fn [function!] arg][
print [mold input "==" mold fn input arg]
]
print "Composite"
s: "1 + 2"
foreach val [
""
":(1):"
":(pi):"
{:("foo"):}
":(rejoin ['a 'b]):"
"a:('--):b"
"a:('--):"
":('--):b"
"ax:(1 / 0):xb"
"alpha: :(rejoin ['a 'b]): answer: :(42 / 3):"
{
name: :(form-full-name cust):
rank: :(as-ordinal index? find scores cust):
ser#: :(cust/uuid):
}
"a :('--): b"
"a :('--):"
":('--): b"
"ax :(1 / 0): xb"
{a :("1 + 2"): b}
{a :({{1 + 2}}): b}
{a :({"1 + 2"}): b}
{a :(s): b}
][test-composite val]
print "^/Composite/custom-error-val"
test-composite-custom-err "ax:(1 / 0):xb"
test-composite-custom-err "ax :(1 / 0): xb"
print "^/Bad Composite Input"
foreach val [
":("
":('end"
"asdf:('end"
"):"
"beg):"
")::("
":(1):beg):"
"asdf:(1):beg):"
":(1/a/b/c):"
":(2abc):"
][test-bad-composite val]
print "^/Composite/Marks"
foreach [val marks] [
"" ["" ""]
":(1):" [":(" "):"]
"):pi:(" ["):" ":("]
"a<%'--%>b" ["<%" "%>"]
"a{'--}b" [#"{" #"}"]
"a{'--}}b" [#"{" "}}"]
"a{{'--}b" ["{{" #"}"]
"a<c>'--</c>b" ["<c>" "</c>"]
"a<c>'--</c>b" [<c> </c>]
][test-composite-marks val marks]
print "^/Composite/with"
o: object [a: 1 b: 2]
foreach val [
""
":(1):"
":(pi + a):"
":(reduce [a b]):"
":(rejoin [a b]):"
"a:(a + b):b"
][test-composite-with val o]
; Function support is from @hiiamboris. I'm not sure about it's usefulness yet.
print "^/Composite/with (func)"
f: func [str w][
composite/with str context? 'w
]
test-composite-with-fn ":(w):" :f 100
print ""
halt