gloo 7.1.3 → 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.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +23 -0
  3. data/docs/application.md +65 -4
  4. data/docs/development.md +10 -0
  5. data/docs/iterators.md +66 -1
  6. data/docs/language_objects.md +34 -22
  7. data/docs/language_scripting.md +23 -2
  8. data/docs/language_syntax.md +86 -3
  9. data/docs/objects.md +6 -6
  10. data/docs/operators.md +36 -2
  11. data/docs/plugins.md +26 -0
  12. data/docs/testing.md +35 -9
  13. data/docs/verbs.md +31 -3
  14. data/lib/VERSION +1 -1
  15. data/lib/VERSION_NOTES +23 -0
  16. data/lib/dependencies.rb +4 -1
  17. data/lib/gloo/app/engine.rb +151 -23
  18. data/lib/gloo/app/prompt.rb +8 -0
  19. data/lib/gloo/convert/string_to_decimal.rb +3 -6
  20. data/lib/gloo/convert/string_to_integer.rb +3 -2
  21. data/lib/gloo/core/dictionary.rb +23 -12
  22. data/lib/gloo/core/obj.rb +77 -23
  23. data/lib/gloo/core/op.rb +99 -0
  24. data/lib/gloo/core/parser.rb +15 -0
  25. data/lib/gloo/core/tokens.rb +18 -0
  26. data/lib/gloo/core/verb.rb +130 -1
  27. data/lib/gloo/exec/dispatch.rb +7 -3
  28. data/lib/gloo/exec/runaway_recursion.rb +34 -0
  29. data/lib/gloo/exec/runner.rb +46 -0
  30. data/lib/gloo/exec/script.rb +16 -2
  31. data/lib/gloo/expr/expression.rb +77 -6
  32. data/lib/gloo/expr/l_decimal.rb +18 -2
  33. data/lib/gloo/expr/l_integer.rb +5 -2
  34. data/lib/gloo/expr/op_div.rb +4 -0
  35. data/lib/gloo/expr/op_eq.rb +4 -0
  36. data/lib/gloo/expr/op_gt.rb +4 -0
  37. data/lib/gloo/expr/op_gteq.rb +4 -0
  38. data/lib/gloo/expr/op_ineq.rb +4 -0
  39. data/lib/gloo/expr/op_lt.rb +4 -0
  40. data/lib/gloo/expr/op_lteq.rb +4 -0
  41. data/lib/gloo/expr/op_minus.rb +4 -0
  42. data/lib/gloo/expr/op_mult.rb +3 -7
  43. data/lib/gloo/expr/op_plus.rb +8 -1
  44. data/lib/gloo/objs/basic/alias.rb +6 -1
  45. data/lib/gloo/objs/basic/boolean.rb +15 -6
  46. data/lib/gloo/objs/basic/decimal.rb +25 -3
  47. data/lib/gloo/objs/basic/script.rb +3 -24
  48. data/lib/gloo/objs/basic/string_msgs.rb +50 -68
  49. data/lib/gloo/objs/ctrl/until.rb +219 -0
  50. data/lib/gloo/persist/declaration_ledger.rb +9 -9
  51. data/lib/gloo/persist/declaration_writer.rb +208 -0
  52. data/lib/gloo/persist/disc_mech.rb +70 -39
  53. data/lib/gloo/persist/file_loader.rb +125 -66
  54. data/lib/gloo/persist/file_saver.rb +130 -198
  55. data/lib/gloo/persist/file_storage.rb +15 -4
  56. data/lib/gloo/persist/file_style.rb +89 -0
  57. data/lib/gloo/persist/line_splitter.rb +16 -1
  58. data/lib/gloo/persist/persist_man.rb +112 -30
  59. data/lib/gloo/persist/save_index.rb +211 -0
  60. data/lib/gloo/persist/script_body_collector.rb +16 -21
  61. data/lib/gloo/persist/source/blank_node.rb +10 -3
  62. data/lib/gloo/persist/source/comment_node.rb +10 -2
  63. data/lib/gloo/persist/source/directive_node.rb +10 -2
  64. data/lib/gloo/persist/source/obj_node.rb +174 -9
  65. data/lib/gloo/persist/source/source_doc.rb +54 -0
  66. data/lib/gloo/persist/subtree_extractor.rb +9 -37
  67. data/lib/gloo/persist/trivia_buffer.rb +7 -7
  68. data/lib/gloo/plugin/callback.rb +54 -10
  69. data/lib/gloo/plugin/ext_manager.rb +44 -0
  70. data/lib/gloo/plugin/lib_manager.rb +65 -1
  71. data/lib/gloo/shell/runner.rb +36 -9
  72. data/lib/gloo/verbs/break.rb +6 -4
  73. data/lib/gloo/verbs/check.rb +8 -2
  74. data/lib/gloo/verbs/create.rb +13 -4
  75. data/lib/gloo/verbs/if.rb +33 -10
  76. data/lib/gloo/verbs/invoke.rb +6 -1
  77. data/lib/gloo/verbs/list.rb +9 -2
  78. data/lib/gloo/verbs/load.rb +31 -22
  79. data/lib/gloo/verbs/move.rb +50 -5
  80. data/lib/gloo/verbs/put.rb +9 -2
  81. data/lib/gloo/verbs/reload.rb +2 -1
  82. data/lib/gloo/verbs/run.rb +8 -1
  83. data/lib/gloo/verbs/save.rb +30 -4
  84. data/lib/gloo/verbs/tell.rb +9 -2
  85. data/lib/gloo/verbs/unless.rb +34 -10
  86. data/lib/gloo/verbs/unload.rb +81 -16
  87. data/test.gloo/app/exit_status.test.gloo +34 -0
  88. data/test.gloo/app/fixtures/exit_after_error.gloo +9 -0
  89. data/test.gloo/ctrl/until.test.gloo +100 -0
  90. data/test.gloo/lang/computed_paths.test.gloo +98 -0
  91. data/test.gloo/lang/declaration.test.gloo +36 -0
  92. data/test.gloo/lang/fixtures/mixed_indent.gloo +5 -0
  93. data/test.gloo/lang/literal.test.gloo +43 -0
  94. data/test.gloo/lang/naming.test.gloo +44 -6
  95. data/test.gloo/lang/ops.test.gloo +193 -0
  96. data/test.gloo/lang/runaway_recursion.test.gloo +44 -0
  97. data/test.gloo/objs/decimal.test.gloo +23 -0
  98. data/test.gloo/objs/string.test.gloo +30 -0
  99. data/test.gloo/verbs/create.test.gloo +6 -21
  100. data/test.gloo/verbs/fixtures/load_beside.gloo +6 -0
  101. data/test.gloo/verbs/fixtures/lossless_text.gloo +7 -0
  102. data/test.gloo/verbs/fixtures/lossless_text_saved.gloo +9 -0
  103. data/test.gloo/verbs/if.test.gloo +41 -0
  104. data/test.gloo/verbs/load.test.gloo +22 -3
  105. data/test.gloo/verbs/move.test.gloo +39 -0
  106. data/test.gloo/verbs/save.test.gloo +239 -0
  107. data/test.gloo/verbs/unless.test.gloo +40 -0
  108. data/test.gloo/verbs/unload.test.gloo +61 -3
  109. metadata +15 -1
