markdown_exec 2.8.5 → 3.0.1

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -1
  3. data/Gemfile.lock +1 -1
  4. data/Rakefile +0 -33
  5. data/bats/bats.bats +2 -0
  6. data/bats/block-type-link.bats +1 -1
  7. data/bats/block-type-ux-allowed.bats +2 -2
  8. data/bats/block-type-ux-invalid.bats +1 -1
  9. data/bats/block-type-ux-required-variables.bats +20 -0
  10. data/bats/block-type-ux-row-format.bats +1 -1
  11. data/bats/block-type-ux-sources.bats +36 -0
  12. data/bats/border.bats +1 -1
  13. data/bats/cli.bats +2 -2
  14. data/bats/command-substitution-options.bats +14 -0
  15. data/bats/command-substitution.bats +1 -1
  16. data/bats/fail.bats +5 -2
  17. data/bats/import.bats +8 -0
  18. data/bats/indented-block-type-vars.bats +1 -1
  19. data/bats/markup.bats +1 -1
  20. data/bats/option-expansion.bats +8 -0
  21. data/bats/table-column-truncate.bats +1 -1
  22. data/bats/test_helper.bash +50 -5
  23. data/docs/dev/bats-document-configuration.md +1 -1
  24. data/docs/dev/block-type-ux-allowed.md +5 -7
  25. data/docs/dev/block-type-ux-auto.md +8 -5
  26. data/docs/dev/block-type-ux-chained.md +4 -2
  27. data/docs/dev/block-type-ux-echo-hash.md +6 -7
  28. data/docs/dev/block-type-ux-echo.md +2 -2
  29. data/docs/dev/block-type-ux-exec.md +3 -5
  30. data/docs/dev/block-type-ux-hidden.md +3 -0
  31. data/docs/dev/{block-type-ux-preconditions.md → block-type-ux-required-variables.md} +2 -3
  32. data/docs/dev/block-type-ux-row-format.md +3 -4
  33. data/docs/dev/block-type-ux-sources.md +57 -0
  34. data/docs/dev/block-type-ux-transform.md +0 -4
  35. data/docs/dev/command-substitution-options.md +61 -0
  36. data/docs/dev/indented-block-type-vars.md +1 -0
  37. data/docs/dev/menu-pagination-indent.md +123 -0
  38. data/docs/dev/menu-pagination.md +111 -0
  39. data/docs/dev/option-expansion.md +10 -0
  40. data/lib/ansi_formatter.rb +2 -0
  41. data/lib/block_cache.rb +197 -0
  42. data/lib/cached_nested_file_reader.rb +3 -1
  43. data/lib/command_result.rb +57 -0
  44. data/lib/constants.rb +19 -1
  45. data/lib/error_reporting.rb +38 -0
  46. data/lib/evaluate_shell_expressions.rb +43 -18
  47. data/lib/fcb.rb +98 -7
  48. data/lib/hash_delegator.rb +544 -330
  49. data/lib/markdown_exec/version.rb +1 -1
  50. data/lib/markdown_exec.rb +136 -45
  51. data/lib/mdoc.rb +59 -10
  52. data/lib/menu.src.yml +23 -11
  53. data/lib/menu.yml +22 -12
  54. data/lib/value_or_exception.rb +76 -0
  55. metadata +16 -4
  56. data/bats/block-type-ux-preconditions.bats +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 718a29bb9eed1123158ffab68a01866fcdbc0126736c5305eae92dd661fb7396
4
- data.tar.gz: 05e374bda6ac5603b13d50a33ef36cffd25d8fccdf43733107d63d19395ee9a5
3
+ metadata.gz: 6105f345e0f4e3b856fc2209f92872c3ab08aa1f7dadab2e3dba4fa686a8d20c
4
+ data.tar.gz: 3463e2cf4f292621d34007a55953744769047747c62fb20408e9a3c7070dc617
5
5
  SHA512:
