markdown_exec 2.2.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +16 -4
  3. data/CHANGELOG.md +28 -0
  4. data/Gemfile.lock +1 -1
  5. data/Rakefile +32 -8
  6. data/bats/bats.bats +33 -0
  7. data/bats/block-types.bats +56 -0
  8. data/bats/cli.bats +74 -0
  9. data/bats/fail.bats +11 -0
  10. data/bats/history.bats +34 -0
  11. data/bats/markup.bats +66 -0
  12. data/bats/mde.bats +29 -0
  13. data/bats/options.bats +92 -0
  14. data/bats/test_helper.bash +152 -0
  15. data/bin/tab_completion.sh +44 -20
  16. data/docs/dev/block-type-opts.md +10 -0
  17. data/docs/dev/block-type-port.md +24 -0
  18. data/docs/dev/block-type-vars.md +7 -0
  19. data/docs/dev/pass-through-arguments.md +8 -0
  20. data/docs/dev/specs-import.md +9 -0
  21. data/docs/dev/specs.md +83 -0
  22. data/docs/dev/text-decoration.md +7 -0
  23. data/examples/bash-blocks.md +4 -4
  24. data/examples/block-names.md +40 -5
  25. data/examples/import0.md +23 -0
  26. data/examples/import1.md +13 -0
  27. data/examples/link-blocks-vars.md +3 -3
  28. data/examples/opts-blocks-require.md +6 -6
  29. data/examples/table-markup.md +31 -0
  30. data/examples/text-markup.md +58 -0
  31. data/examples/vars-blocks.md +2 -2
  32. data/examples/wrap.md +87 -9
  33. data/lib/ansi_formatter.rb +12 -6
  34. data/lib/ansi_string.rb +153 -0
  35. data/lib/argument_processor.rb +160 -0
  36. data/lib/cached_nested_file_reader.rb +4 -2
  37. data/lib/ce_get_cost_and_usage.rb +4 -3
  38. data/lib/cli.rb +1 -1
  39. data/lib/colorize.rb +41 -0
  40. data/lib/constants.rb +17 -0
  41. data/lib/directory_searcher.rb +4 -2
  42. data/lib/doh.rb +190 -0
  43. data/lib/env.rb +1 -1
  44. data/lib/exceptions.rb +9 -6
  45. data/lib/fcb.rb +0 -199
  46. data/lib/filter.rb +18 -5
  47. data/lib/find_files.rb +8 -3
  48. data/lib/format_table.rb +406 -0
  49. data/lib/hash_delegator.rb +939 -611
  50. data/lib/hierarchy_string.rb +221 -0
  51. data/lib/input_sequencer.rb +19 -11
  52. data/lib/instance_method_wrapper.rb +2 -1
  53. data/lib/layered_hash.rb +143 -0
  54. data/lib/link_history.rb +22 -8
  55. data/lib/markdown_exec/version.rb +1 -1
  56. data/lib/markdown_exec.rb +420 -165
  57. data/lib/mdoc.rb +38 -38
  58. data/lib/menu.src.yml +832 -680
  59. data/lib/menu.yml +814 -689
  60. data/lib/namer.rb +6 -12
  61. data/lib/object_present.rb +1 -1
  62. data/lib/option_value.rb +7 -3
  63. data/lib/poly.rb +33 -14
  64. data/lib/resize_terminal.rb +60 -52
  65. data/lib/saved_assets.rb +45 -34
  66. data/lib/saved_files_matcher.rb +6 -3
  67. data/lib/streams_out.rb +7 -1
  68. data/lib/table_extractor.rb +166 -0
  69. data/lib/tap.rb +5 -6
  70. data/lib/text_analyzer.rb +236 -0
  71. metadata +28 -3
  72. data/lib/std_out_err_logger.rb +0 -119
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32532369e9eec3574b8bff6d6c79097f547e120c7b113c10a765364e20a311a4
4
- data.tar.gz: 3773bab7197401361c06bace1921663679bbf53d77f2cbe5daa1c2975c091e87
3
+ metadata.gz: c2578ee1f8b5967a2c9467ddf616133c3896f1928d0ca4b17d856ce78316e75c
4
+ data.tar.gz: 35fcea4c4a78f74269e96fdf06315a924ba00ff267a5fac2bf77a76909aeaeda
5
5
  SHA512:
6
- metadata.gz: e6ad41fdae333916ef13870498b6b1b9be7338af8ae39238b4a16a475b42430cb9282c59dbcecd124f422ab218848a70611ce6120e03074660a213a89e054df1
7
- data.tar.gz: f9ef27a86c8a7cb4e15b4eb59705d1fdad6a15b8c6af176978b09f1108599569e0f74423b89c1baaa2cfaed249a4ff37fb18c8e7c6c87220d0ecb48a5e4cdd45
6
+ metadata.gz: 19bef54c4148b8c3b2861e1193367b19d55d4e5e2132ff3d132cdc69c2ae5082ec391a0eeeec42d729e40d5bed27348d64a4dc72cc2f781e0dc3c46545cec582
7
+ data.tar.gz: 609d69e5a3c36e2c4864887d6d7677f48529f7f77509e4414245feec182c85aa7e8d35199efc9c479a5380cc420853849720ec1eb290d39cbb12db220673d7d0
data/.rubocop.yml CHANGED
@@ -13,15 +13,21 @@ Layout/LeadingCommentSpace:
13
13
  Layout/LineContinuationLeadingSpace:
14
14
  Enabled: false
15
15
 
16
- Layout/LineLength: # 2024-01-21 temp disable
16
+ Layout/LineLength:
17
17
  # Enabled: false
18
- # Max: 80
19
- Max: 96
18
+ Max: 80
19
+ # Max: 96
20
20
  # Max: 120
21
21
 
22
22
  Lint/Debugger:
23
23
  Enabled: false
24
24
 
25
+ Lint/LiteralAsCondition:
26
+ Enabled: false
27
+
28
+ Lint/RedundantSplatExpansion:
29
+ Enabled: false
30
+
25
31
  Lint/SafeNavigationChain:
26
32
  Enabled: false
27
33
 
@@ -73,7 +79,7 @@ Style/ClassVars:
73
79
  Style/CommentedKeyword:
74
80
  Enabled: false
75
81
 
76
- Style/Documentation: # 2024-01-21 temp disable
82
+ Style/Documentation:
77
83
  Enabled: false
78
84
 
79
85
  Style/DoubleNegation:
@@ -88,6 +94,9 @@ Style/FormatStringToken:
88
94
  Style/GlobalVars:
89
95
  Enabled: false
90
96
 
97
+ Style/IfUnlessModifier: # 2024-08 suggests lines that are too long
98
+ Enabled: false
99
+
91
100
  Style/Lambda:
92
101
  Enabled: false
93
102
 
@@ -97,6 +106,9 @@ Style/MixinUsage:
97
106
  Style/MultilineBlockChain:
98
107
  Enabled: false
99
108
 
109
+ Style/MultilineIfModifier:
110
+ Enabled: false
111
+
100
112
  Style/OpenStructUse:
101
113
  Enabled: false
102
114
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.4.0] - 2024-09-12
4
+
5
+ ### Added
6
+
7
+ - Commands to list, search, and view saved asset history.
8
+ - BATS tests for basic and common options.
9
+ - Options to format lists in report output.
10
+ - Options to format tables over multiple lines by role and order.
11
+ - Options for automatic menu entry to edit inherited code when none exists.
12
+ - Example documents for wrapped blocks, text and table formatting.
13
+
14
+ ### Changed
15
+
16
+ - Rework argument processing.
17
+ - Update default line decorations. Avoid patterns likely to exist in code.
18
+ - Refactor block selection to default to all.
19
+ - Use AnsiString over String to decorate output.
20
+ - Handle Ctrl-C at menu.
21
+
22
+ ## [2.3.0] - 2024-08-05
23
+
24
+ ### Added
25
+
26
+ - In-line decoration of text
27
+ - ANSI graphics modes for text decoration.
28
+ - Translation from text to ANSI graphics.
29
+ - Options for decorations in three stages, with default (Main) in the middle.
30
+
3
31
  ## [2.2.0] - 2024-07-27