@@ -19,6 +19,8 @@ module Gloo
19
19
  # Run the verb.
20
20
  #
21
21
  def run
22
+ return unless take_path_arg( 1 )
23
+
22
24
  msg = @tokens.after_token( TO )
23
25
 
24
26
  unless msg
@@ -67,10 +69,14 @@ module Gloo
67
69
  'or change state, while check is used to investigate ' \
68
70
  'state. Using the verb that matches intent makes the ' \
69
71
  'code read like natural communication.',
70
- :syntax => [ 'tell {path.to.object} to {message}' ],
72
+ :syntax => [
73
+ 'tell {path.to.object} to {message}',
74
+ 'tell ( {expression} ) to {message}'
75
+ ],
71
76
  :parameters => [
72
77
  '{path.to.object} — The object that we want to send a message to.',
73
- '{message} — The message to send.'
78
+ '{message} — The message to send.',
79
+ Gloo::Core::Verb::COMPUTED_PATH_DOC
74
80
  ],
75
81
  :result => 'The result depends on the message that is sent.',
76
82
  :errors => [
@@ -82,6 +88,7 @@ module Gloo
82
88
  > tell the.script to run
83
89
  > tell my.str to up
84
90
  > tell the.container to count
91
+ > tell ( 'jobs.' name ) to run
85
92
  EXAMPLES
86
93
  :notes => <<~NOTES.strip
87
94
  tell and check send the same message the same way — the two
@@ -27,8 +27,13 @@ module Gloo
27
27
 
28
28
  @do = @tokens.expr_after( SEPARATORS, ELSE )
29
29
  @else = @tokens.expr_after( ELSE )
30
+ give_params_to_last_part
30
31
 
31
- if evals_false( value )
32
+ truth = evals_false( value )
33
+ # A condition that reported an error abandons the line.
34
+ return if truth.nil?
35
+
36
+ if truth
32
37
  run_do
33
38
  else
34
39
  run_else unless @else.blank?
@@ -55,6 +60,23 @@ module Gloo
55
60
 
56
61
  private
57
62
 
63
+ #
64
+ # A trailing ( ... ) the parser split off the line belongs to the
65
+ # command at the end of it (eg. show's colour in
66
+ # unless x do show 'a' (red)): give it back to the else part if
67
+ # there is one, otherwise to the do part.
68
+ #
69
+ def give_params_to_last_part
70
+ return unless @params.respond_to?( :cmd )
71
+
72
+ group = " ( #{@params.cmd} )"
73
+ if !@else.blank?
74
+ @else += group
75
+ elsif !@do.blank?
76
+ @do += group
77
+ end
78
+ end
79
+
58
80
  #
59
81
  # Get the list of tokens that represent the parameters
60
82
  # of the unless command.
@@ -72,18 +94,15 @@ module Gloo
72
94
  end
73
95
 
74
96
  #
75
- # Does the given value evalute to true?
97
+ # Does the given value evalute to false? The exact opposite of if:
98
+ # the [bool] rule decides (see Boolean.to_bool). Nil if working it
99
+ # out reported an error.
76
100
  #
77
101
  def evals_false( value )
78
- eval_result = false
79
- if value.count.positive?
80
- expr = Gloo::Expr::Expression.new( @engine, value )
81
- result = expr.evaluate
82
- eval_result = true if result == false
83
- eval_result = true if result.is_a?( Numeric ) && result.zero?
84
- end
102
+ result, ok = evaluate_expr( value )
103
+ return nil unless ok
85
104
 
86
- return eval_result
105
+ return !Gloo::Objs::Boolean.to_bool( @engine, result )
87
106
  end
88
107
 
89
108
  #
@@ -137,6 +156,11 @@ module Gloo
137
156
  "#{MISSING_EXPR_ERR} — No expression is provided as parameter to the verb.",
138
157
  'Other errors depend on the command that is run.'
139
158
  ],