6
- metadata.gz: 18629932f2c6b095329f56ec594eb1016df88b17278ef544f6954f793f054e55c137b8240692392ebba9165c15e0f58b6c1e3883447fa740c90fa1fccb20f351
7
- data.tar.gz: bc1e0a9ea38227dc83136f2884934ed6dfed93a4c1e73c4c1faa8a6188b2bc7a197062d356f2e3ff5665629e04de46d40904191de9d23af9b6ba31c9f26953d5
6
+ metadata.gz: dd25c39ccfefc8d5db5dd8ec985a4c7537824f631e916b18a17236504ea077eac24bc45eed13bd13756dad18ab045422c583b8479d32e9379219dc7f58682f7b
7
+ data.tar.gz: '084bc0518c1b016c738361f2dcc076cf0f51e5cb56b91b54f21880be09198b2d2176a5428ae2f2dfcedd09de34e73f45c278c13c705db04cc83b3bda8a8f5cb5'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.0.1] - 2025-05-21
4
+
5
+ ### Changed
6
+
7
+ - Block ids to reflect source file when imported.
8
+ - Disable UX block warnings for initial values.
9
+
10
+ ## [3.0.0] - 2025-05-20
11
+
12
+ ### Added
13
+
14
+ - UX block keys 'act' and 'init' specify initial and activation behavior.
15
+ - Inactive targets in long blocks of text to smooth navigation.
16
+ - Options to display configuration keys and values similar to other shell expansions.
17
+
18
+ ### Changed
19
+
20
+ - Rename UX block key 'default' to 'init' except when used in a prompt for input from the user.
21
+ - Rename UX block keys 'allow', 'format', 'require'.
22
+ - Handle user selecting 'Back' when saving.
23
+ - Modify internal block IDs.
24
+ - Remove extraneous final newline in output.
25
+ - UX block required variables are temporary for evaluation.
26
+
3
27
  ## [2.8.5] - 2025-04-07
4
28
 
5
29
  ### Added
@@ -71,7 +95,7 @@
71
95
 
72
96
  ### Added
73
97
 
74
- - UX blocks can add preconditions. Preconditions are variable names that must be set before the UX block is executed. If any preconditions are not set, a warning is displayed, and the sequence is aborted.
98
+ - UX blocks can specify required variables. The variables must be present before the UX block is executed. If any required variables are not set, a warning is displayed, and the sequence is aborted.
75
99
  - UX blocks can require shell an other UX blocks.
76
100
  - UX blocks are evaluated in order and calculation can depend on prior variables in the same sequence.
77
101
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (2.8.5)
4
+ markdown_exec (3.0.1)
5
5
  clipboard (~> 1.3.6)
6
6
  open3 (~> 0.1.1)
7
7
  optparse (~> 0.1.1)
data/Rakefile CHANGED
@@ -127,8 +127,6 @@ task :minitest do
127
127
  './lib/dev/hierarchy.rb --verbose',
128
128
  './lib/dev/process_command.rb --verbose',
129
129
  './lib/dev/process_template.rb --test --verbose',
130
- # './lib/dev/ruby_file_processor.rb --test --verbose',
131
- # './lib/dev/std_out_err_logger.rb', ### errs
132
130
  './lib/dev/visibility-controller.rb --verbose',
133
131
  './lib/directory_searcher.rb --verbose',
134
132
  './lib/evaluate_shell_expressions.rb --verbose',
@@ -147,7 +145,6 @@ task :minitest do
147
145
  './lib/resize_terminal.rb --verbose',
148
146
  './lib/saved_assets.rb --verbose',
149
147
  './lib/saved_files_matcher.rb --verbose',
150
- # './lib/shell_session.rb --verbose',
151
148
  './lib/table_extractor.rb --verbose',
152
149
  './lib/text_analyzer.rb --verbose'
153
150
  ]
@@ -258,33 +255,3 @@ def words_list(words)
258
255
  %("#{word}")
259
256
  end.join ' '
260
257
  end
261
-
262
- desc 'Build the Docker image for MarkdownExec'
263
- task :docker_build do
264
- dockerfile = 'Dockerfile.ruby-3.3'
265
- image_tag = "mde-#{MarkdownExec::VERSION}.gem"
266
-
267
- command = [
268
- "docker build",
269
- "--build-arg VERSION=#{MarkdownExec::VERSION}",
270
- "-f #{dockerfile}",
271
- "-t #{image_tag}",
272
- "."
273
- ].join(' ')
274
-
275
- puts "Building Docker image: #{image_tag} using #{dockerfile}..."
276
- puts system(command) || abort("Docker build failed. Please check the output for details.")
277
- end
278
-
279
- desc 'Launch an interactive Docker Bash shell'
280
- task :docker_exec do
281
- exec "docker exec -it mde-#{MarkdownExec::VERSION}.gem bash"
282
- end
283
-
284
- desc 'Run the mde binary inside a Docker container. eg `docker_run -- args`'
285
- task :docker_run, [:args] do
286
- args = ARGV.dup
287
- args.shift
288
- args.shift if args[0] == '--'
289
- exec "docker run -it mde-#{MarkdownExec::VERSION}.gem mde #{args.join(' ')}"
290
- end
data/bats/bats.bats CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env bats
2
2
 
