gloo 7.2 → 7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/application.md +19 -3
- data/docs/iterators.md +66 -1
- data/docs/language_objects.md +14 -7
- data/docs/language_scripting.md +17 -0
- data/docs/language_syntax.md +86 -3
- data/docs/objects.md +6 -6
- data/docs/operators.md +36 -2
- data/docs/plugins.md +26 -0
- data/docs/testing.md +31 -2
- data/docs/verbs.md +8 -0
- data/lib/VERSION +1 -1
- data/lib/VERSION_NOTES +15 -0
- data/lib/gloo/app/engine.rb +133 -17
- data/lib/gloo/app/prompt.rb +8 -0
- data/lib/gloo/convert/string_to_decimal.rb +3 -6
- data/lib/gloo/convert/string_to_integer.rb +3 -2
- data/lib/gloo/core/dictionary.rb +23 -12
- data/lib/gloo/core/obj.rb +77 -0
- data/lib/gloo/core/op.rb +99 -0
- data/lib/gloo/core/parser.rb +15 -0
- data/lib/gloo/core/tokens.rb +18 -0
- data/lib/gloo/core/verb.rb +130 -1
- data/lib/gloo/exec/dispatch.rb +7 -3
- data/lib/gloo/exec/runaway_recursion.rb +34 -0
- data/lib/gloo/exec/runner.rb +46 -0
- data/lib/gloo/exec/script.rb +16 -2
- data/lib/gloo/expr/expression.rb +77 -6
- data/lib/gloo/expr/l_decimal.rb +18 -2
- data/lib/gloo/expr/l_integer.rb +5 -2
- data/lib/gloo/expr/op_div.rb +4 -0
- data/lib/gloo/expr/op_eq.rb +4 -0
- data/lib/gloo/expr/op_gt.rb +4 -0
- data/lib/gloo/expr/op_gteq.rb +4 -0
- data/lib/gloo/expr/op_ineq.rb +4 -0
- data/lib/gloo/expr/op_lt.rb +4 -0
- data/lib/gloo/expr/op_lteq.rb +4 -0
- data/lib/gloo/expr/op_minus.rb +4 -0
- data/lib/gloo/expr/op_mult.rb +3 -7
- data/lib/gloo/expr/op_plus.rb +8 -1
- data/lib/gloo/objs/basic/alias.rb +6 -1
- data/lib/gloo/objs/basic/boolean.rb +15 -6
- data/lib/gloo/objs/basic/decimal.rb +25 -3
- data/lib/gloo/objs/basic/script.rb +3 -1
- data/lib/gloo/objs/basic/string_msgs.rb +50 -68
- data/lib/gloo/objs/ctrl/until.rb +219 -0
- data/lib/gloo/plugin/callback.rb +54 -10
- data/lib/gloo/plugin/ext_manager.rb +44 -0
- data/lib/gloo/plugin/lib_manager.rb +65 -1
- data/lib/gloo/shell/runner.rb +36 -9
- data/lib/gloo/verbs/break.rb +6 -4
- data/lib/gloo/verbs/check.rb +8 -2
- data/lib/gloo/verbs/create.rb +13 -4
- data/lib/gloo/verbs/if.rb +33 -10
- data/lib/gloo/verbs/invoke.rb +6 -1
- data/lib/gloo/verbs/list.rb +9 -2
- data/lib/gloo/verbs/load.rb +4 -1
- data/lib/gloo/verbs/move.rb +8 -2
- data/lib/gloo/verbs/put.rb +9 -2
- data/lib/gloo/verbs/reload.rb +2 -1
- data/lib/gloo/verbs/run.rb +8 -1
- data/lib/gloo/verbs/save.rb +4 -0
- data/lib/gloo/verbs/tell.rb +9 -2
- data/lib/gloo/verbs/unless.rb +34 -10
- data/lib/gloo/verbs/unload.rb +81 -16
- data/test.gloo/ctrl/until.test.gloo +100 -0
- data/test.gloo/lang/computed_paths.test.gloo +98 -0
- data/test.gloo/lang/literal.test.gloo +43 -0
- data/test.gloo/lang/ops.test.gloo +193 -0
- data/test.gloo/lang/runaway_recursion.test.gloo +44 -0
- data/test.gloo/objs/decimal.test.gloo +23 -0
- data/test.gloo/objs/string.test.gloo +30 -0
- data/test.gloo/verbs/create.test.gloo +6 -21
- data/test.gloo/verbs/if.test.gloo +41 -0
- data/test.gloo/verbs/load.test.gloo +4 -3
- data/test.gloo/verbs/unless.test.gloo +40 -0
- data/test.gloo/verbs/unload.test.gloo +61 -3
- metadata +6 -1
data/lib/gloo/verbs/unload.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
2
|
# Copyright:: Copyright (c) 2022 Eric Crane. All rights reserved.
|
|
3
3
|
#
|
|
4
|
-
# Unload all files.
|
|
4
|
+
# Unload all files, or one library or extension.
|
|
5
5
|
#
|
|
6
6
|
|
|
7
7
|
module Gloo
|
|
@@ -11,15 +11,37 @@ module Gloo
|
|
|
11
11
|
KEYWORD = 'unload'.freeze
|
|
12
12
|
KEYWORD_SHORT = 'u!'.freeze
|
|
13
13
|
|
|
14
|
+
LIB_OPT = 'lib'.freeze
|
|
15
|
+
EXT_OPT = 'ext'.freeze
|
|
16
|
+
|
|
17
|
+
WRONG_ARGS_ERR = 'unload takes nothing, or lib or ext and a name, ' \
|
|
18
|
+
'so nothing was unloaded; to unload one object, use tell x to unload.'.freeze
|
|
19
|
+
MISSING_NAME_ERR = 'Missing the name of the library or extension to unload!'.freeze
|
|
20
|
+
|
|
14
21
|
#
|
|
15
22
|
# Run the verb.
|
|
16
|
-
#
|
|
23
|
+
# With nothing after it, this unloads all loaded objects and
|
|
24
|
+
# resets the engine state; with lib or ext and a name, it unloads
|
|
25
|
+
# that library or extension.
|
|
17
26
|
#
|
|
18
27
|
def run
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
return unless take_evaluated_arg
|
|
29
|
+
|
|
30
|
+
return unload_all if @tokens.token_count == 1
|
|
31
|
+
|
|
32
|
+
opt = @tokens.second.strip.downcase
|
|
33
|
+
unless [ LIB_OPT, EXT_OPT ].include?( opt ) && @tokens.token_count <= 3
|
|
34
|
+
@engine.err WRONG_ARGS_ERR
|
|
35
|
+
return @engine.heap.it.set_to( false )
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
name = @tokens.at( 2 )
|
|
39
|
+
if name.blank?
|
|
40
|
+
@engine.syntax_err MISSING_NAME_ERR
|
|
41
|
+
return @engine.heap.it.set_to( false )
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
unload_plugin( opt, name )
|
|
23
45
|
end
|
|
24
46
|
|
|
25
47
|
#
|
|
@@ -42,6 +64,28 @@ module Gloo
|
|
|
42
64
|
|
|
43
65
|
private
|
|
44
66
|
|
|
67
|
+
#
|
|
68
|
+
# Unload all files, emptying the heap.
|
|
69
|
+
#
|
|
70
|
+
def unload_all
|
|
71
|
+
return unless @engine.persist_man.maps
|
|
72
|
+
|
|
73
|
+
@engine.persist_man.unload_all
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
#
|
|
77
|
+
# Unload the named library (lib) or extension (ext). If it
|
|
78
|
+
# couldn't be unloaded (already reported), it is false.
|
|
79
|
+
#
|
|
80
|
+
def unload_plugin( opt, name )
|
|
81
|
+
ok = if opt == LIB_OPT
|
|
82
|
+
@engine.lib_manager.unload_lib( name )
|
|
83
|
+
else
|
|
84
|
+
@engine.ext_manager.unload_ext( name )
|
|
85
|
+
end
|
|
86
|
+
@engine.heap.it.set_to false unless ok
|
|
87
|
+
end
|
|
88
|
+
|
|
45
89
|
# ---------------------------------------------------------------------
|
|
46
90
|
# Verb Documentation
|
|
47
91
|
# ---------------------------------------------------------------------
|
|
@@ -53,21 +97,42 @@ module Gloo
|
|
|
53
97
|
{
|
|
54
98
|
:name => KEYWORD,
|
|
55
99
|
:shortcut => KEYWORD_SHORT,
|
|
56
|
-
:description => 'Un-load all open files
|
|
57
|
-
'
|
|
58
|
-
'
|
|
59
|
-
'save state
|
|
60
|
-
|
|
61
|
-
|
|
100
|
+
:description => 'Un-load all open files, or one library or ' \
|
|
101
|
+
'extension. With nothing after it, unload empties the heap: ' \
|
|
102
|
+
'use the files command to see the list of files that will be ' \
|
|
103
|
+
'un-loaded, and be sure to save state first. With lib or ext ' \
|
|
104
|
+
'and a name, it unloads that library or extension: its verbs ' \
|
|
105
|
+
'and object types are gone until it is loaded again.',
|
|
106
|
+
:syntax => [ 'unload', 'unload lib {name}', 'unload ext {name}' ],
|
|
107
|
+
:parameters => [
|
|
108
|
+
'lib {name} or ext {name} (optional) — the library or extension ' \
|
|
109
|
+
'to unload, as given to load. The name can be worked out: ' \
|
|
110
|
+
'unload lib ( name ).'
|
|
111
|
+
],
|
|
112
|
+
:result => 'With nothing after it, all objects are unloaded from ' \
|
|
113
|
+
'the heap. With lib or ext, that library\'s or extension\'s ' \
|
|
114
|
+
'verbs and object types are removed; load lib or load ext ' \
|
|
115
|
+
'brings them back.',
|
|
62
116
|
:errors => [
|
|
63
|
-
'unload
|
|
64
|
-
'
|
|
65
|
-
|
|
117
|
+
'Anything else after unload is an error, and nothing is ' \
|
|
118
|
+
'unloaded. To unload one object, use tell x to unload.',
|
|
119
|
+
'unload lib or unload ext without a name is a syntax error.',
|
|
120
|
+
'A library or extension can\'t be unloaded while objects of ' \
|
|
121
|
+
'its types are on the heap: it is an error naming them, and ' \
|
|
122
|
+
'nothing is unloaded.',
|
|
123
|
+
'A library gloo loaded itself (gloo-test, when running tests) ' \
|
|
124
|
+
'can\'t be unloaded: it is an error.'
|
|
66
125
|
],
|
|
67
|
-
:notes => 'unload
|
|
126
|
+
:notes => 'Plain unload keeps loaded libraries and extensions. ' \
|
|
127
|
+
'Unloading a library or extension that isn\'t loaded ' \
|
|
128
|
+
'does nothing. Its Ruby code stays loaded, so any settings or ' \
|
|
129
|
+
'caches of its own aren\'t reset. To unload just one object, ' \
|
|
68
130
|
'send it the unload message (tell x to unload).',
|
|
69
131
|
:examples => <<~EXAMPLES.strip
|
|
70
132
|
> unload
|
|
133
|
+
> unload lib md
|
|
134
|
+
> exists? object markdown
|
|
135
|
+
> load lib md
|
|
71
136
|
EXAMPLES
|
|
72
137
|
}
|
|
73
138
|
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Until loop tests: do, then done, until done is true.
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
tests.ctrl.until [can] :
|
|
6
|
+
|
|
7
|
+
count [int] : 0
|
|
8
|
+
answer [string] :
|
|
9
|
+
|
|
10
|
+
# A one-line done: its result is in it.
|
|
11
|
+
up [until] :
|
|
12
|
+
do [script] : tell ^^.count to inc
|
|
13
|
+
done [script] : eval ^^.count > 4
|
|
14
|
+
|
|
15
|
+
runs_until_done [test] :
|
|
16
|
+
description [string] : The loop runs do until done's result is true.
|
|
17
|
+
on_test [script] :
|
|
18
|
+
put 0 into ^^.count
|
|
19
|
+
tell ^^.up to run
|
|
20
|
+
eval ^^.count = 5
|
|
21
|
+
assert "expected the loop to stop once count passed 4"
|
|
22
|
+
|
|
23
|
+
runs_at_least_once [test] :
|
|
24
|
+
description [string] : done is checked after each pass, so do runs once even when done is already true.
|
|
25
|
+
on_test [script] :
|
|
26
|
+
put 10 into ^^.count
|
|
27
|
+
tell ^^.up to run
|
|
28
|
+
eval ^^.count = 11
|
|
29
|
+
assert "expected do to run once"
|
|
30
|
+
|
|
31
|
+
# done follows the [bool] rule.
|
|
32
|
+
by_text [until] :
|
|
33
|
+
max [int] : 3
|
|
34
|
+
do [script] : tell ^^.count to inc
|
|
35
|
+
done [script] : eval ^^.answer
|
|
36
|
+
|
|
37
|
+
text_true_ends_it [test] :
|
|
38
|
+
description [string] : The text true in done counts as true.
|
|
39
|
+
on_test [script] :
|
|
40
|
+
put 0 into ^^.count
|
|
41
|
+
put 'true' into ^^.answer
|
|
42
|
+
tell ^^.by_text to run
|
|
43
|
+
eval ^^.count = 1
|
|
44
|
+
assert "expected the text true to end the loop"
|
|
45
|
+
|
|
46
|
+
# index and max.
|
|
47
|
+
capped [until] :
|
|
48
|
+
index [int] :
|
|
49
|
+
max [int] : 3
|
|
50
|
+
do [script] : tell ^^.count to inc
|
|
51
|
+
done [script] : eval false
|
|
52
|
+
|
|
53
|
+
index_counts_from_zero [test] :
|
|
54
|
+
description [string] : index holds the current pass, counting from 0.
|
|
55
|
+
expect_errors [bool] : true
|
|
56
|
+
on_test [script] :
|
|
57
|
+
put 0 into ^^.count
|
|
58
|
+
tell ^^.capped to run
|
|
59
|
+
eval ^^.capped.index = 2
|
|
60
|
+
assert "expected index 2 on the third pass"
|
|
61
|
+
|
|
62
|
+
max_reached_is_an_error [test] :
|
|
63
|
+
description [string] : Reaching max ends the loop with an error, and it is false.
|
|
64
|
+
expect_errors [bool] : true
|
|
65
|
+
on_test [script] :
|
|
66
|
+
put 0 into ^^.count
|
|
67
|
+
tell ^^.capped to run
|
|
68
|
+
refute "expected it to be false"
|
|
69
|
+
eval ^^.count = 3
|
|
70
|
+
assert "expected max passes"
|
|
71
|
+
|
|
72
|
+
# An error in done ends the loop.
|
|
73
|
+
bad_done [until] :
|
|
74
|
+
do [script] : tell ^^.count to inc
|
|
75
|
+
done [script] : eval no.such.obj = 1
|
|
76
|
+
|
|
77
|
+
error_in_done_ends_it [test] :
|
|
78
|
+
description [string] : An error in done ends the loop after that pass.
|
|
79
|
+
expect_errors [bool] : true
|
|
80
|
+
on_test [script] :
|
|
81
|
+
put 0 into ^^.count
|
|
82
|
+
tell ^^.bad_done to run
|
|
83
|
+
eval ^^.count = 1
|
|
84
|
+
assert "expected one pass"
|
|
85
|
+
|
|
86
|
+
# break loop ends the loop.
|
|
87
|
+
early [until] :
|
|
88
|
+
index [int] :
|
|
89
|
+
do [script] :
|
|
90
|
+
tell ^^.count to inc
|
|
91
|
+
if ^.index = 2 then break loop
|
|
92
|
+
done [script] : eval false
|
|
93
|
+
|
|
94
|
+
break_loop_ends_it [test] :
|
|
95
|
+
description [string] : break loop in do ends the loop.
|
|
96
|
+
on_test [script] :
|
|
97
|
+
put 0 into ^^.count
|
|
98
|
+
tell ^^.early to run
|
|
99
|
+
eval ^^.count = 3
|
|
100
|
+
assert "expected break loop on the third pass"
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Computed object paths: a ( … ) group where a verb expects an object
|
|
3
|
+
# path is worked out, and its value is used as the path.
|
|
4
|
+
#
|
|
5
|
+
|
|
6
|
+
tests.lang.computed_paths [can] :
|
|
7
|
+
|
|
8
|
+
#
|
|
9
|
+
# The quote-rotation example (svt/data/quote.gloo), with ( … ) in
|
|
10
|
+
# place of an alias: each pass builds the next slot's path, relative
|
|
11
|
+
# to this container, creates it and fills it.
|
|
12
|
+
#
|
|
13
|
+
quotes [can] :
|
|
14
|
+
i [int] : 0
|
|
15
|
+
file [string] :
|
|
16
|
+
add_quote [script] :
|
|
17
|
+
tell ^.i to inc
|
|
18
|
+
create ( '^.quotes.' ^.i ) as string
|
|
19
|
+
put ^.file into ( '^.quotes.' ^.i )
|
|
20
|
+
|
|
21
|
+
builds_paths_at_runtime [test] :
|
|
22
|
+
description [string] : create and put take a path built at runtime, relative to the script.
|
|
23
|
+
on_test [script] :
|
|
24
|
+
put 0 into ^^.i
|
|
25
|
+
put 'first.md' into ^^.file
|
|
26
|
+
run ^^.add_quote
|
|
27
|
+
put 'second.md' into ^^.file
|
|
28
|
+
run ^^.add_quote
|
|
29
|
+
eval ^^.quotes.1 = 'first.md'
|
|
30
|
+
assert "expected quotes.1 to hold the first file"
|
|
31
|
+
eval ^^.quotes.2 = 'second.md'
|
|
32
|
+
assert "expected quotes.2 to hold the second file"
|
|
33
|
+
tell ^^.quotes.1 to unload
|
|
34
|
+
tell ^^.quotes.2 to unload
|
|
35
|
+
|
|
36
|
+
count [int] : 0
|
|
37
|
+
target [string] : tests.lang.computed_paths.count
|
|
38
|
+
|
|
39
|
+
tell_a_computed_object [test] :
|
|
40
|
+
description [string] : tell ( expr ) sends the message to the object at the worked-out path.
|
|
41
|
+
on_test [script] :
|
|
42
|
+
put 0 into ^^.count
|
|
43
|
+
tell ( ^^.target ) to inc
|
|
44
|
+
eval ^^.count = 1
|
|
45
|
+
assert "expected the object named by target to be incremented"
|
|
46
|
+
|
|
47
|
+
#
|
|
48
|
+
# Aliases. ln points at a.s, and a.s holds the path of other.place.
|
|
49
|
+
# ( ln ) follows the alias and uses a.s's value as a path: a second
|
|
50
|
+
# hop. ( ln* ) uses the alias's own value, the path a.s.
|
|
51
|
+
#
|
|
52
|
+
a [can] :
|
|
53
|
+
s [string] :
|
|
54
|
+
other [can] :
|
|
55
|
+
place [string] :
|
|
56
|
+
ln [alias] :
|
|
57
|
+
a_s_path [string] : tests.lang.computed_paths.a.s
|
|
58
|
+
place_path [string] : tests.lang.computed_paths.other.place
|
|
59
|
+
|
|
60
|
+
set_up_alias [script] :
|
|
61
|
+
put ^.a_s_path into ^.ln*
|
|
62
|
+
put ^.place_path into ^.a.s
|
|
63
|
+
put '' into ^.other.place
|
|
64
|
+
|
|
65
|
+
put_into_an_alias_goes_to_its_target [test] :
|
|
66
|
+
description [string] : put x into ln puts x into the alias's target, a.s.
|
|
67
|
+
on_test [script] :
|
|
68
|
+
run ^^.set_up_alias
|
|
69
|
+
put 'x' into ^^.ln
|
|
70
|
+
eval ^^.a.s = 'x'
|
|
71
|
+
assert "expected a.s to get the value"
|
|
72
|
+
|
|
73
|
+
put_into_a_parenthesised_alias_takes_a_second_hop [test] :
|
|
74
|
+
description [string] : put x into ( ln ) uses the target's value as the path, so x goes into other.place.
|
|
75
|
+
on_test [script] :
|
|
76
|
+
run ^^.set_up_alias
|
|
77
|
+
put 'x' into ( ^^.ln )
|
|
78
|
+
eval ^^.other.place = 'x'
|
|
79
|
+
assert "expected other.place to get the value"
|
|
80
|
+
eval ^^.a.s = ^^.place_path
|
|
81
|
+
assert "expected a.s to be unchanged"
|
|
82
|
+
|
|
83
|
+
put_into_a_parenthesised_alias_star_matches_the_alias [test] :
|
|
84
|
+
description [string] : put x into ( ln* ) uses the alias's own value, a.s, the same as put x into ln.
|
|
85
|
+
on_test [script] :
|
|
86
|
+
run ^^.set_up_alias
|
|
87
|
+
put 'x' into ( ^^.ln* )
|
|
88
|
+
eval ^^.a.s = 'x'
|
|
89
|
+
assert "expected a.s to get the value"
|
|
90
|
+
|
|
91
|
+
put_into_an_alias_star_retargets_it [test] :
|
|
92
|
+
description [string] : put path into ln* points the alias somewhere else, as before.
|
|
93
|
+
on_test [script] :
|
|
94
|
+
run ^^.set_up_alias
|
|
95
|
+
put ^^.place_path into ^^.ln*
|
|
96
|
+
put 'y' into ^^.ln
|
|
97
|
+
eval ^^.other.place = 'y'
|
|
98
|
+
assert "expected the retargeted alias to put into other.place"
|
|
@@ -57,3 +57,46 @@ tests.lang.literal [can] :
|
|
|
57
57
|
put FALSE into ^^.b
|
|
58
58
|
eval ^^.b = false
|
|
59
59
|
assert "expected FALSE to parse"
|
|
60
|
+
|
|
61
|
+
decimal_spellings [test] :
|
|
62
|
+
description [string] : trailing zeros, a leading dot, an exponent and a tiny value are all decimals.
|
|
63
|
+
on_test [script] :
|
|
64
|
+
eval 2.50 * 2
|
|
65
|
+
put it into ^^.d
|
|
66
|
+
eval ^^.d = 5.0
|
|
67
|
+
assert "expected 2.50 to be a decimal"
|
|
68
|
+
|
|
69
|
+
eval .5 + 0
|
|
70
|
+
put it into ^^.d
|
|
71
|
+
eval ^^.d = 0.5
|
|
72
|
+
assert "expected .5 to be a decimal"
|
|
73
|
+
|
|
74
|
+
eval 1.0e3 + 0
|
|
75
|
+
put it into ^^.d
|
|
76
|
+
eval ^^.d = 1000.0
|
|
77
|
+
assert "expected 1.0e3 to be a decimal"
|
|
78
|
+
|
|
79
|
+
eval 0.0000001 * 10000000
|
|
80
|
+
put it into ^^.d
|
|
81
|
+
eval ^^.d > 0.99
|
|
82
|
+
assert "expected 0.0000001 to be a decimal"
|
|
83
|
+
|
|
84
|
+
integer_spellings [test] :
|
|
85
|
+
description [string] : leading zeros and a leading plus are integers; 007 is 7, not octal.
|
|
86
|
+
on_test [script] :
|
|
87
|
+
eval 007 + 1
|
|
88
|
+
put it into ^^.i
|
|
89
|
+
eval ^^.i = 8
|
|
90
|
+
assert "expected 007 to be 7"
|
|
91
|
+
|
|
92
|
+
eval +5 + 0
|
|
93
|
+
put it into ^^.i
|
|
94
|
+
eval ^^.i = 5
|
|
95
|
+
assert "expected +5 to be 5"
|
|
96
|
+
|
|
97
|
+
decimal_at_load [test] :
|
|
98
|
+
description [string] : a typed decimal written with trailing zeros loads without a warning.
|
|
99
|
+
on_test [script] :
|
|
100
|
+
put '2.50' into ^^.d
|
|
101
|
+
eval ^^.d = 2.5
|
|
102
|
+
assert "expected '2.50' to go into a decimal as 2.5"
|
|
@@ -7,6 +7,8 @@ tests.lang.ops [can] :
|
|
|
7
7
|
first [string] : Ada
|
|
8
8
|
last [string] : Lovelace
|
|
9
9
|
full [string] :
|
|
10
|
+
count [int] : 3
|
|
11
|
+
five [string] : 5
|
|
10
12
|
|
|
11
13
|
confirm_eq_ops [test] :
|
|
12
14
|
description [string] : Confirm equality operations.
|
|
@@ -105,3 +107,194 @@ tests.lang.ops [can] :
|
|
|
105
107
|
eval ^^.full = 'abcd'
|
|
106
108
|
assert "expected no operator, + and and to mix"
|
|
107
109
|
|
|
110
|
+
|
|
111
|
+
confirm_integer_and_decimal_math [test] :
|
|
112
|
+
description [string] : An integer and a decimal give a decimal, whichever side each is on.
|
|
113
|
+
on_test [script] :
|
|
114
|
+
eval 1 + 2.5 = 3.5
|
|
115
|
+
assert "expected 1 + 2.5 to be 3.5"
|
|
116
|
+
|
|
117
|
+
eval 1 - 0.5 = 0.5
|
|
118
|
+
assert "expected 1 - 0.5 to be 0.5"
|
|
119
|
+
|
|
120
|
+
eval 3 * 1.5 = 4.5
|
|
121
|
+
assert "expected 3 * 1.5 to be 4.5"
|
|
122
|
+
|
|
123
|
+
eval 7 / 2.0 = 3.5
|
|
124
|
+
assert "expected 7 / 2.0 to be 3.5"
|
|
125
|
+
|
|
126
|
+
eval 2.5 + 1 = 3.5
|
|
127
|
+
assert "expected 2.5 + 1 to be 3.5"
|
|
128
|
+
|
|
129
|
+
confirm_two_integers_stay_integers [test] :
|
|
130
|
+
description [string] : An integer with an integer gives an integer.
|
|
131
|
+
on_test [script] :
|
|
132
|
+
eval 7 / 2 = 3
|
|
133
|
+
assert "expected 7 / 2 to be 3"
|
|
134
|
+
|
|
135
|
+
confirm_integer_and_decimal_compare [test] :
|
|
136
|
+
description [string] : An integer on the left is compared with a decimal as a decimal.
|
|
137
|
+
on_test [script] :
|
|
138
|
+
eval 1 = 1.9
|
|
139
|
+
refute "expected 1 to not equal 1.9"
|
|
140
|
+
|
|
141
|
+
eval 1 != 1.9
|
|
142
|
+
assert "expected 1 != 1.9"
|
|
143
|
+
|
|
144
|
+
eval 1 < 1.5
|
|
145
|
+
assert "expected 1 < 1.5"
|
|
146
|
+
|
|
147
|
+
eval 2 > 1.5
|
|
148
|
+
assert "expected 2 > 1.5"
|
|
149
|
+
|
|
150
|
+
eval 1 <= 0.5
|
|
151
|
+
refute "expected 1 to not be less than or equal to 0.5"
|
|
152
|
+
|
|
153
|
+
eval 1 >= 1.5
|
|
154
|
+
refute "expected 1 to not be greater than or equal to 1.5"
|
|
155
|
+
|
|
156
|
+
confirm_text_less_than [test] :
|
|
157
|
+
description [string] : Text is compared in dictionary order with < and <=.
|
|
158
|
+
on_test [script] :
|
|
159
|
+
eval 'abc' < 'abd'
|
|
160
|
+
assert "expected 'abc' < 'abd'"
|
|
161
|
+
|
|
162
|
+
eval 'B' < 'a'
|
|
163
|
+
refute "expected 'B' to not be less than 'a'"
|
|
164
|
+
|
|
165
|
+
eval 'A' < 'a'
|
|
166
|
+
assert "expected 'A' < 'a' (capital first on a tie)"
|
|
167
|
+
|
|
168
|
+
eval 'apple' < 'Banana'
|
|
169
|
+
assert "expected 'apple' < 'Banana'"
|
|
170
|
+
|
|
171
|
+
eval 'x' <= 'x'
|
|
172
|
+
assert "expected 'x' <= 'x'"
|
|
173
|
+
|
|
174
|
+
eval 'abd' <= 'abc'
|
|
175
|
+
refute "expected 'abd' to not be less than or equal to 'abc'"
|
|
176
|
+
|
|
177
|
+
confirm_text_greater_than [test] :
|
|
178
|
+
description [string] : Text is compared in dictionary order with > and >=.
|
|
179
|
+
on_test [script] :
|
|
180
|
+
eval 'abd' > 'abc'
|
|
181
|
+
assert "expected 'abd' > 'abc'"
|
|
182
|
+
|
|
183
|
+
eval 'b' > 'A'
|
|
184
|
+
assert "expected 'b' > 'A'"
|
|
185
|
+
|
|
186
|
+
eval 'x' > 'x'
|
|
187
|
+
refute "expected 'x' to not be greater than 'x'"
|
|
188
|
+
|
|
189
|
+
eval 'x' >= 'x'
|
|
190
|
+
assert "expected 'x' >= 'x'"
|
|
191
|
+
|
|
192
|
+
eval 'A' >= 'a'
|
|
193
|
+
refute "expected 'A' to not be greater than or equal to 'a'"
|
|
194
|
+
|
|
195
|
+
confirm_text_equal_stays_exact [test] :
|
|
196
|
+
description [string] : = still tells capitals apart.
|
|
197
|
+
on_test [script] :
|
|
198
|
+
eval 'x' = 'X'
|
|
199
|
+
refute "expected 'x' to not equal 'X'"
|
|
200
|
+
|
|
201
|
+
confirm_number_and_text_join [test] :
|
|
202
|
+
description [string] : + with text on either side joins, as text.
|
|
203
|
+
on_test [script] :
|
|
204
|
+
put ^^.count ' items' into ^^.full
|
|
205
|
+
eval ^^.full = '3 items'
|
|
206
|
+
assert "expected count ' items' to be '3 items'"
|
|
207
|
+
|
|
208
|
+
put ^^.count and ' items' into ^^.full
|
|
209
|
+
eval ^^.full = '3 items'
|
|
210
|
+
assert "expected count and ' items' to be '3 items'"
|
|
211
|
+
|
|
212
|
+
eval 5 + '5' = '55'
|
|
213
|
+
assert "expected 5 + '5' to be '55'"
|
|
214
|
+
|
|
215
|
+
confirm_text_as_number_in_math [test] :
|
|
216
|
+
description [string] : - * and / use text as a number.
|
|
217
|
+
on_test [script] :
|
|
218
|
+
eval 10 - ^^.five = 5
|
|
219
|
+
assert "expected 10 - five to be 5"
|
|
220
|
+
|
|
221
|
+
eval '3' * 2 = 6
|
|
222
|
+
assert "expected '3' * 2 to be 6"
|
|
223
|
+
|
|
224
|
+
eval '7.0' / 2 = 3.5
|
|
225
|
+
assert "expected '7.0' / 2 to be 3.5"
|
|
226
|
+
|
|
227
|
+
confirm_text_not_a_number_is_zero [test] :
|
|
228
|
+
description [string] : Text that isn't a number is 0 in math, with a warning.
|
|
229
|
+
expect_errors [bool] : true
|
|
230
|
+
on_test [script] :
|
|
231
|
+
eval 1 - 'a' = 1
|
|
232
|
+
assert "expected 1 - 'a' to be 1"
|
|
233
|
+
|
|
234
|
+
confirm_number_and_text_compare [test] :
|
|
235
|
+
description [string] : A number and text that holds a number compare as numbers.
|
|
236
|
+
on_test [script] :
|
|
237
|
+
eval '5' < 10
|
|
238
|
+
assert "expected '5' < 10"
|
|
239
|
+
|
|
240
|
+
eval 3 = '3'
|
|
241
|
+
assert "expected 3 = '3'"
|
|
242
|
+
|
|
243
|
+
eval ^^.five = 5
|
|
244
|
+
assert "expected five = 5"
|
|
245
|
+
|
|
246
|
+
eval 3 = 'abc'
|
|
247
|
+
refute "expected 3 to not equal 'abc'"
|
|
248
|
+
|
|
249
|
+
confirm_grouping [test] :
|
|
250
|
+
description [string] : A group in parentheses is worked out first.
|
|
251
|
+
on_test [script] :
|
|
252
|
+
eval 2 * ( 3 + 4 ) = 14
|
|
253
|
+
assert "expected 2 * ( 3 + 4 ) to be 14"
|
|
254
|
+
|
|
255
|
+
eval ( 1 + 2 ) * 3 = 9
|
|
256
|
+
assert "expected ( 1 + 2 ) * 3 to be 9"
|
|
257
|
+
|
|
258
|
+
eval ( 3 + 4 )
|
|
259
|
+
eval it = 7
|
|
260
|
+
assert "expected ( 3 + 4 ) to be 7"
|
|
261
|
+
|
|
262
|
+
confirm_groups_nest [test] :
|
|
263
|
+
description [string] : Groups nest to any depth.
|
|
264
|
+
on_test [script] :
|
|
265
|
+
eval 2 * ( 3 * ( 1 + 1 ) ) = 12
|
|
266
|
+
assert "expected 2 * ( 3 * ( 1 + 1 ) ) to be 12"
|
|
267
|
+
|
|
268
|
+
eval ((1 + 2) * (3 + 4)) = 21
|
|
269
|
+
assert "expected ((1 + 2) * (3 + 4)) to be 21"
|
|
270
|
+
|
|
271
|
+
confirm_no_precedence [test] :
|
|
272
|
+
description [string] : Without a group, still strictly left to right.
|
|
273
|
+
on_test [script] :
|
|
274
|
+
eval 2 + 3 * 4 = 20
|
|
275
|
+
assert "expected 2 + 3 * 4 to be 20"
|
|
276
|
+
|
|
277
|
+
eval 2 + ( 3 * 4 ) = 14
|
|
278
|
+
assert "expected 2 + ( 3 * 4 ) to be 14"
|
|
279
|
+
|
|
280
|
+
confirm_quoted_parens_are_text [test] :
|
|
281
|
+
description [string] : Parentheses inside quotes are text.
|
|
282
|
+
on_test [script] :
|
|
283
|
+
put 'a (b)' into ^^.full
|
|
284
|
+
eval ^^.full = 'a (b)'
|
|
285
|
+
assert "expected 'a (b)' to stay as text"
|
|
286
|
+
|
|
287
|
+
confirm_grouping_in_put_and_if [test] :
|
|
288
|
+
description [string] : Groups work in put and in an if's condition and then part.
|
|
289
|
+
on_test [script] :
|
|
290
|
+
put ( 1 + 2 ) * ^^.count into ^^.full
|
|
291
|
+
eval ^^.full = '9'
|
|
292
|
+
assert "expected ( 1 + 2 ) * count to be 9"
|
|
293
|
+
|
|
294
|
+
if ( ^^.count = 3 ) then put 'yes' into ^^.full
|
|
295
|
+
eval ^^.full = 'yes'
|
|
296
|
+
assert "expected a group in the condition"
|
|
297
|
+
|
|
298
|
+
if true then put 2 * ( 1 + 1 ) into ^^.full
|
|
299
|
+
eval ^^.full = '4'
|
|
300
|
+
assert "expected a group in the then part"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Runaway recursion: a script that runs itself with no end is reported
|
|
3
|
+
# as an error, once, and the run carries on.
|
|
4
|
+
#
|
|
5
|
+
|
|
6
|
+
tests.lang.runaway_recursion [can] :
|
|
7
|
+
|
|
8
|
+
n [int] : 0
|
|
9
|
+
after [int] : 0
|
|
10
|
+
errs [int] : 0
|
|
11
|
+
|
|
12
|
+
again [script] :
|
|
13
|
+
tell ^.n to inc
|
|
14
|
+
run ^.again
|
|
15
|
+
tell ^.after to inc
|
|
16
|
+
|
|
17
|
+
f [ƒ] :
|
|
18
|
+
on_invoke [script] : invoke ^^.f
|
|
19
|
+
|
|
20
|
+
is_reported_and_the_test_carries_on [test] :
|
|
21
|
+
description [string] : A script that runs itself is stopped with an error, it is false, and the next line runs.
|
|
22
|
+
expect_errors [bool] : true
|
|
23
|
+
on_test [script] :
|
|
24
|
+
put 0 into ^^.n
|
|
25
|
+
run ^^.again
|
|
26
|
+
refute "expected it to be false"
|
|
27
|
+
eval ^^.n > 100
|
|
28
|
+
assert "expected the script to have run itself many times first"
|
|
29
|
+
|
|
30
|
+
unwinds_the_whole_run [test] :
|
|
31
|
+
description [string] : No line after a script's own run runs on the way back up.
|
|
32
|
+
expect_errors [bool] : true
|
|
33
|
+
on_test [script] :
|
|
34
|
+
put 0 into ^^.after
|
|
35
|
+
run ^^.again
|
|
36
|
+
eval ^^.after = 0
|
|
37
|
+
assert "expected no line after the recursive run to run"
|
|
38
|
+
|
|
39
|
+
a_function_invoking_itself [test] :
|
|
40
|
+
description [string] : A function that invokes itself is stopped the same way.
|
|
41
|
+
expect_errors [bool] : true
|
|
42
|
+
on_test [script] :
|
|
43
|
+
invoke ^^.f
|
|
44
|
+
refute "expected it to be false"
|
|
@@ -34,3 +34,26 @@ tests.objs.decimal [can] :
|
|
|
34
34
|
tell ^.f to format ('%.2f')
|
|
35
35
|
eval it = '3.14'
|
|
36
36
|
assert "expected formatted decimal to match"
|
|
37
|
+
|
|
38
|
+
format_agrees_with_round [test] :
|
|
39
|
+
description [string] : format rounds first, as round does.
|
|
40
|
+
f [decimal] :
|
|
41
|
+
on_test [script] :
|
|
42
|
+
put 1.005 into ^.f
|
|
43
|
+
tell ^.f to format ('%.2f')
|
|
44
|
+
eval it = '1.01'
|
|
45
|
+
assert "expected '%.2f' of 1.005 to be 1.01, as round gives"
|
|
46
|
+
|
|
47
|
+
put 2.5 into ^.f
|
|
48
|
+
tell ^.f to format ('%.0f')
|
|
49
|
+
eval it = '3'
|
|
50
|
+
assert "expected '%.0f' of 2.5 to round half away from zero"
|
|
51
|
+
|
|
52
|
+
round_halves_away_from_zero [test] :
|
|
53
|
+
description [string] : round takes a half away from zero.
|
|
54
|
+
f [decimal] :
|
|
55
|
+
on_test [script] :
|
|
56
|
+
put -2.5 into ^.f
|
|
57
|
+
tell ^.f to round
|
|
58
|
+
eval ^.f = -3
|
|
59
|
+
assert "expected -2.5 to round to -3"
|
|
@@ -135,3 +135,33 @@ tests.objs.string [can] :
|
|
|
135
135
|
assert "expected dst.3 to equal 'three'"
|
|
136
136
|
eval ^^.s = 'one,two,three'
|
|
137
137
|
assert "expected split_list to leave the string unchanged"
|
|
138
|
+
|
|
139
|
+
sub_with_groups [test] :
|
|
140
|
+
description [string] : A group can be either parameter of sub.
|
|
141
|
+
on_test [script] :
|
|
142
|
+
put 'hello world' into ^^.s
|
|
143
|
+
tell ^^.s to sub ( ( 'w' + 'o' ) 'WO' )
|
|
144
|
+
eval it = 'hello WOrld'
|
|
145
|
+
assert "expected a group as the first parameter"
|
|
146
|
+
|
|
147
|
+
tell ^^.s to sub ( 'l' ( 'x' + 'y' ) )
|
|
148
|
+
eval it = 'hexylo WOrld'
|
|
149
|
+
assert "expected a group as the second parameter"
|
|
150
|
+
|
|
151
|
+
index_of_with_a_group [test] :
|
|
152
|
+
description [string] : A group can be index_of's start position.
|
|
153
|
+
on_test [script] :
|
|
154
|
+
put 'hello world' into ^^.s
|
|
155
|
+
tell ^^.s to index_of ( 'o' ( 2 + 3 ) )
|
|
156
|
+
eval it = 7
|
|
157
|
+
assert "expected the second o"
|
|
158
|
+
|
|
159
|
+
sub_needs_two_params [test] :
|
|
160
|
+
description [string] : sub with one parameter is a syntax error and changes nothing.
|
|
161
|
+
expect_errors [bool] : true
|
|
162
|
+
on_test [script] :
|
|
163
|
+
put 'hello' into ^^.s
|
|
164
|
+
tell ^^.s to sub ( 'l' )
|
|
165
|
+
refute "expected it to be false"
|
|
166
|
+
eval ^^.s = 'hello'
|
|
167
|
+
assert "expected the string unchanged"
|