159
+ :notes => 'What counts as true follows the [bool] rule: true, a ' \
160
+ 'number other than 0, and the text true or t are true; anything ' \
161
+ 'else is false (blank quietly, other text with a warning). See ' \
162
+ 'doc language_syntax, What Counts as True. A condition that ' \
163
+ 'reports an error abandons the line: neither command runs.',
140
164
  :examples => <<~EXAMPLES.strip
141
165
  #
142
166
  # Unless statement example
@@ -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
- # This will unload all loaded objects and reset the engine state.
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 if extra_words_err?( 'nothing was unloaded; to unload one object, use tell x to unload' )
20
- return unless @engine.persist_man.maps
21
-
22
- @engine.persist_man.unload_all
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. Use the files ' \
57
- 'command to see the list of files that will be un-loaded. ' \
58
- 'The heap will be empty after this is run, so be sure to ' \
59
- 'save state prior to executing.',
60
- :syntax => [ 'unload' ],
61
- :result => 'All objects will be unloaded from the heap.',
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 takes no object, so nothing was unloaded — anything ' \
64
- 'written after unload is an error, and nothing is unloaded. ' \
65
- 'To unload one object, use tell x to unload.'
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 takes no object; to unload just one object, ' \
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,34 @@
1
+ #
2
+ # Exit status of a script run.
3
+ # `gloo file.gloo` exits 1 if anything went wrong at any point in the
4
+ # run, not just on its last line. The engine running these tests was
5
+ # started in Test mode, so the check runs gloo again with [system],
6
+ # on a fixture beside this file.
7
+ #
8
+
9
+ tests.app.exit_status [can] :
10
+
11
+ # The interpreter and the fixture, both found from source_dir.
12
+ run_rb [string] : /../../lib/run.rb
13
+ fixture [string] : /fixtures/exit_after_error.gloo
14
+ quiet [string] : --quiet
15
+ # The fixture's error output isn't part of these tests' output.
16
+ discard [string] : > /dev/null 2>&1
17
+ where [string] :
18
+
19
+ run_gloo [system] :
20
+ command [string] :
21
+ get_output [bool] : false
22
+ result [bool] :
23
+
24
+ error_then_success_exits_1 [test] :
25
+ description [string] : A run with an error on an earlier line exits non-zero, though its last line works.
26
+ on_test [script] :
27
+ check ^^ for source_dir
28
+ put it into ^^.where
29
+ # Paths are quoted in case the folder has spaces.
30
+ put "ruby '" ^^.where ^^.run_rb "' " ^^.quiet " '" ^^.where ^^.fixture "' " ^^.discard into ^^.run_gloo.command
31
+ tell ^^.run_gloo to run
32
+ # result is false when the command exits non-zero.
33
+ eval ^^.run_gloo.result
34
+ refute "expected the run to exit non-zero"
@@ -0,0 +1,9 @@
1
+ #
2
+ # Run by exit_status.test.gloo as `gloo` would run it: an error, then
3
+ # a line that works. The run must still exit 1.
4
+ #
5
+ a [can] :
6
+ n [int] : 0
7
+ on_load [script] :
8
+ show no.such.object
9
+ put 1 into a.n
@@ -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"
@@ -41,3 +41,39 @@ END
41
41
  on_test [script] :