3
+ # this file is skipped during code checks.
4
+
3
5
  greet () {
4
6
  echo "Hello, $1"'!'
5
7
  sleep 9
@@ -4,6 +4,6 @@ load 'test_helper'
4
4
 
5
5
  @test 'Link blocks - set variable in link block; call hidden block' {
6
6
  # __Exit is required as last block is a Link type
7
- run_mde_specs_md_args_expect_xansi '[VARIABLE1]' __Exit ' VARIABLE1: 1'
7
+ run_mde_specs_md_args_expect_xansi '[VARIABLE1]' $EXIT_MENU ' VARIABLE1: 1'
8
8
  run_mde_specs_md_args_expect_xansi '[VARIABLE1]' '(echo-VARIABLE1)' ' VARIABLE1: 1 VARIABLE1: 1'
9
9
  }
@@ -4,14 +4,14 @@ load 'test_helper'
4
4
 
5
5
  @test 'automatic blocks load defaults - constants or first allowed from output of echo or exec' {
6
6
  spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-allowed.md \
7
- 'SPECIES=Pongo tapanuliensis_GENUS=Pongo_FAMILY=_ORDER=Click to select..._CLASS=Click to select..._YEAR_DISCOVERED=_NAME=Tapanuli Orangutan'
7
+ 'SPECIES=Pongo tapanuliensis_GENUS=Pongo_FAMILY=_ORDER: Click to select..._Click to select..._YEAR_DISCOVERED=_NAME=Tapanuli Orangutan'
8
8
  }
9
9
 
10
10
  @test 'executing a block loads the first allowed value' {
11
11
  skip 'Unable to test the menu presented'
12
12
  spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-allowed.md \
13
13
  '[FAMILY]' \
14
- 'SPECIES=Pongo tapanuliensis_GENUS=Pongo_FAMILY=Hominidae_ORDER=Click to select..._CLASS=Click to select..._YEAR_DISCOVERED=_NAME='
14
+ 'SPECIES=Pongo tapanuliensis_GENUS=Pongo_FAMILY=Hominidae_Click to select...Click to select..._YEAR_DISCOVERED=_NAME='
15
15
  }
16
16
 
17
17
  @test 'executing a block loads the first line in the output of exec' {
@@ -4,5 +4,5 @@ load 'test_helper'
4
4
 
5
5
  @test 'automatic block is invalid YAML' {
6
6
  spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-invalid.md \
7
- '_Error: HashDelegator../docs/dev/block-type-ux-invalid.md_vmlpd_bfnf_b_3 - --- !ruby/object:NullResult_message: Invalid YAML_data: invalid_ -- -- '
7
+ '_Error: HashDelegator.ItrBlkFrmNstFls:1¤./docs/dev/block-type-ux-invalid.md:1 - --- !ruby/object:NullResult_message: Invalid YAML_data: invalid_ -- -- '
8
8
  }
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test 'An undefined variable is a precondition - initial' {
6
+ spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-required-variables.md \
7
+ 'SPECIES='
8
+ }
9
+
10
+ # hangs
11
+ # Enter a value: []: #<Errno::EISDIR: Is a directory @ io_fillbuf - fd:12 test>
12
+ # ["/Users/fareed/Documents/dev/ruby/markdown_exec/lib/hash_delegator.rb:4650:in `gets'",
13
+ # "/Users/fareed/Documents/dev/ruby/markdown_exec/lib/hash_delegator.rb:4650:in `gets'",
14
+ # "/Users/fareed/Documents/dev/ruby/markdown_exec/lib/hash_delegator.rb:4650:in `block in ux_block_export_activated'",
15
+ #
16
+ #@test 'An undefined variable is a precondition - active' {
17
+ # spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-required-variables.md \
18
+ # test \
19
+ # 'A value must exist for: MISSING_VARIABLE_SPECIES='
20
+ #}
@@ -4,5 +4,5 @@ load 'test_helper'
4
4
 
5
5
  @test 'Row format merges with prior table' {
6
6
  spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-row-format.md \
7
- ' | Variable | Value | Prompt |_ | --------- | ---------------- | ------------------- |_ | Species | Pongo tapanulien | New species? |_ | Name: Gen | Value: Pongo | Prompt: New genus? |_ | Family | Hominidae | Enter a value: |'
7
+ " | Variable | Value | Prompt |_ | ---------- | -------------------- | --------------------- |_ | Species | Pongo tapanuliensis | New species? |_ | Name: Genu | Value: Xform: 'Pongo | Prompt: New genus? |_ | Family | Hominidae | Enter a value: |"
8
8
  }
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test 'dname' {
6
+ spec_mde_xansi_message_doc_blocks_expect docs/dev/block-type-ux-sources.md \
7
+ dname \
8
+ 'USER_NAME=Guest_CURRENT_DIR=markdown_exec_SHELL_VERSION=/bin/bash_ENVIRONMENT=development_USER_EMAIL=_VERSION='
9
+ }
10
+
11
+ @test 'init_source' {
12
+ spec_mde_xansi_message_doc_blocks_expect docs/dev/block-type-ux-sources.md \
13
+ export_init \
14
+ 'default_exec_echo_allow_false_false'
15
+ }
16
+
17
+ @test 'act_source' {
18
+ spec_mde_xansi_message_doc_blocks_expect docs/dev/block-type-ux-sources.md \
19
+ export_act \
20
+ 'edit_edit_edit_allow_edit_edit'
21
+ }
22
+
23
+ @test 'is_disabled?' {
24
+ spec_mde_xansi_message_doc_blocks_expect docs/dev/block-type-ux-sources.md \
25
+ is_disabled? \
26
+ 'false_false_false_false_false_false'
27
+ }
28
+
29
+ # test trigger presents prompt
30
+ # test trigger presents allow list
31
+ # test validation limits input
32
+ # test transform formats output
33
+ # test format creates output
34
+ # test default, validation, prompt are displayed
35
+
36
+ # bin/bmde docs/dev/block-type-ux-sources.md --list-blocks-message init_source --list-blocks-type 3 --list-blocks
data/bats/border.bats CHANGED
@@ -4,5 +4,5 @@ load 'test_helper'
4
4
 
5
5
  @test 'Border - ' {
6
6
  spec_mde_xansi_dname_doc_blocks_expect docs/dev/border.md \
7
- 'A: 1_ B: 2_'
7
+ 'A: 1_B: 2'
8
8
  }
data/bats/cli.bats CHANGED
@@ -39,14 +39,14 @@ load 'test_helper'
39
39
  # the last block is a link block, so menu is displayed
40
40
  @test 'link block setting an environment variable requires a bash block' {
41
41
  BATS_OUTPUT_FILTER=A
42
- spec_mde_args_expect docs/dev/requiring-blocks.md '[link-local-block-with-vars]' __Exit \
42
+ spec_mde_args_expect docs/dev/requiring-blocks.md '[link-local-block-with-vars]' $EXIT_MENU \
43
43
  ' ARG1: 37'
44
44
  }
45
45
 
46
46
  # the last block is a link block, so menu is displayed
47
47
  @test 'link block setting an environment variable calls a bash block in a file' {
48
48
  BATS_OUTPUT_FILTER=A
49
- spec_mde_args_expect docs/dev/requiring-blocks.md '[link-file-block-with-vars]' __Exit \
49
+ spec_mde_args_expect docs/dev/requiring-blocks.md '[link-file-block-with-vars]' $EXIT_MENU \
50
50
  ' ARG1: arg1-from-link-file'
51
51
  }
52
52
 
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test 'Operator $' {
6
+ spec_mde_xansi_dname_doc_blocks_expect docs/dev/command-substitution-options.md \
7
+ 'operator_$' \
8
+ 'Command substitution__The current value of environment variable Common_Name_is displayed using two different operators._The command echo $SHLVL is executed via command_substitution, using two different operators.__| Operato | Variable Expansio | Command Substitutio |_| ------- | ----------------- | ------------------- |_| $ | Tapanuli Oranguta | Pongo tapanuliensis |_| @ | @{Common_Name} | @(echo $Species) |__Toggle between operators.__operator_$__operator_@'
9
+ }
10
+
11
+ @test 'Operator @' {
12
+ spec_mde_xansi_dname_doc_blocks_expect docs/dev/command-substitution-options.md \
13
+ 'Command substitution__The current value of environment variable Common_Name_is displayed using two different operators._The command echo $SHLVL is executed via command_substitution, using two different operators.__| Operato | Variable Expansio | Command Substitutio |_| ------- | ----------------- | ------------------- |_| $ | ${Common_Name} | $(echo $Species) |_| @ | Tapanuli Oranguta | Pongo tapanuliensis |__Toggle between operators.__operator_$__operator_@'
14
+ }
@@ -4,5 +4,5 @@ load 'test_helper'
4
4
 
5
5
  @test 'Command substitution' {
6
6
  spec_mde_xansi_dname_doc_blocks_expect docs/dev/command-substitution.md \
7
- 'CURRENT BASE NAME IS: MARKDOWN_EXEC_current base name is: markdown_exec_current base name is: markdown_exec_| current base name |_| ----------------- |_| markdown_exec |_: notice the string is not expanded in Shell block types (names or body)._ echo "current base name is now $(basename `pwd`)"__load: file_markdown_exec.sh_Status not zero: $(err)'
7
+ 'CURRENT BASE NAME IS: MARKDOWN_EXEC_current base name is: markdown_exec_current base name is: markdown_exec_| current base name |_| ----------------- |_| markdown_exec |_: notice the string is not expanded in Shell block types (names or body)._echo "current base name is now $(basename `pwd`)"_load: file_markdown_exec.sh_Status not zero: $(err)'
8
8
  }
data/bats/fail.bats CHANGED
@@ -2,10 +2,13 @@
2
2
 
3
3
  load 'test_helper'
4
4
 
5
+ # this file contains a test that fails.
6
+ # this file is skipped during code checks.
7
+
5
8
  @test 'FAIL' {
6
- run_mde_specs_md_args_expect_xansi '[VARIABLE1]' '__Exit' ' VARIABLE1: FAIL'
9
+ run_mde_specs_md_args_expect_xansi '[VARIABLE1]' $EXIT_MENU ' VARIABLE1: FAIL'
7
10
  }
8
11
 
9
12
  @test 'OK' {
10
- run_mde_specs_md_args_expect_xansi '[VARIABLE1]' '__Exit' ' VARIABLE1: 1'
13
+ run_mde_specs_md_args_expect_xansi '[VARIABLE1]' $EXIT_MENU ' VARIABLE1: 1'
11
14
  }
data/bats/import.bats CHANGED
@@ -14,3 +14,11 @@ load 'test_helper'
14
14
  spec_mde_args_expect docs/dev/import-missing.md \
15
15
  ' Error: CachedNestedFileReader.readlines -- No such file or directory - this-is-missing.md @@ '
16
16
  }
17
+
18
+ @test 'Directives - import; list block ids' {
19
+ BATS_OUTPUT_FILTER=A
20
+ BATS_SAFE=_
21
+ spec_mde_args_expect docs/dev/import.md \
22
+ --list-block-message id --list-blocks \
23
+ 'ItrBlkFrmNstFls:1¤./docs/dev/specs-import.md:0_ItrBlkFrmNstFls:4¤./docs/dev/specs-import.md:3_ItrBlkFrmNstFls:7¤./docs/dev/specs-import.md:6'
24
+ }
@@ -5,5 +5,5 @@ load 'test_helper'
5
5
  @test 'an indented block with multiple lines' {
6
6
  BATS_OUTPUT_FILTER=A
7
7
  spec_mde_xansi_dname_doc_blocks_expect docs/dev/indented-block-type-vars.md \
8
- ' Species: Pongo tapanuliensis_ Genus: Pongo_'
8
+ ' Species: Pongo tapanuliensis_ Genus: Pongo'
9
9
  }
data/bats/markup.bats CHANGED
@@ -53,5 +53,5 @@ load 'test_helper'
53
53
  #}
54
54
 
55
55
  # @test 'OK' {
56
- # run_mde_specs_md_args_expect_xansi '[VARIABLE1]' '__Exit' ' VARIABLE1: 1'
56
+ # run_mde_specs_md_args_expect_xansi '[VARIABLE1]' $EXIT_MENU ' VARIABLE1: 1'
57
57
  # }
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test '' {
6
+ spec_mde_xansi_dname_doc_blocks_expect docs/dev/option-expansion.md \
7
+ '_| Optio | Description | Value | Va | Def |_| ----- | -------------------------------- | ----- | -- | --- |_| scree | Screen width for document and in | 2 | 64 | 0 |_| table | | 5 | fa | tru |'
8
+ }
@@ -4,5 +4,5 @@ load 'test_helper'
4
4
 
5
5
  @test 'Tables - truncate columns' {
6
6
  spec_mde_xansi_dname_doc_blocks_expect docs/dev/table-column-truncate.md \
7
- 'DEMONSTRATE TRUNCATION OF TEXT IN TABLE CELLS__| Common Name | Species | Genus | Family | Year Di |_| ------------ | ------------ | ----- | ------- | ------- |_| Tapanuli Ora | Pongo tapanu | Pongo | Hominid | 2017 |_| Psychedelic | Histiophryne | Histi | Antenna | 2009 |_| Ruby Seadrag | Phyllopteryx | Phyll | Syngnat | 2015 |_| Illacme tobi | Illacme tobi | Illac | Siphono | 2016 |_| Spiny Dandel | Taraxacum ja | Tarax | Asterac | 2022 |__'
7
+ 'DEMONSTRATE TRUNCATION OF TEXT IN TABLE CELLS__| Common Name | Species | Genus | Family | Year Di |_| ------------ | ------------ | ----- | ------- | ------- |_| Tapanuli Ora | Pongo tapanu | Pongo | Hominid | 2017 |_| Psychedelic | Histiophryne | Histi | Antenna | 2009 |_| Ruby Seadrag | Phyllopteryx | Phyll | Syngnat | 2015 |_| Illacme tobi | Illacme tobi | Illac | Siphono | 2016 |_| Spiny Dandel | Taraxacum ja | Tarax | Asterac | 2022 |_'
8
8
  }
@@ -1,5 +1,35 @@
1
1
  # facilitate execution of program, comparison of output
2
2
 
3
+ EXIT_MENU=__Exit # name of menu Exit option
4
+
5
+ # Compare two byte sequences (strings or files) and report each difference:
6
+ # • zero-based byte offset
7
+ # • expected byte (0xHEX) and printable character (or “.”)
8
+ # • actual byte (0xHEX) and printable character (or “.”)
9
+ compare_bytes () {
10
+ set +e
11
+ local mode="$1"; shift
12
+ if [[ "$mode" == "--file" ]]; then
13
+ local f1="$1" f2="$2"
14
+ exec 3<"$f1" 4<"$f2"
15
+ # read raw bytes from file descriptors 3 and 4
16
+ cmp --verbose /dev/fd/3 /dev/fd/4
17
+ else
18
+ local live="$mode" expect="$1"
19
+ # feed the two strings into cmp via process-substitution
20
+ cmp --verbose <(printf '%s' "$live") <(printf '%s' "$expect")
21
+ fi |
22
+ head -n 3 |
23
+ gawk '{
24
+ live = strtonum(0 $2)
25
+ expect = strtonum(0 $3)
26
+ offset = $1 - 1
27
+ printf "Offset 0x%X (%4d): output \"%c\" 0x%02X (%3d) vs expect \"%c\" 0x%02X (%3d)\n", \
28
+ offset, offset, live, live, live, expect, expect, expect
29
+ }'
30
+ set -e
31
+ }
32
+
3
33
  date_from_history_file_name () {
4
34
  basename "$1" | sed -E 's/.*([0-9]{4}-[0-9]{2}-[0-9]{2}).*/\1/'
5
35
  }