4
32
 
5
33
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (2.2.0)
4
+ markdown_exec (2.4.0)
5
5
  clipboard (~> 1.3.6)
6
6
  open3 (~> 0.1.1)
7
7
  optparse (~> 0.1.1)
data/Rakefile CHANGED
@@ -74,16 +74,30 @@ task :clean do
74
74
  system 'rm *.gem'
75
75
  end
76
76
 
77
+ desc 'bats'
78
+ task :bats do
79
+ FileList['bats/**/*.bats'].each do |file|
80
+ next if %w[bats/bats.bats bats/fail.bats].include?(file)
81
+
82
+ system "bats #{file}"
83
+ end
84
+ end
85
+
77
86
  desc 'minitest'
78
87
  task :minitest do
79
88
  commands = [
89
+ './lib/argument_processor.rb',
80
90
  './lib/block_label.rb',
81
91
  './lib/cached_nested_file_reader.rb',
92
+ './lib/dev/process_template.rb --test',
82
93
  './lib/directory_searcher.rb',
83
94
  './lib/fcb.rb',
84
95
  './lib/filter.rb',
85
96
  './lib/find_files.rb',
97
+ './lib/format_table.rb',
86
98
  './lib/hash_delegator.rb',
99
+ './lib/hierarchy_string.rb',
100
+ './lib/link_history.rb',
87
101
  './lib/markdown_exec.rb',
88
102
  './lib/mdoc.rb',
89
103
  './lib/object_present.rb',
@@ -91,14 +105,19 @@ task :minitest do
91
105
  './lib/regexp.rb',
92
106
  './lib/resize_terminal.rb',
93
107
  './lib/saved_assets.rb',
94
- './lib/saved_files_matcher.rb'
108
+ './lib/saved_files_matcher.rb',
109
+ './lib/table_extractor.rb',
110
+ './lib/text_analyzer.rb'
95
111
  ]
96
112
 
97
113
  commands.each do |command|
98
- raise "Failed: #{command}" unless system("bundle exec ruby #{command}")
99
- rescue StandardError => err
100
- puts "Error: #{err.message}"
101
- exit 1
114
+ result = system("bundle exec ruby #{command}")
115
+ error_level = $?.exitstatus
116
+
117
+ if error_level != 0
118
+ puts "Error: Command '#{command}' failed with exit status #{error_level}."
119
+ exit error_level
120
+ end
102
121
  end
103
122
  end
104
123
 
@@ -109,8 +128,9 @@ end
109
128
 
110
129
  desc 'test'
111
130
  task :test do
112
- Rake::Task['minitest'].execute
113
131
  system 'bundle exec rspec'
132
+ Rake::Task['minitest'].invoke
133
+ Rake::Task['bats'].invoke
114
134
  end
115
135
 
116
136
  private
@@ -134,14 +154,17 @@ task :update_menu_yml do
134
154
  }
135
155
  )
136
156
 
157
+ ### sort keys
137
158
  File.write(MENU_YML, menu_options.to_yaml)
138
159
  puts `stat #{MENU_YML}`
139
160
  end
161
+ task :menu => 'update_menu_yml'
140
162
 
141
163
  # write tab_completion.sh with erb
142
164
  #
143
165
  def update_tab_completion(target)
144
- words = `#{File.join BF, MarkdownExec::BIN_NAME} --tab-completions`.split("\n")
166
+ words = `#{File.join BF,
167
+ MarkdownExec::BIN_NAME} --tab-completions`.split("\n")
145
168
  mde_tab_completions = "(#{words_list(words)})"
146
169
  mde_help = `#{File.join BF, MarkdownExec::BIN_NAME} --help`.split("\n")
147
170
 
@@ -164,7 +187,8 @@ end
164
187
 
165
188
  desc 'update installed tab_completion.sh'
166
189
  task :update_installed_tab_completion do
167
- update_tab_completion(fs = File.join(`mde --pwd`.chomp, BF, 'tab_completion.sh'))
190
+ update_tab_completion(fs = File.join(`mde --pwd`.chomp, BF,
191
+ 'tab_completion.sh'))
168
192
 