42
42
  eval ^^.closed_then_colon = 8
43
43
  assert "expected the value 8"
44
+
45
+ # A fixture beside this file whose lines mix tabs and spaces, on one
46
+ # line and from line to line: a tab counts as two spaces.
47
+ mixed_indent_path [string] : /fixtures/mixed_indent.gloo
48
+ where [string] :
49
+
50
+ a_tab_and_spaces_on_one_line_add_up [test] :
51
+ description [string] : a tab plus two spaces is two levels deep, in either order.
52
+ on_test [script] :
53
+ check ^^ for source_dir
54
+ put it into ^^.where
55
+ load ( ^^.where ^^.mixed_indent_path )
56
+ tell mixed_indent_fixture.a to count
57
+ eval it = 2
58
+ assert "expected x and y under a"
59
+ eval mixed_indent_fixture.b = 3
60
+ assert "expected b beside a"
61
+ tell mixed_indent_fixture to unload
62
+
63
+ # Spaces just inside the brackets are allowed.
64
+ spaced_int [ int ] : 5
65
+ spaced_after [int ]: 6
66
+ spaced_text [text ] : BEGIN
67
+ one
68
+ END
69
+
70
+ spaces_inside_the_brackets_are_allowed [test] :
71
+ description [string] : a space just inside a type's brackets doesn't change the type.
72
+ on_test [script] :
73
+ eval ^^.spaced_int = 5
74
+ assert "expected [ int ] to be an integer 5"
75
+ eval ^^.spaced_after + 1 = 7
76
+ assert "expected [int ]: to be an integer 6"
77
+ check ^^.spaced_text for starts_with? ( 'one' )
78
+ assert "expected [text ] to read its block"
79
+
@@ -0,0 +1,5 @@
1
+ mixed_indent_fixture [can] :
2
+ a [can] :
3
+ x [int] : 1
4
+ y [int] : 2
5
+ b [int] : 3
@@ -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"
@@ -4,9 +4,6 @@
4
4
 