@@ -13,23 +43,27 @@ echo_hexdump_expected_output_filter () {
13
43
  local output="$2"
14
44
  local filter="$3"
15
45
 
46
+ # print label, line, character count; output
16
47
  echo -e "- output_$(echo "$output" | wc -l)_$(echo -n "$output" | wc -c):\n$output"
17
48
  if [[ $filter == A ]]; then
49
+ # print label, line, character count; converted output
18
50
  echo -e "- converted_$(echo "$output" | wc -l)_$(echo -n "$output" | wc -c):"
19
51
  echo "$(remove_ansi_escape_sequences "$output")"
20
52
  fi
53
+ # print label, line, character count; expected output
21
54
  echo -e "- expected_$(echo "$expected" | wc -l)_$(echo -n "$expected" | wc -c):\n$expected"
22
55
 
23
56
  if [[ $filter == A ]]; then
24
- echo "- output"
25
- echo_hexdump "$output"
57
+ # print label and hex dump of converted output
26
58
  echo "- converted"
27
59
  echo_hexdump "$(remove_ansi_escape_sequences "$output")"
60
+ # print label and hex dump of expected output
28
61
  echo "- expected"
29
62
  echo_hexdump "$expected"
30
63
 
31
- # print the byte offset of the first difference
32
- #diff <(remove_ansi_escape_sequences "$output") <(echo -n "$expected") | grep "^[0-9a-f]{8} " | cut -c 1-8
64
+ # print the byte offset of the first few differences
65
+ echo "- offset"
66
+ compare_bytes "$(remove_ansi_escape_sequences "$output")" "$expected"
33
67
  fi
34
68
  }
