rundoc 0.0.2 → 1.0.0
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 +5 -5
- data/.travis.yml +8 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -0
- data/README.md +63 -15
- data/bin/rundoc +8 -0
- data/lib/rundoc.rb +14 -1
- data/lib/rundoc/code_command.rb +18 -4
- data/lib/rundoc/code_command/background.rb +9 -0
- data/lib/rundoc/code_command/background/log/clear.rb +17 -0
- data/lib/rundoc/code_command/background/log/read.rb +16 -0
- data/lib/rundoc/code_command/background/process_spawn.rb +70 -0
- data/lib/rundoc/code_command/background/start.rb +36 -0
- data/lib/rundoc/code_command/background/stop.rb +17 -0
- data/lib/rundoc/code_command/background/wait.rb +19 -0
- data/lib/rundoc/code_command/bash.rb +1 -1
- data/lib/rundoc/code_command/bash/cd.rb +1 -1
- data/lib/rundoc/code_command/file_command/append.rb +2 -0
- data/lib/rundoc/code_command/raw.rb +18 -0
- data/lib/rundoc/code_command/rundoc_command.rb +2 -1
- data/lib/rundoc/code_section.rb +21 -74
- data/lib/rundoc/peg_parser.rb +282 -0
- data/lib/rundoc/version.rb +1 -1
- data/rundoc.gemspec +2 -1
- data/test/fixtures/rails_5/rundoc.md +70 -74
- data/test/rundoc/code_commands/append_file_test.rb +2 -2
- data/test/rundoc/code_commands/background_test.rb +43 -0
- data/test/rundoc/code_commands/bash_test.rb +1 -1
- data/test/rundoc/code_commands/pipe_test.rb +1 -1
- data/test/rundoc/code_commands/remove_contents_test.rb +1 -1
- data/test/rundoc/code_section_test.rb +6 -5
- data/test/rundoc/parser_test.rb +2 -7
- data/test/rundoc/peg_parser_test.rb +348 -0
- data/test/rundoc/regex_test.rb +1 -1
- data/test/rundoc/test_parse_java.rb +1 -1
- data/test/test_helper.rb +1 -1
- metadata +33 -4
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class CodeSectionTest < Test
|
3
|
+
class CodeSectionTest < Minitest::Test
|
4
4
|
|
5
5
|
def setup
|
6
6
|
end
|
@@ -10,7 +10,7 @@ class CodeSectionTest < Test::Unit::TestCase
|
|
10
10
|
sup
|
11
11
|
|
12
12
|
```
|
13
|
-
|
13
|
+
:::-- $ mkdir foo
|
14
14
|
```
|
15
15
|
|
16
16
|
yo
|
@@ -42,7 +42,7 @@ RUBY
|
|
42
42
|
def test_show_command_hide_render
|
43
43
|
contents = <<-RUBY
|
44
44
|
```
|
45
|
-
|
45
|
+
:::>- $ echo "foo"
|
46
46
|
```
|
47
47
|
RUBY
|
48
48
|
|
@@ -80,15 +80,16 @@ RUBY
|
|
80
80
|
code_section = Rundoc::CodeSection.new(match, keyword: ":::")
|
81
81
|
code_section.render
|
82
82
|
|
83
|
+
puts code_section.commands.inspect
|
83
84
|
code_command = code_section.commands.first
|
84
|
-
assert_equal true,
|
85
|
+
assert_equal true, code_command.render_command
|
85
86
|
assert_equal true, code_command.render_result
|
86
87
|
end
|
87
88
|
|
88
89
|
def test_hide_command_hide_render
|
89
90
|
contents = <<-RUBY
|
90
91
|
```
|
91
|
-
|
92
|
+
:::-- $ echo "foo"
|
92
93
|
```
|
93
94
|
RUBY
|
94
95
|
|
data/test/rundoc/parser_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class ParserTest < Test
|
3
|
+
class ParserTest < Minitest::Test
|
4
4
|
|
5
5
|
def setup
|
6
6
|
end
|
@@ -10,7 +10,7 @@ class ParserTest < Test::Unit::TestCase
|
|
10
10
|
sup
|
11
11
|
|
12
12
|
```
|
13
|
-
|
13
|
+
:::>- $ mkdir foo
|
14
14
|
:::>> $ ls
|
15
15
|
```
|
16
16
|
|
@@ -24,11 +24,6 @@ RUBY
|
|
24
24
|
parsed = Rundoc::Parser.new(contents)
|
25
25
|
actual = parsed.to_md
|
26
26
|
assert_equal expected, actual
|
27
|
-
|
28
|
-
parsed = Rundoc::Parser.new("\n```\n:::= $ ls\n```\n")
|
29
|
-
actual = parsed.to_md
|
30
|
-
expected = "\n```\n$ ls\nfoo\n```\n"
|
31
|
-
assert_equal expected, actual
|
32
27
|
end
|
33
28
|
end
|
34
29
|
end
|
@@ -0,0 +1,348 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'parslet/convenience'
|
3
|
+
|
4
|
+
class PegParserTest < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@transformer = Rundoc::PegTransformer.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_string
|
10
|
+
input = %Q{"hello world"}
|
11
|
+
parser = Rundoc::PegParser.new.string
|
12
|
+
tree = parser.parse_with_debug(input)
|
13
|
+
expected = {:string => "hello world"}
|
14
|
+
assert_equal expected, tree
|
15
|
+
|
16
|
+
actual = @transformer.apply(tree)
|
17
|
+
assert_equal "hello world", actual
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_keyword_args
|
21
|
+
input = %Q{foo: 'bar', baz: "boo"}
|
22
|
+
parser = Rundoc::PegParser.new.named_args
|
23
|
+
tree = parser.parse_with_debug(input)
|
24
|
+
actual = @transformer.apply(tree)
|
25
|
+
expected = {foo: 'bar', baz: "boo"}
|
26
|
+
assert_equal expected, actual
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_method_call
|
30
|
+
input = %Q{sup(foo: 'bar')}
|
31
|
+
parser = Rundoc::PegParser.new.method_call
|
32
|
+
tree = parser.parse_with_debug(input)
|
33
|
+
|
34
|
+
actual = @transformer.apply(tree)
|
35
|
+
assert_equal :sup, actual.keyword
|
36
|
+
assert_equal({foo: 'bar'}, actual.original_args)
|
37
|
+
|
38
|
+
# seattle style
|
39
|
+
input = %Q{sup foo: 'bar' }
|
40
|
+
parser = Rundoc::PegParser.new.method_call
|
41
|
+
tree = parser.parse_with_debug(input)
|
42
|
+
actual = @transformer.apply(tree)
|
43
|
+
assert_equal :sup, actual.keyword
|
44
|
+
assert_equal({foo: 'bar'}, actual.original_args)
|
45
|
+
|
46
|
+
# with a dot
|
47
|
+
input = %Q{sup.you foo: 'bar' }
|
48
|
+
parser = Rundoc::PegParser.new.method_call
|
49
|
+
tree = parser.parse_with_debug(input)
|
50
|
+
actual = @transformer.apply(tree)
|
51
|
+
assert_equal :"sup.you", actual.keyword
|
52
|
+
assert_equal({foo: 'bar'}, actual.original_args)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_with_string_arg
|
56
|
+
input = %Q{sup("hey")}
|
57
|
+
parser = Rundoc::PegParser.new.method_call
|
58
|
+
tree = parser.parse_with_debug(input)
|
59
|
+
|
60
|
+
actual = @transformer.apply(tree)
|
61
|
+
assert_equal :sup, actual.keyword
|
62
|
+
assert_equal("hey", actual.original_args)
|
63
|
+
|
64
|
+
input = %Q{sup "hey"}
|
65
|
+
parser = Rundoc::PegParser.new.method_call
|
66
|
+
tree = parser.parse_with_debug(input)
|
67
|
+
|
68
|
+
actual = @transformer.apply(tree)
|
69
|
+
assert_equal :sup, actual.keyword
|
70
|
+
assert_equal("hey", actual.original_args)
|
71
|
+
|
72
|
+
input = %Q{sup hey}
|
73
|
+
parser = Rundoc::PegParser.new.method_call
|
74
|
+
tree = parser.parse_with_debug(input)
|
75
|
+
|
76
|
+
actual = @transformer.apply(tree)
|
77
|
+
assert_equal :sup, actual.keyword
|
78
|
+
assert_equal("hey", actual.original_args)
|
79
|
+
|
80
|
+
input = %Q{ $ cat foo.rb}
|
81
|
+
parser = Rundoc::PegParser.new.method_call
|
82
|
+
tree = parser.parse_with_debug(input)
|
83
|
+
|
84
|
+
actual = @transformer.apply(tree)
|
85
|
+
assert_equal :"$", actual.keyword
|
86
|
+
assert_equal("cat foo.rb", actual.original_args)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_visability
|
90
|
+
input = %Q{>>}
|
91
|
+
parser = Rundoc::PegParser.new.visability
|
92
|
+
tree = parser.parse_with_debug(input)
|
93
|
+
actual = @transformer.apply(tree)
|
94
|
+
assert_equal true, actual.command?
|
95
|
+
assert_equal true, actual.result?
|
96
|
+
|
97
|
+
input = %Q{->}
|
98
|
+
parser = Rundoc::PegParser.new.visability
|
99
|
+
tree = parser.parse_with_debug(input)
|
100
|
+
actual = @transformer.apply(tree)
|
101
|
+
assert_equal false, actual.command?
|
102
|
+
assert_equal true, actual.result?
|
103
|
+
|
104
|
+
input = %Q{--}
|
105
|
+
parser = Rundoc::PegParser.new.visability
|
106
|
+
tree = parser.parse_with_debug(input)
|
107
|
+
actual = @transformer.apply(tree)
|
108
|
+
assert_equal false, actual.command?
|
109
|
+
assert_equal false, actual.result?
|
110
|
+
|
111
|
+
input = %Q{>-}
|
112
|
+
parser = Rundoc::PegParser.new.visability
|
113
|
+
tree = parser.parse_with_debug(input)
|
114
|
+
actual = @transformer.apply(tree)
|
115
|
+
assert_equal true, actual.command?
|
116
|
+
assert_equal false, actual.result?
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_command
|
120
|
+
input = %Q{:::>> $ cat foo.rb\n}
|
121
|
+
parser = Rundoc::PegParser.new.command
|
122
|
+
tree = parser.parse_with_debug(input)
|
123
|
+
|
124
|
+
actual = @transformer.apply(tree)
|
125
|
+
assert_equal :"$", actual.keyword
|
126
|
+
assert_equal("cat foo.rb", actual.original_args)
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_command_with_stdin
|
130
|
+
input = String.new
|
131
|
+
input << ":::>> file.write hello.txt\n"
|
132
|
+
input << "world\n"
|
133
|
+
|
134
|
+
parser = Rundoc::PegParser.new.command_with_stdin
|
135
|
+
tree = parser.parse_with_debug(input)
|
136
|
+
|
137
|
+
actual = @transformer.apply(tree)
|
138
|
+
assert_equal :"file.write", actual.keyword
|
139
|
+
assert_equal("hello.txt", actual.original_args)
|
140
|
+
assert_equal("world\n", actual.contents)
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_command_with_stdin_no_string
|
144
|
+
input = String.new
|
145
|
+
input << ":::>> file.write hello.txt\n"
|
146
|
+
|
147
|
+
parser = Rundoc::PegParser.new.command_with_stdin
|
148
|
+
tree = parser.parse_with_debug(input)
|
149
|
+
|
150
|
+
actual = @transformer.apply(tree)
|
151
|
+
|
152
|
+
assert_equal :"file.write", actual.keyword
|
153
|
+
assert_equal("hello.txt", actual.original_args)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_multiple_commands_stdin
|
157
|
+
input = String.new
|
158
|
+
input << ":::>> file.write hello.txt\n"
|
159
|
+
input << "world\n"
|
160
|
+
input << ":::>> file.write cinco.txt\n"
|
161
|
+
input << "\n\n\n"
|
162
|
+
input << " river\n"
|
163
|
+
|
164
|
+
parser = Rundoc::PegParser.new.multiple_commands
|
165
|
+
tree = parser.parse_with_debug(input)
|
166
|
+
|
167
|
+
actual = @transformer.apply(tree)
|
168
|
+
|
169
|
+
assert_equal :"file.write", actual.first.keyword
|
170
|
+
assert_equal("hello.txt", actual.first.original_args)
|
171
|
+
assert_equal("world\n", actual.first.contents)
|
172
|
+
|
173
|
+
assert_equal :"file.write", actual.last.keyword
|
174
|
+
assert_equal("cinco.txt", actual.last.original_args)
|
175
|
+
assert_equal("\n\n\n river\n", actual.last.contents)
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_multiple_commands_with_fence
|
179
|
+
input = String.new
|
180
|
+
input << "```\n"
|
181
|
+
input << ":::>> file.write hello.txt\n"
|
182
|
+
input << "world\n"
|
183
|
+
input << "```\n"
|
184
|
+
|
185
|
+
parser = Rundoc::PegParser.new.fenced_commands
|
186
|
+
tree = parser.parse_with_debug(input)
|
187
|
+
|
188
|
+
actual = @transformer.apply(tree)
|
189
|
+
|
190
|
+
assert_equal :"file.write", actual.first.keyword
|
191
|
+
assert_equal("hello.txt", actual.first.original_args)
|
192
|
+
assert_equal("world\n", actual.first.contents)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_raw
|
196
|
+
input = String.new
|
197
|
+
input << "hello.txt\n"
|
198
|
+
input << "world\n"
|
199
|
+
input << ":::>> $ cd foo\n"
|
200
|
+
|
201
|
+
parser = Rundoc::PegParser.new.raw_code
|
202
|
+
tree = parser.parse_with_debug(input)
|
203
|
+
|
204
|
+
actual = @transformer.apply(tree)
|
205
|
+
|
206
|
+
assert_equal "hello.txt\nworld\n", actual.first.contents
|
207
|
+
assert_equal :"$", actual.last.keyword
|
208
|
+
assert_equal("cd foo", actual.last.original_args)
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
def test_quotes_in_shell_commands
|
213
|
+
input = %Q{:::>- $ git commit -m "init"\n}
|
214
|
+
parser = Rundoc::PegParser.new.code_block
|
215
|
+
tree = parser.parse_with_debug(input)
|
216
|
+
|
217
|
+
actual = @transformer.apply(tree)
|
218
|
+
|
219
|
+
assert_equal :"$", actual.last.keyword
|
220
|
+
assert_equal('git commit -m "init"', actual.last.original_args)
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_raises_on_syntax
|
224
|
+
input = %Q{:::> $ git commit -m "init"\n}
|
225
|
+
assert_raises(Rundoc::PegTransformer::TransformError) do
|
226
|
+
parser = Rundoc::PegParser.new.code_block
|
227
|
+
tree = parser.parse_with_debug(input)
|
228
|
+
|
229
|
+
actual = @transformer.apply(tree)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
def test_no_args
|
235
|
+
# input = String.new
|
236
|
+
# input << %Q{rundoc}
|
237
|
+
# parser = Rundoc::PegParser.new.no_args_method
|
238
|
+
# tree = parser.parse_with_debug(input)
|
239
|
+
# actual = @transformer.apply(tree)
|
240
|
+
# assert_equal("rundoc", actual.to_s)
|
241
|
+
|
242
|
+
# input = String.new
|
243
|
+
# input << %Q{:::-- rundoc\n}
|
244
|
+
# parser = Rundoc::PegParser.new.command
|
245
|
+
# tree = parser.parse_with_debug(input)
|
246
|
+
|
247
|
+
# actual = @transformer.apply(tree)
|
248
|
+
# assert_equal :rundoc, actual.keyword
|
249
|
+
# assert_nil(actual.original_args)
|
250
|
+
|
251
|
+
|
252
|
+
input = String.new
|
253
|
+
input << %Q{:::-- rundoc\n}
|
254
|
+
input << %Q{email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`\n}
|
255
|
+
|
256
|
+
parser = Rundoc::PegParser.new.command_with_stdin
|
257
|
+
tree = parser.parse_with_debug(input)
|
258
|
+
|
259
|
+
actual = @transformer.apply(tree)
|
260
|
+
assert_equal :rundoc, actual.keyword
|
261
|
+
assert_equal("email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`", actual.original_args)
|
262
|
+
end
|
263
|
+
|
264
|
+
|
265
|
+
def test_positional_args
|
266
|
+
input = +""
|
267
|
+
input << %Q{call("foo", "bar", biz: "baz")}
|
268
|
+
|
269
|
+
parser = Rundoc::PegParser.new.method_call
|
270
|
+
tree = parser.parse_with_debug(input)
|
271
|
+
|
272
|
+
# =====================================
|
273
|
+
#
|
274
|
+
# Handles more than one value, but not only one value
|
275
|
+
actual = @transformer.apply(tree)
|
276
|
+
assert_equal ["foo", "bar", { biz: "baz"}], actual.original_args
|
277
|
+
|
278
|
+
input = +""
|
279
|
+
input << %Q{call("foo", biz: "baz")}
|
280
|
+
|
281
|
+
parser = Rundoc::PegParser.new.method_call
|
282
|
+
tree = parser.parse_with_debug(input)
|
283
|
+
|
284
|
+
actual = @transformer.apply(tree)
|
285
|
+
assert_equal ["foo", { biz: "baz"}], actual.original_args
|
286
|
+
|
287
|
+
input = +""
|
288
|
+
input << %Q{call("rails server", name: "server")}
|
289
|
+
|
290
|
+
parser = Rundoc::PegParser.new.method_call
|
291
|
+
tree = parser.parse_with_debug(input)
|
292
|
+
|
293
|
+
actual = @transformer.apply(tree)
|
294
|
+
assert_equal ["rails server", {name: "server"}], actual.original_args
|
295
|
+
|
296
|
+
# input = +""
|
297
|
+
# input << %Q{background.start("rails server", name: "server")}
|
298
|
+
# parser = Rundoc::PegParser.new.method_call
|
299
|
+
|
300
|
+
# tree = parser.parse_with_debug(input)
|
301
|
+
|
302
|
+
# puts tree.inspect
|
303
|
+
|
304
|
+
# actual = @transformer.apply(tree)
|
305
|
+
# assert_equal :"background.start", actual.keyword
|
306
|
+
|
307
|
+
# ================
|
308
|
+
|
309
|
+
input = +""
|
310
|
+
input << %Q{call("foo", "bar")}
|
311
|
+
|
312
|
+
parser = Rundoc::PegParser.new.method_call
|
313
|
+
tree = parser.parse_with_debug(input)
|
314
|
+
|
315
|
+
# puts tree.inspect
|
316
|
+
|
317
|
+
actual = @transformer.apply(tree)
|
318
|
+
assert_equal ["foo", "bar"], actual.original_args
|
319
|
+
|
320
|
+
# ======================
|
321
|
+
|
322
|
+
input = +""
|
323
|
+
input << %Q{call("foo", "bar", biz: "baz")}
|
324
|
+
|
325
|
+
parser = Rundoc::PegParser.new.method_call
|
326
|
+
tree = parser.parse_with_debug(input)
|
327
|
+
|
328
|
+
actual = @transformer.apply(tree)
|
329
|
+
assert_equal ["foo", "bar", { biz: "baz"}], actual.original_args
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_positional_args_code_block
|
333
|
+
|
334
|
+
input = +""
|
335
|
+
input << %Q{:::>> background.start("rails server", name: "server")\n}
|
336
|
+
# input << %Q{:::-- background.stop(name: "server")\n}
|
337
|
+
|
338
|
+
parser = Rundoc::PegParser.new.command
|
339
|
+
|
340
|
+
tree = parser.parse_with_debug(input)
|
341
|
+
|
342
|
+
# puts tree.inspect
|
343
|
+
|
344
|
+
actual = @transformer.apply(tree)
|
345
|
+
assert_equal :"background.start", actual.keyword
|
346
|
+
assert_equal ["rails server", {:name=>"server"}], actual.original_args
|
347
|
+
end
|
348
|
+
end
|
data/test/rundoc/regex_test.rb
CHANGED