5
5
  tests.lang.naming [can] :
6
6
 
7
- dup [string] : first
8
- dup [string] : second
9
-
10
7
  Alpha [string] : mixed case
11
8
 
12
9
  1 [string] : numeric name
@@ -18,9 +15,24 @@ tests.lang.naming [can] :
18
15
  # test so the syntax error it reports belongs to that test.
19
16
  nameless_file [file] :
20
17
 
18
+ # A fixture that declares one name twice, loaded inside its tests so
19
+ # the warning about the ignored value belongs to them.
20
+ dup_file [file] :
21
+
21
22
  # Scratch files live in the gloo tmp folder ($.gloo_tmp).
22
23
  on_load [script] :
23
24
  put $.gloo_tmp '/gloo_naming_test.gloo' into ^.nameless_file
25
+ put $.gloo_tmp '/gloo_naming_dup_test.gloo' into ^.dup_file
26
+
27
+ dup_src [text] : BEGIN
28
+ dup_fixture [container] :
29
+ dup [string] : first
30
+ dup [string] : second
31
+ box [container] :
32
+ x [string] : ex
33
+ box [container] :
34
+ y [string] : why
35
+ END
24
36
 
25
37
  nameless_src [text] : BEGIN
26
38
  naming_fixture [container] :
@@ -28,10 +40,36 @@ naming_fixture [container] :
28
40
  END
29
41
 
30
42
  first_of_a_duplicate_name_wins [test] :
31
- description [string] : when two siblings share a name, the path always reaches the first.
43
+ description [string] : a second declaration of a name is the same object; the first value wins.
44
+ expect_errors [bool] : true
45
+ on_test [script] :
46
+ tell ^^.dup_file to write ( ^^.dup_src )
47
+ load ( ^^.dup_file )
48
+ eval dup_fixture.dup = 'first'
49
+ assert "expected the first value to win"
50
+
51
+ tell dup_fixture to count
52
+ eval it = 2
53
+ assert "expected one 'dup' and one 'box', not four objects"
54
+
55
+ tell dup_fixture to unload
56
+ tell ^^.dup_file to delete
57
+
58
+ a_container_declared_twice_merges [test] :
59
+ description [string] : a container declared twice is one container with the children of both.
60
+ expect_errors [bool] : true
32
61
  on_test [script] :
33
- eval ^^.dup = 'first'
34
- assert "expected the first 'dup' to be the one reached"
62
+ tell ^^.dup_file to write ( ^^.dup_src )
63
+ load ( ^^.dup_file )
64
+ tell dup_fixture.box to count
65
+ eval it = 2
66
+ assert "expected x and y in the one box"
67
+
68
+ eval dup_fixture.box.y = 'why'
69
+ assert "expected the second declaration's child to be there"
70
+
71
+ tell dup_fixture to unload
72
+ tell ^^.dup_file to delete
35
73
 
36
74
  path_lookup_is_case_insensitive [test] :
37
75
  description [string] : a pathname segment matches a name regardless of case.