35
69
 
@@ -210,8 +244,8 @@ spec_mde_args_grep_filter_expect () {
210
244
 
211
245
  if ( ! expect_equal_with_conversion "$expected" "$output" "$filter"); then
212
246
  echo_hexdump_expected_output_filter "$expected" "$output" "$filter"
247
+ return 1
213
248
  fi
214
- expect_equal_with_conversion "$expected" "$output" "$filter"
215
249
  [[ -n $status ]] && echo "- status: $status"
216
250
  [[ -n $status ]]
217
251
  }
@@ -237,6 +271,17 @@ spec_mde_xansi_dname_doc_blocks_expect () {
237
271
  "${!#}"
238
272
  }
239
273
 
274
+ spec_mde_xansi_message_doc_blocks_expect () {
275
+ BATS_OUTPUT_FILTER=A
276
+ BATS_SAFE=_
277
+ spec_mde_args_expect "$1" \
278
+ "${@:3:$(($#-3))}" \
279
+ --list-blocks-message "$2" \
280
+ --list-blocks-type 3 \
281
+ --list-blocks \
282
+ "${!#}"
283
+ }
284
+
240
285
  spec_mde_xansi_oname_doc_blocks_expect () {
241
286
  BATS_OUTPUT_FILTER=A
242
287
  BATS_SAFE=_
@@ -31,4 +31,4 @@ script_execution_tail:
31
31
  user_must_approve: false
32
32
 
33
33
  clear_screen_for_select_block: false
34
- ```
34
+ ```
@@ -3,13 +3,11 @@
3
3
  allowed:
4
4
  - Pongo tapanuliensis
5
5
  - Histiophryne psychedelica
6
- default: :allowed
7
6
  name: SPECIES
8
7
  ```
9
8
  / automatic block loads first line in output of exec
10
9
  ```ux :[document_ux_GENUS]
11
10
  allowed: :exec
12
- default: :allowed
13
11
  exec: echo "Pongo\nHistiophryne psychedelica"
14
12
  name: GENUS
15
13
  ```
@@ -18,7 +16,7 @@ name: GENUS
18
16
  allowed:
19
17
  - Hominidae
20
18
  - Antennariidae
21
- default: ''
19
+ init: false
22
20
  name: FAMILY
23
21
  ```
24
22
  / automatic block loads default value that is not in allowed list
@@ -26,13 +24,13 @@ name: FAMILY
26
24
  allowed:
27
25
  - Primates
28
26
  - Lophiiformes
29
- default: Click to select...
27
+ format: '%{name}: Click to select...'
30
28
  name: ORDER
31
29
  ```
32
30
  / automatic block loads default value, not in allowed list from echo
33
31
  ```ux :[document_ux_CLASS]
34
32
  allowed: :echo
35
- default: Click to select...
33
+ format: Click to select...
36
34
  echo: |
37
35
  Mammalia
38
36
  Actinopterygii
@@ -41,14 +39,14 @@ name: CLASS
41
39
  / executed block presents a menu of the lines in the output of exec
42
40
  ```ux :[YEAR_DISCOVERED]
43
41
  allowed: :exec
44
- default: ''
42
+ init: false
43
+ prompt: ''
45
44
  exec: echo "2017\n2009"
46
45
  name: YEAR_DISCOVERED
47
46
  ```
48
47
  / automatic block presents a menu of the lines in the output of echo
49
48
  ```ux :[document_ux_NAME]
50
49
  allowed: :echo
51
- default: :allowed
52
50
  echo: |
53
51
  Tapanuli Orangutan
54
52
  Psychedelic Frogfish
@@ -6,26 +6,28 @@ name: v1
6
6
  / name and default
7
7
  / transform and validate options not applied to default
8
8
  ```ux
9
- default: ''
9
+ init: false
10
10
  echo: 11
11
11
  name: v2
12
12
  ```
13
13
  / name and default; auto-load
14
14
  / prompt option is ignored during auto-load
15
15
  ```ux :[document_ux_v3]
16
- default: 12
16
+ init: :echo
17
+ echo: 12
17
18
  name: v3
18
19
  ```
19
20
  / name, default, exec; auto-load static
20
21
  ```ux :[document_ux_v4]
21
- default: 21
22
+ init: :echo
23
+ echo: 21
22
24
  exec: basename $(pwd)
23
25
  name: v4
24
26
  ```
25
27
  / name, default, exec; auto-load executed `basename $(pwd)`
26
28
  / allowed is ignored by exec
27
29
  ```ux :[document_ux_v5]
28
- default: :exec
30
+ init: :exec
29
31
  exec: basename $(pwd)
30
32
  name: v5
31
33
  ```
@@ -34,7 +36,8 @@ name: v5
34
36
  allowed:
35
37
  - 32
36
38
  - 33
37
- default: 31
39
+ init: :echo
40
+ echo: 31
38
41
  name: v6
39
42
  ```
40
43
  @import bats-document-configuration.md
@@ -3,19 +3,21 @@
3
3
  ENTITY='Pongo tapanuliensis,Pongo'
4
4
  ```
5
5
  ```ux :[SPECIES] +(shell) +(GENUS)
6
+ act: :echo
6
7
  echo: "${ENTITY%%,*}"
8
+ init: false
7
9
  name: SPECIES
8
10
  ```
9
11
  / required ux block requires another
10
12
  ```ux :(GENUS) +[NAME]
11
13
  echo: "${ENTITY##*,}"
14
+ init: false
12
15
  name: GENUS
13
- readonly: true
14
16
  ```
15
17
  / executed in context of prior ux blocks, uses their values
16
18
  ```ux :[NAME]
17
19
  echo: "$SPECIES - $GENUS"
20
+ init: false
18
21
  name: NAME
19
- readonly: true
20
22
  ```
21
23
  @import bats-document-configuration.md
@@ -1,6 +1,5 @@
1
1
  / This automatic block sets multiple variables and displays the first variable.
2
2
  ```ux :[document_ux_BASENAME]
3
- default: :echo
4
3
  echo:
5
4
  BASENAME: "$(basename `pwd`)"
6
5
  DOCUMENTS: "${BASENAME%%_*}"
@@ -10,19 +9,19 @@ readonly: true
10
9
  ```
11
10
  / This block displays the second variable in the first block.
12
11
  ```ux :[DOCUMENTS]
13
- default: false
12
+ init: false
14
13
  name: DOCUMENTS
15
14
  readonly: true
16
15
  ```
17
16
  / This block displays the third variable in the first block.
18
17
  ```ux :[OPERATION]
19
- default: false
18
+ init: false
20
19
  name: OPERATION
21
20
  readonly: true
22
21
  ```
23
22
  / Multiple UX blocks to set many variables for a specific name.
24
23
  ```ux
25
- default: false
24
+ init: false
26
25
  echo:
27
26
  Species: Pongo tapanuliensis
28
27
  Genus: Pongo
@@ -37,7 +36,7 @@ menu_format: 'Load %{name}'
37
36
  name: Tapanuli Orangutan
38
37
  ```
39
38
  ```ux
40
- default: false
39
+ init: false
41
40
  echo:
42
41
  Species: Histiophryne psychedelica
43
42
  Genus: Histiophryne
@@ -56,7 +55,7 @@ name: Psychedelic Frogfish
56
55
  | -| -
57
56
  / A read-only variable in a UX block in a table
58
57
  ```ux
59
- default: false
58
+ init: false
60
59
  menu_format: '| %{name}| ${%{name}}'
61
60
  name: Species
62
61
  readonly: true
@@ -65,7 +64,7 @@ readonly: true
65
64
  | Genus| ${Genus}
66
65
  / An editable variable in a UX block in a table
67
66
  ```ux
68
- default: false
67
+ init: false
69
68
  menu_format: '| %{name}| ${%{name}}'
70
69
  name: Family
71
70
  ```
@@ -9,14 +9,14 @@ menu_with_inherited_lines: true
9
9
  ```
10
10
  / This block is not visible. Execute to set a new value, displayed by the block above.
11
11
  ```ux :(VAR_has_count)
12
- default: false
12
+ init: false
13
13
  echo: $(basename `pwd` | wc -c)
14
14
  force: false
15
15
  name: VAR
16
16
  ```
17
17
  / This block is visible. Execute to set a new value, displayed by the block above.
18
18
  ```ux :[IAB_has_count]
19
- default: false
19
+ init: false
20
20
  echo: $VAR$VAR
21
21
  name: IAB
22
22
  ```