169
193
  puts `cat #{fs}` ###
170
194
  end
data/bats/bats.bats ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env bats
2
+
3
+ greet () {
4
+ echo "Hello, $1"'!'
5
+ sleep 9
6
+ }
7
+
8
+ @test 'Export function, variables to BATS; exit a running job' {
9
+ name='World'
10
+ export name
11
+ export -f greet
12
+ run bash -c "
13
+ greet \"$(echo '$name')\" &"'
14
+ pid="$!"
15
+
16
+ # Wait for 1 second, to show it is not stopping
17
+ sleep 1
18
+
19
+ if kill -0 $pid 2>/dev/null; then
20
+ kill $pid
21
+ wait $pid 2>/dev/null
22
+ exit_status=$?
23
+ else
24
+ wait $pid 2>/dev/null
25
+ exit_status=$?
26
+ fi
27
+ echo -n "$exit_status" > /tmp/exit_status
28
+ '
29
+ # app exits with an error code
30
+ [ "$(cat /tmp/exit_status)" = 143 ]
31
+ [ "$status" = 0 ]
32
+ [ "$output" = "Hello, World!" ]
33
+ }
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ # Type: Bash
6
+
7
+ # Type: Link
8
+
9
+ @test 'Link blocks - set variable in link block; call hidden block' {
10
+ run_mde_specs_md_args_expect_xansi '[VARIABLE1]' '__Exit' ' VARIABLE1: 1'
11
+ run_mde_specs_md_args_expect_xansi '[VARIABLE1]' '(echo-VARIABLE1)' ' VARIABLE1: 1 VARIABLE1: 1'
12
+ }
13
+
14
+ # Type: Opts
15
+
16
+ @test 'Opts block - before' {
17
+ BATS_OUTPUT_FILTER=A
18
+ spec_mde_args_expect docs/dev/block-type-opts.md --list-blocks-message dname --list-blocks-type 3 --list-blocks \
19
+ 'BEFORE Species menu_note_format: "AFTER %{line}" '
20
+ }
21
+
22
+ @test 'Opts block - after' {
23
+ skip 'Fails because command executes before the block is processed'
24
+ spec_mde_args_expect docs/dev/block-type-opts.md --list-blocks-message dname --list-blocks-type 3 '[decorate-note]' --list-blocks \
25
+ 'AFTER Species'
26
+ }
27
+
28
+ @test 'Opts block - show that menu has changed' {
29
+ skip 'Unable to show that menu has changed'
30
+ spec_mde_args_expect docs/dev/block-type-opts.md '[decorate-note]' \
31
+ 'AFTER Species'
32
+ }
33
+
34
+ # Type: Port
35
+
36
+ # includes output from assignment and from shell block
37
+ @test 'Port block - export variable' {
38
+ BATS_OUTPUT_FILTER=A
39
+ spec_mde_args_expect docs/dev/block-type-port.md '[set_vault_1]' show \
40
+ 'VAULT = 1 VAULT: 1'
41
+ }
42
+
43
+ @test 'Port block - export variable - not set' {
44
+ BATS_OUTPUT_FILTER=A
45
+ spec_mde_args_expect docs/dev/block-type-port.md VAULT-is-export show \
46
+ ' VAULT: This variable has not been set.'
47
+ }
48
+
49
+ # Type: Vars
50
+
51
+ # includes output from assignment and from shell block
52
+ @test 'Vars block - set variable' {
53
+ BATS_OUTPUT_FILTER=A
54
+ spec_mde_args_expect docs/dev/block-type-vars.md '[set_vault_1]' show \
55
+ 'VAULT = 1 VAULT: 1'
56
+ }
data/bats/cli.bats ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test 'pass-through arguments to scripts' {
6
+ BATS_OUTPUT_FILTER=A
7
+ spec_mde_args_expect docs/dev/pass-through-arguments.md output_arguments -- 1 23 \
8
+ ' ARGS: 1 23'
9
+ }
10
+
11
+ @test 'Position 0 File Name - file does not exist; string not found; select a file from the current directory' {
12
+ skip 'algorithm to exit waiting MDE is not ready'
13
+ BATS_SLEEP=3
14
+ spec_mde_args_expect NotFoundAnywhere \
15
+ 'Searching in: . Choose a file: (Press ↑/↓ arrow to move, Enter to select and letters to filter) ‣ ./CHANGELOG.md ./CODE_OF_CONDUCT.md ./README.md ./TODO.md'
16
+ }
17
+
18
+ @test 'Position 1 Block Name - block does not exist' {
19
+ BATS_OUTPUT_FILTER=A
20
+ BATS_STATUS=1
21
+ spec_mde_args_expect docs/dev/pass-through-arguments.md NonExistentBlock \
22
+ ' Error: Block not found -- name: NonExistentBlock'
23
+ }
24
+
25
+ @test 'block named in link does not exist' {
26
+ BATS_STATUS=1
27
+ spec_mde_args_expect docs/dev/requiring-blocks.md '[link-missing-local-block]' \
28
+ 'Block missing'
29
+ }
30
+
31
+ # Requiring blocks
32
+
33
+ @test 'bash block setting an environment variable requires a bash block' {
34
+ BATS_OUTPUT_FILTER=A
35
+ spec_mde_args_expect docs/dev/requiring-blocks.md '[set-env]' \
36
+ ' ARG1: 37'
37
+ }
38
+
39
+ # the last block is a link block, so menu is displayed
40
+ @test 'link block setting an environment variable requires a bash block' {
41
+ BATS_OUTPUT_FILTER=A
42
+ spec_mde_args_expect docs/dev/requiring-blocks.md '[link-local-block-with-vars]' __Exit \
43
+ ' ARG1: 37'
44
+ }
45
+
46
+ # the last block is a link block, so menu is displayed
47
+ @test 'link block setting an environment variable calls a bash block in a file' {
48
+ BATS_OUTPUT_FILTER=A
49
+ spec_mde_args_expect docs/dev/requiring-blocks.md '[link-file-block-with-vars]' __Exit \
50
+ ' ARG1: arg1-from-link-file'
51
+ }
52
+
53
+ @test 'history' {
54
+ file_name="$(most_recent_history_file_name)"
55
+ BATS_OUTPUT_GREP="$file_name"
56
+ spec_mde_args_expect examples/save.md --history \
57
+ "$file_name"
58
+ }
59
+
60
+ @test 'sift - format text' {
61
+ file_name="$(most_recent_history_file_name)"
62
+ date="$(date_from_history_file_name "$file_name")"
63
+ BATS_OUTPUT_GREP="$file_name"
64
+ spec_mde_args_expect examples/save.md --sift "$date" --history \
65
+ "$file_name"
66
+ }
67
+
68
+ @test 'sift - format yaml' {
69
+ file_name="$(most_recent_history_file_name)"
70
+ date="$(date_from_history_file_name "$file_name")"
71
+ BATS_OUTPUT_GREP="$file_name"
72
+ spec_mde_args_expect examples/save.md --format yaml --sift "$date" --history \
73
+ "- $file_name"
74
+ }
data/bats/fail.bats ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test 'FAIL' {
6
+ run_mde_specs_md_args_expect_xansi '[VARIABLE1]' '__Exit' ' VARIABLE1: FAIL'
7
+ }
8
+
9
+ @test 'OK' {
10
+ run_mde_specs_md_args_expect_xansi '[VARIABLE1]' '__Exit' ' VARIABLE1: 1'
11
+ }
data/bats/history.bats ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ @test 'Options - history' {
6
+ local log_files="$(ls -1 logs/*examples_save_md*)"
7
+ spec_mde_args_expect examples/save.md --history \
8
+ "$log_files"
9
+ }
10
+
11
+ @test 'Options - history, dig' {
12
+ skip 'test hangs on menu'
13
+ local log_files="$(ls -1 logs/*)"
14
+ spec_mde_args_expect --history --dig \
15
+ "$log_files"
16
+ }
17
+
18
+ @test 'Options - history, probe' {
19
+ local log_files="$(grep --files-with-matches '04:31' logs/* 2>/dev/null)"
20
+ spec_mde_args_expect examples/save.md --probe '04:31' --history \
21
+ "$log_files"
22
+ }
23
+
24
+ @test 'Options - history, sift' {
25
+ local log_files="$(ls -1 logs/*-31-*examples_save_md*)"
26
+ spec_mde_args_expect examples/save.md --sift -31- --history \
27
+ "$log_files"
28
+ }
29
+
30
+ @test 'Options - history, sift and probe' {
31
+ local log_files="$(grep --files-with-matches 'e' logs/*-31-*examples_save_md* 2>/dev/null)"
32
+ spec_mde_args_expect examples/save.md --sift -31- --probe e --history \
33
+ "$log_files"
34
+ }
data/bats/markup.bats ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ # Text Decoration
6
+
7
+ @test 'Options - list blocks - 1 plain' {
8
+ BATS_OUTPUT_FILTER=A \
9
+ spec_mde_args_expect \
10
+ docs/dev/text-decoration.md \
11
+ --list-blocks-message oname \
12
+ --list-blocks-type 3 \
13
+ --list-blocks \
14
+ '-:= =:- * Exit - **_Bold-Underline_** - **Bold** - **~Bold-Italic~** - __Underline__ - _~Underline-Italic~_ - `Italic` - ~~Strikethrough~~ -:= ~~~ =:-'
15
+ }
16
+
17
+ @test 'Options - list blocks - 2 extracts markup' {
18
+ BATS_OUTPUT_FILTER=A \
19
+ spec_mde_args_expect \
20
+ docs/dev/text-decoration.md \
21
+ --list-blocks-message dname \
22
+ --list-blocks-type 3 \
23
+ --list-blocks \
24
+ '-:= =:- * Exit - Bold-Underline - Bold - Bold-Italic - Underline - Underline-Italic - Italic - Strikethrough -:= ~~~ =:-'
25
+ }
26
+
27
+ @test 'Options - list blocks - 3 decorates' {
28
+ spec_mde_args_expect docs/dev/text-decoration.md --list-blocks-message dname --list-blocks-type 3 --list-blocks \
29
+ $'\x1b\x5b\x33\x38\x3b\x32\x3b\x31\x32\x38\x3b\x32\x30\x38\x3b\x31\x39\x32\x6d\x2d\x3a\x3d\x20\x20\x20\x20\x20\x20\x3d\x3a\x2d\x1b\x5b\x30\x6d\x0a\x1b\x5b\x33\x38\x3b\x32\x3b\x36\x34\x3b\x31\x39\x32\x3b\x31\x39\x32\x6d\x2a\x20\x45\x78\x69\x74\x1b\x5b\x30\x6d\x0a\x1b\x5b\x33\x38\x3b\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x6d\x2d\x20\x1b\x5b\x30\x6d\x1b\x5b\x31\x6d\x1b\x5b\x34\x6d\x42\x6f\x6c\x64\x2d\x55\x6e\x64\x65\x72\x6c\x69\x6e\x65\x1b\x5b\x32\x32\x6d\x1b\x5b\x32\x34\x6d\x0a\x1b\x5b\x33\x38\x3b\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x6d\x2d\x20\x1b\x5b\x30\x6d\x1b\x5b\x31\x6d\x42\x6f\x6c\x64\x1b\x5b\x32\x32\x6d\x0a\x1b\x5b\x33\x38\x3b\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x6d\x2d\x20\x1b\x5b\x30\x6d\x1b\x5b\x31\x6d\x1b\x5b\x33\x6d\x42\x6f\x6c\x64\x2d\x49\x74\x61\x6c\x69\x63\x1b\x5b\x32\x32\x6d\x1b\x5b\x32\x33\x6d\x0a\x1b\x5b\x33\x38\x3b\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x6d\x2d\x20\x1b\x5b\x30\x6d\x1b\x5b\x34\x6d\x55\x6e\x64\x65\x72\x6c\x69\x6e\x65\x1b\x5b\x32\x34\x6d\x0a\x1b\x5b\x33\x38\x3b\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x6d\x2d\x20\x1b\x5b\x30\x6d\x1b\x5b\x34\x6d\x1b\x5b\x33\x6d\x55\x6e\x64\x65\x72\x6c\x69\x6e\x65\x2d\x49\x74\x61\x6c\x69\x63\x1b\x5b\x32\x33\x6d\x1b\x5b\x32\x34\x6d\x0a\x1b\x5b\x33\x38\x3b\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x6d\x2d\x20\x1b\x5b\x30\x6d\x1b\x5b\x33\x6d\x49\x74\x61\x6c\x69\x63\x1b\x5b\x32\x33\x6d\x0a\x1b\x5b\x33\x38\x3b\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x3b\x31\x39\x32\x6d\x2d\x20\x1b\x5b\x30\x6d\x1b\x5b\x39\x6d\x53\x74\x72\x69\x6b\x65\x74\x68\x72\x6f\x75\x67\x68\x1b\x5b\x32\x39\x6d\x0a\x1b\x5b\x33\x38\x3b\x32\x3b\x31\x32\x38\x3b\x32\x30\x38\x3b\x31\x39\x32\x6d\x2d\x3a\x3d\x20\x20\x20\x7e\x7e\x7e\x20\x20\x20\x3d\x3a\x2d\x1b\x5b\x30\x6d'
30
+ }
31
+
32
+ # Raw comparison test
33
+ #@test "raw comparison" {
34
+ # expect_equal_raw "Hello, World!" "Hello, World!"
35
+ #}
36
+ # remove_ansi_escape_sequences2() {
37
+ # # printf '%s' "$1" | sed -E 's/\x1b\[[0-9;]*[a-zA-Z]//g' | tr '\n\t\r\v\f' ' '
38
+ # # printf '%s' "$1" | sed -E 's/\x1b\[[0-9;]*[a-zA-Z]//g'
39
+ # # printf '%s' "$1" | sed -E 's/e/E/g' | tr '\n\t\r\v\f' ' '
40
+ # printf '%s' "$1" | perl -pe 's/\e\[[0-9;]*[a-zA-Z]//g'
41
+ # }
42
+
43
+ # test ANSI escape sequence removal within BATS
44
+ @test "comparison with ANSI removal" {
45
+ actual="Hello, \e[31mWorld\e[0m!"
46
+ echo 'actual'
47
+ echo -en "$actual" | hexdump -C
48
+
49
+ echo 'converted'
50
+ converted="$(remove_ansi_escape_sequences "$actual")"
51
+ echo -en "$converted" | hexdump -C
52
+
53
+ [[ "Hello, World!" == "$converted" ]]
54
+ echo "converision passed"
55
+ # (( 0 == 1 )) # force output
56
+ }
57
+
58
+ #@test 'Defaults' {
59
+ # run_mde_args_expect_raw \
60
+ # docs/dev/specs.md bash1 \
61
+ # '\nbash1!'
62
+ #}
63
+
64
+ # @test 'OK' {
65
+ # run_mde_specs_md_args_expect_xansi '[VARIABLE1]' '__Exit' ' VARIABLE1: 1'
66
+ # }
data/bats/mde.bats ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ # Directives
6
+
7
+ @test 'Directives - Import' {
8
+ # this shell block is in the import, not the primary document
9
+ run_mde_specs_md_args_expect_xansi 'shell-block-in-import' ' shell-block-in-import'
10
+ }
11
+
12
+ # Blocks, Wrapped
13
+
14
+ @test 'Shell blocks - wrapped block; nested; inverted' {
15
+ run_mde_specs_md_args_expect_xansi '[single]' ' outer-before single-body outer-after'
16
+ run_mde_specs_md_args_expect_xansi '[nested]' ' outer-before inner-before nested-body inner-after outer-after'
17
+ run_mde_specs_md_args_expect_xansi '[inverted-nesting]' ' inner-before outer-before inverted-nesting outer-after inner-after'
18
+ }
19
+
20
+ # Blocks, Wrapped, Imported
21
+
22
+ @test 'Shell blocks - wrapped block; imported' {
23
+ # the wrap blocks are in the import, not the primary document
24
+ run_mde_specs_md_args_expect_xansi '[test-wrap-from-import]' ' wrap-from-import-before test-wrap-from-import wrap-from-import-after'
25
+ }
26
+
27
+ @test 'Shell blocks - required; wrapped block' {
28
+ run_mde_specs_md_args_expect_xansi '[test-require-wrapped-block]' ' outer-before single-body outer-after test-require-wrapped-block'
29
+ }
data/bats/options.bats ADDED
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env bats
2
+
3
+ load 'test_helper'
4
+
5
+ # Defaults
6
+
7
+ @test 'Options - document and block name' {
8
+ run_mde_specs_md_args_expect_xansi bash1 \
9
+ ' bash1!'
10
+ }
11
+
12
+ # Options
13
+
14
+ @test 'Options - block-name' {
15
+ BATS_OUTPUT_FILTER=A
16
+ spec_mde_args_expect --block-name bash1 docs/dev/specs.md \
17
+ ' bash1!'
18
+ }
19
+
20
+ @test 'Options - find' {
21
+ run_mde_specs_md_args_expect_xansi --find search \
22
+ 'Searching in: . In directory names ./docs/research In file names ./examples/search.md'
23
+ }
24
+
25
+ @test 'Options - list blocks' {
26
+ BATS_OUTPUT_FILTER=A
27
+ spec_mde_args_expect --list-blocks-message oname --list-blocks-type 0 examples/colors.md --list-blocks \
28
+ '(document_options) load_colors load_colors2 Bash1 Link1 Opts1 Port1 Vars1'
29
+ }
30
+
31
+ @test 'Options - list blocks, eval' {
32
+ BATS_OUTPUT_FILTER=A
33
+ spec_mde_args_expect --list-blocks-eval block.oname examples/colors.md --list-blocks \
34
+ '(document_options) load_colors load_colors2 Bash1 Link1 Opts1 Port1 Vars1'
35
+ }
36
+
37
+ @test 'Options - how' {
38
+ spec_mde_args_expect --how how \
39
+ "prompt_show_expr_format: 'Expr: %{expr}' # prompt_show_expr_format"
40
+ }
41
+
42
+ @test 'Options - list-default-env' {
43
+ BATS_OUTPUT_GREP=SHEBANG
44
+ spec_mde_args_expect --list-default-env \
45
+ "MDE_SHEBANG=\#\!/usr/bin/env # Shebang for saved scripts"
46
+ }
47
+
48
+ @test 'Options - list-default-yaml' {
49
+ BATS_OUTPUT_GREP=shebang
50
+ spec_mde_args_expect --list-default-yaml \
51
+ "shebang: '#!/usr/bin/env' # Shebang for saved scripts"
52
+ }
53
+
54
+ @test 'Options - list-docs, path' {
55
+ BATS_OUTPUT_FILTER=A
56
+ BATS_OUTPUT_GREP=specs
57
+ spec_mde_args_expect --path docs/dev --list-docs \
58
+ 'docs/dev/specs-import.md docs/dev/specs.md'
59
+ }
60
+
61
+ # @test 'Options - list-recent-output' {
62
+ # BATS_OUTPUT_FILTER=A \
63
+ # spec_mde_args_expect \
64
+ # --path docs/dev \
65
+ # --list-recent-output \
66
+ # "?"
67
+ # }
68
+
69
+ @test 'Options - load-code' {
70
+ BATS_OUTPUT_FILTER=A
71
+ BATS_OUTPUT_GREP=var1
72
+ spec_mde_args_expect examples/load_code.md --load-code examples/load1.sh display_variables \
73
+ 'var1: line2'
74
+ }
75
+
76
+ @test 'Options - pwd' {
77
+ spec_mde_args_expect --pwd \
78
+ $(pwd)
79
+ }
80
+
81
+ @test 'Options - tab-completions' {
82
+ BATS_OUTPUT_FILTER=A
83
+ BATS_OUTPUT_GREP=find
84
+ spec_mde_args_expect --tab-completions \
85
+ '--find --find-path'
86
+ }
87
+
88
+ @test 'Options - version' {
89
+ version=$(grep VERSION "$PROJECT_ROOT/lib/markdown_exec/version.rb" | cut -d "'" -f 2)
90
+ spec_mde_args_expect --version \
91
+ "$version"
92
+ }