rundoc 1.1.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/check_changelog.yml +16 -7
- data/.github/workflows/ci.yml +48 -0
- data/.standard.yml +6 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -1
- data/README.md +98 -5
- data/Rakefile +9 -10
- data/lib/rundoc/cli.rb +15 -17
- data/lib/rundoc/code_command/background/log/clear.rb +1 -1
- data/lib/rundoc/code_command/background/log/read.rb +1 -1
- data/lib/rundoc/code_command/background/process_spawn.rb +8 -9
- data/lib/rundoc/code_command/background/start.rb +7 -7
- data/lib/rundoc/code_command/background/stop.rb +1 -1
- data/lib/rundoc/code_command/background/wait.rb +2 -2
- data/lib/rundoc/code_command/background.rb +6 -6
- data/lib/rundoc/code_command/bash/cd.rb +6 -7
- data/lib/rundoc/code_command/bash.rb +10 -12
- data/lib/rundoc/code_command/file_command/append.rb +12 -16
- data/lib/rundoc/code_command/file_command/remove.rb +6 -9
- data/lib/rundoc/code_command/no_such_command.rb +0 -1
- data/lib/rundoc/code_command/pipe.rb +2 -5
- data/lib/rundoc/code_command/print/erb.rb +48 -0
- data/lib/rundoc/code_command/print/text.rb +33 -0
- data/lib/rundoc/code_command/raw.rb +1 -1
- data/lib/rundoc/code_command/rundoc/depend_on.rb +0 -1
- data/lib/rundoc/code_command/rundoc/require.rb +2 -3
- data/lib/rundoc/code_command/rundoc_command.rb +3 -4
- data/lib/rundoc/code_command/website/driver.rb +17 -17
- data/lib/rundoc/code_command/website/navigate.rb +2 -2
- data/lib/rundoc/code_command/website/screenshot.rb +1 -1
- data/lib/rundoc/code_command/website/visit.rb +4 -5
- data/lib/rundoc/code_command/website.rb +4 -4
- data/lib/rundoc/code_command/write.rb +10 -11
- data/lib/rundoc/code_command.rb +28 -17
- data/lib/rundoc/code_section.rb +42 -25
- data/lib/rundoc/parser.rb +17 -19
- data/lib/rundoc/peg_parser.rb +57 -59
- data/lib/rundoc/version.rb +1 -1
- data/lib/rundoc.rb +10 -14
- data/rundoc.gemspec +19 -21
- data/test/fixtures/rails_4/rundoc.md +94 -30
- data/test/fixtures/rails_5/rundoc.md +69 -10
- data/test/fixtures/rails_6/rundoc.md +226 -165
- data/test/fixtures/rails_7/rundoc.md +477 -0
- data/test/integration/print_test.rb +194 -0
- data/test/rundoc/code_commands/append_file_test.rb +5 -8
- data/test/rundoc/code_commands/background_test.rb +3 -6
- data/test/rundoc/code_commands/bash_test.rb +7 -9
- data/test/rundoc/code_commands/pipe_test.rb +9 -9
- data/test/rundoc/code_commands/print_test.rb +94 -0
- data/test/rundoc/code_commands/remove_contents_test.rb +4 -5
- data/test/rundoc/code_section_test.rb +50 -56
- data/test/rundoc/parser_test.rb +28 -61
- data/test/rundoc/peg_parser_test.rb +49 -53
- data/test/rundoc/regex_test.rb +120 -127
- data/test/rundoc/test_parse_java.rb +1 -3
- data/test/test_helper.rb +4 -6
- metadata +39 -42
- data/.travis.yml +0 -8
- data/lib/rundoc/code_command/repl.rb +0 -37
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "test_helper"
|
2
|
+
require "parslet/convenience"
|
3
3
|
|
4
4
|
class PegParserTest < Minitest::Test
|
5
5
|
def setup
|
@@ -7,10 +7,10 @@ class PegParserTest < Minitest::Test
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_string
|
10
|
-
input = %
|
10
|
+
input = %("hello world")
|
11
11
|
parser = Rundoc::PegParser.new.string
|
12
12
|
tree = parser.parse_with_debug(input)
|
13
|
-
expected = {:
|
13
|
+
expected = {string: "hello world"}
|
14
14
|
assert_equal expected, tree
|
15
15
|
|
16
16
|
actual = @transformer.apply(tree)
|
@@ -18,42 +18,42 @@ class PegParserTest < Minitest::Test
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_keyword_args
|
21
|
-
input = %
|
21
|
+
input = %(foo: 'bar', baz: "boo")
|
22
22
|
parser = Rundoc::PegParser.new.named_args
|
23
23
|
tree = parser.parse_with_debug(input)
|
24
24
|
actual = @transformer.apply(tree)
|
25
|
-
expected = {foo:
|
25
|
+
expected = {foo: "bar", baz: "boo"}
|
26
26
|
assert_equal expected, actual
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_method_call
|
30
|
-
input = %
|
30
|
+
input = %{sup(foo: 'bar')}
|
31
31
|
parser = Rundoc::PegParser.new.method_call
|
32
32
|
tree = parser.parse_with_debug(input)
|
33
33
|
|
34
34
|
actual = @transformer.apply(tree)
|
35
35
|
assert_equal :sup, actual.keyword
|
36
|
-
assert_equal({foo:
|
36
|
+
assert_equal({foo: "bar"}, actual.original_args)
|
37
37
|
|
38
38
|
# seattle style
|
39
|
-
input = %
|
39
|
+
input = %(sup foo: 'bar' )
|
40
40
|
parser = Rundoc::PegParser.new.method_call
|
41
41
|
tree = parser.parse_with_debug(input)
|
42
42
|
actual = @transformer.apply(tree)
|
43
43
|
assert_equal :sup, actual.keyword
|
44
|
-
assert_equal({foo:
|
44
|
+
assert_equal({foo: "bar"}, actual.original_args)
|
45
45
|
|
46
46
|
# with a dot
|
47
|
-
input = %
|
47
|
+
input = %(sup.you foo: 'bar' )
|
48
48
|
parser = Rundoc::PegParser.new.method_call
|
49
49
|
tree = parser.parse_with_debug(input)
|
50
50
|
actual = @transformer.apply(tree)
|
51
51
|
assert_equal :"sup.you", actual.keyword
|
52
|
-
assert_equal({foo:
|
52
|
+
assert_equal({foo: "bar"}, actual.original_args)
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_with_string_arg
|
56
|
-
input = %
|
56
|
+
input = %{sup("hey")}
|
57
57
|
parser = Rundoc::PegParser.new.method_call
|
58
58
|
tree = parser.parse_with_debug(input)
|
59
59
|
|
@@ -61,7 +61,7 @@ class PegParserTest < Minitest::Test
|
|
61
61
|
assert_equal :sup, actual.keyword
|
62
62
|
assert_equal("hey", actual.original_args)
|
63
63
|
|
64
|
-
input = %
|
64
|
+
input = %(sup "hey")
|
65
65
|
parser = Rundoc::PegParser.new.method_call
|
66
66
|
tree = parser.parse_with_debug(input)
|
67
67
|
|
@@ -69,7 +69,7 @@ class PegParserTest < Minitest::Test
|
|
69
69
|
assert_equal :sup, actual.keyword
|
70
70
|
assert_equal("hey", actual.original_args)
|
71
71
|
|
72
|
-
input = %
|
72
|
+
input = %(sup hey)
|
73
73
|
parser = Rundoc::PegParser.new.method_call
|
74
74
|
tree = parser.parse_with_debug(input)
|
75
75
|
|
@@ -77,7 +77,7 @@ class PegParserTest < Minitest::Test
|
|
77
77
|
assert_equal :sup, actual.keyword
|
78
78
|
assert_equal("hey", actual.original_args)
|
79
79
|
|
80
|
-
input = %
|
80
|
+
input = %( $ cat foo.rb)
|
81
81
|
parser = Rundoc::PegParser.new.method_call
|
82
82
|
tree = parser.parse_with_debug(input)
|
83
83
|
|
@@ -87,28 +87,28 @@ class PegParserTest < Minitest::Test
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def test_visability
|
90
|
-
input = %
|
90
|
+
input = %(>>)
|
91
91
|
parser = Rundoc::PegParser.new.visability
|
92
92
|
tree = parser.parse_with_debug(input)
|
93
93
|
actual = @transformer.apply(tree)
|
94
94
|
assert_equal true, actual.command?
|
95
95
|
assert_equal true, actual.result?
|
96
96
|
|
97
|
-
input = %
|
97
|
+
input = %(->)
|
98
98
|
parser = Rundoc::PegParser.new.visability
|
99
99
|
tree = parser.parse_with_debug(input)
|
100
100
|
actual = @transformer.apply(tree)
|
101
101
|
assert_equal false, actual.command?
|
102
102
|
assert_equal true, actual.result?
|
103
103
|
|
104
|
-
input = %
|
104
|
+
input = %(--)
|
105
105
|
parser = Rundoc::PegParser.new.visability
|
106
106
|
tree = parser.parse_with_debug(input)
|
107
107
|
actual = @transformer.apply(tree)
|
108
108
|
assert_equal false, actual.command?
|
109
109
|
assert_equal false, actual.result?
|
110
110
|
|
111
|
-
input = %
|
111
|
+
input = %(>-)
|
112
112
|
parser = Rundoc::PegParser.new.visability
|
113
113
|
tree = parser.parse_with_debug(input)
|
114
114
|
actual = @transformer.apply(tree)
|
@@ -117,7 +117,7 @@ class PegParserTest < Minitest::Test
|
|
117
117
|
end
|
118
118
|
|
119
119
|
def test_blerg_method_call
|
120
|
-
input = %
|
120
|
+
input = %($ cat foo.rb)
|
121
121
|
parser = Rundoc::PegParser.new.method_call
|
122
122
|
tree = parser.parse_with_debug(input)
|
123
123
|
|
@@ -127,7 +127,7 @@ class PegParserTest < Minitest::Test
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def test_command
|
130
|
-
input = %
|
130
|
+
input = %(:::>> $ cat foo.rb\n)
|
131
131
|
parser = Rundoc::PegParser.new.command
|
132
132
|
tree = parser.parse_with_debug(input)
|
133
133
|
|
@@ -137,7 +137,7 @@ class PegParserTest < Minitest::Test
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def test_command_with_stdin
|
140
|
-
input =
|
140
|
+
input = +""
|
141
141
|
input << ":::>> file.write hello.txt\n"
|
142
142
|
input << "world\n"
|
143
143
|
|
@@ -151,7 +151,7 @@ class PegParserTest < Minitest::Test
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def test_command_with_stdin_no_string
|
154
|
-
input =
|
154
|
+
input = +""
|
155
155
|
input << ":::>> file.write hello.txt\n"
|
156
156
|
|
157
157
|
parser = Rundoc::PegParser.new.command_with_stdin
|
@@ -164,7 +164,7 @@ class PegParserTest < Minitest::Test
|
|
164
164
|
end
|
165
165
|
|
166
166
|
def test_multiple_commands_stdin
|
167
|
-
input =
|
167
|
+
input = +""
|
168
168
|
input << ":::>> file.write hello.txt\n"
|
169
169
|
input << "world\n"
|
170
170
|
input << ":::>> file.write cinco.txt\n"
|
@@ -186,7 +186,7 @@ class PegParserTest < Minitest::Test
|
|
186
186
|
end
|
187
187
|
|
188
188
|
def test_multiple_commands_with_fence
|
189
|
-
input =
|
189
|
+
input = +""
|
190
190
|
input << "```\n"
|
191
191
|
input << ":::>> file.write hello.txt\n"
|
192
192
|
input << "world\n"
|
@@ -203,7 +203,7 @@ class PegParserTest < Minitest::Test
|
|
203
203
|
end
|
204
204
|
|
205
205
|
def test_raw
|
206
|
-
input =
|
206
|
+
input = +""
|
207
207
|
input << "hello.txt\n"
|
208
208
|
input << "world\n"
|
209
209
|
input << ":::>> $ cd foo\n"
|
@@ -218,9 +218,8 @@ class PegParserTest < Minitest::Test
|
|
218
218
|
assert_equal("cd foo", actual.last.original_args)
|
219
219
|
end
|
220
220
|
|
221
|
-
|
222
221
|
def test_quotes_in_shell_commands
|
223
|
-
input = %
|
222
|
+
input = %(:::>- $ git commit -m "init"\n)
|
224
223
|
parser = Rundoc::PegParser.new.code_block
|
225
224
|
tree = parser.parse_with_debug(input)
|
226
225
|
|
@@ -231,16 +230,15 @@ class PegParserTest < Minitest::Test
|
|
231
230
|
end
|
232
231
|
|
233
232
|
def test_raises_on_syntax
|
234
|
-
input = %
|
233
|
+
input = %(:::> $ git commit -m "init"\n)
|
235
234
|
assert_raises(Rundoc::PegTransformer::TransformError) do
|
236
235
|
parser = Rundoc::PegParser.new.code_block
|
237
236
|
tree = parser.parse_with_debug(input)
|
238
237
|
|
239
|
-
|
238
|
+
@transformer.apply(tree)
|
240
239
|
end
|
241
240
|
end
|
242
241
|
|
243
|
-
|
244
242
|
def test_no_args
|
245
243
|
# input = String.new
|
246
244
|
# input << %Q{rundoc}
|
@@ -258,10 +256,9 @@ class PegParserTest < Minitest::Test
|
|
258
256
|
# assert_equal :rundoc, actual.keyword
|
259
257
|
# assert_nil(actual.original_args)
|
260
258
|
|
261
|
-
|
262
|
-
input
|
263
|
-
input << %
|
264
|
-
input << %Q{email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`\n}
|
259
|
+
input = +""
|
260
|
+
input << %(:::-- rundoc\n)
|
261
|
+
input << %(email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`\n)
|
265
262
|
|
266
263
|
parser = Rundoc::PegParser.new.command_with_stdin
|
267
264
|
tree = parser.parse_with_debug(input)
|
@@ -272,8 +269,8 @@ class PegParserTest < Minitest::Test
|
|
272
269
|
end
|
273
270
|
|
274
271
|
def test_rundoc_sub_commands_no_quotes
|
275
|
-
input =
|
276
|
-
input << %
|
272
|
+
input = +""
|
273
|
+
input << %(:::-- rundoc.depend_on ../foo/bar.md\n)
|
277
274
|
|
278
275
|
parser = Rundoc::PegParser.new.command_with_stdin
|
279
276
|
tree = parser.parse_with_debug(input)
|
@@ -283,8 +280,8 @@ class PegParserTest < Minitest::Test
|
|
283
280
|
end
|
284
281
|
|
285
282
|
def test_seattle_style_method_call
|
286
|
-
input =
|
287
|
-
input << %
|
283
|
+
input = +""
|
284
|
+
input << %(rundoc.depend_on '../foo/bar.md')
|
288
285
|
parser = Rundoc::PegParser.new.method_call
|
289
286
|
tree = parser.parse_with_debug(input)
|
290
287
|
|
@@ -294,8 +291,8 @@ class PegParserTest < Minitest::Test
|
|
294
291
|
end
|
295
292
|
|
296
293
|
def test_rundoc_seattle_sub_command
|
297
|
-
input =
|
298
|
-
input << %
|
294
|
+
input = +""
|
295
|
+
input << %(:::>> rundoc.depend_on '../foo/bar.md'\n)
|
299
296
|
|
300
297
|
parser = Rundoc::PegParser.new.command
|
301
298
|
tree = parser.parse_with_debug(input)
|
@@ -307,7 +304,7 @@ class PegParserTest < Minitest::Test
|
|
307
304
|
|
308
305
|
def test_positional_args
|
309
306
|
input = +""
|
310
|
-
input << %
|
307
|
+
input << %{call("foo", "bar", biz: "baz")}
|
311
308
|
|
312
309
|
parser = Rundoc::PegParser.new.method_call
|
313
310
|
tree = parser.parse_with_debug(input)
|
@@ -316,19 +313,19 @@ class PegParserTest < Minitest::Test
|
|
316
313
|
#
|
317
314
|
# Handles more than one value, but not only one value
|
318
315
|
actual = @transformer.apply(tree)
|
319
|
-
assert_equal ["foo", "bar", {
|
316
|
+
assert_equal ["foo", "bar", {biz: "baz"}], actual.original_args
|
320
317
|
|
321
318
|
input = +""
|
322
|
-
input << %
|
319
|
+
input << %{call("foo", biz: "baz")}
|
323
320
|
|
324
321
|
parser = Rundoc::PegParser.new.method_call
|
325
322
|
tree = parser.parse_with_debug(input)
|
326
323
|
|
327
324
|
actual = @transformer.apply(tree)
|
328
|
-
assert_equal ["foo", {
|
325
|
+
assert_equal ["foo", {biz: "baz"}], actual.original_args
|
329
326
|
|
330
327
|
input = +""
|
331
|
-
input << %
|
328
|
+
input << %{call("rails server", name: "server")}
|
332
329
|
|
333
330
|
parser = Rundoc::PegParser.new.method_call
|
334
331
|
tree = parser.parse_with_debug(input)
|
@@ -350,7 +347,7 @@ class PegParserTest < Minitest::Test
|
|
350
347
|
# ================
|
351
348
|
|
352
349
|
input = +""
|
353
|
-
input << %
|
350
|
+
input << %{call("foo", "bar")}
|
354
351
|
|
355
352
|
parser = Rundoc::PegParser.new.method_call
|
356
353
|
tree = parser.parse_with_debug(input)
|
@@ -363,19 +360,18 @@ class PegParserTest < Minitest::Test
|
|
363
360
|
# ======================
|
364
361
|
|
365
362
|
input = +""
|
366
|
-
input << %
|
363
|
+
input << %{call("foo", "bar", biz: "baz")}
|
367
364
|
|
368
365
|
parser = Rundoc::PegParser.new.method_call
|
369
366
|
tree = parser.parse_with_debug(input)
|
370
367
|
|
371
368
|
actual = @transformer.apply(tree)
|
372
|
-
assert_equal ["foo", "bar", {
|
369
|
+
assert_equal ["foo", "bar", {biz: "baz"}], actual.original_args
|
373
370
|
end
|
374
371
|
|
375
372
|
def test_positional_args_code_block
|
376
|
-
|
377
373
|
input = +""
|
378
|
-
input << %
|
374
|
+
input << %{:::>> background.start("rails server", name: "server")\n}
|
379
375
|
# input << %Q{:::-- background.stop(name: "server")\n}
|
380
376
|
|
381
377
|
parser = Rundoc::PegParser.new.command
|
@@ -386,6 +382,6 @@ class PegParserTest < Minitest::Test
|
|
386
382
|
|
387
383
|
actual = @transformer.apply(tree)
|
388
384
|
assert_equal :"background.start", actual.keyword
|
389
|
-
assert_equal ["rails server", {:
|
385
|
+
assert_equal ["rails server", {name: "server"}], actual.original_args
|
390
386
|
end
|
391
387
|
end
|
data/test/rundoc/regex_test.rb
CHANGED
@@ -1,126 +1,121 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
class RegexTest < Minitest::Test
|
4
|
-
|
5
4
|
def setup
|
6
5
|
end
|
7
6
|
|
8
7
|
def test_indent_regex
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
regex = Rundoc::Parser::INDENT_BLOCK
|
8
|
+
contents = <<~RUBY
|
9
|
+
foo
|
10
|
+
|
11
|
+
$ cd
|
12
|
+
yo
|
13
|
+
sup
|
14
|
+
|
15
|
+
bar
|
16
|
+
RUBY
|
17
|
+
|
18
|
+
regex = Rundoc::Parser::INDENT_BLOCK
|
21
19
|
parsed = contents.match(/#{regex}/).to_s
|
22
20
|
assert_equal "\n $ cd\n yo\n sup\n", parsed
|
23
21
|
end
|
24
22
|
|
25
23
|
def test_github_regex
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
regex = Rundoc::Parser::GITHUB_BLOCK
|
24
|
+
contents = <<~RUBY
|
25
|
+
foo
|
26
|
+
|
27
|
+
```
|
28
|
+
$ cd
|
29
|
+
yo
|
30
|
+
sup
|
31
|
+
```
|
32
|
+
|
33
|
+
bar
|
34
|
+
RUBY
|
35
|
+
|
36
|
+
regex = Rundoc::Parser::GITHUB_BLOCK
|
40
37
|
parsed = contents.match(/#{regex}/m).to_s
|
41
38
|
assert_equal "```\n$ cd\nyo\nsup\n```\n", parsed
|
42
39
|
end
|
43
40
|
|
44
41
|
def test_github_tagged_regex
|
45
|
-
contents =
|
46
|
-
foo
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
$ cd
|
50
|
-
yo
|
51
|
-
sup
|
52
|
-
```
|
53
|
-
|
54
|
-
bar
|
55
|
-
RUBY
|
56
|
-
|
57
|
-
regex
|
42
|
+
contents = <<~RUBY
|
43
|
+
foo
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
$ cd
|
47
|
+
yo
|
48
|
+
sup
|
49
|
+
```
|
50
|
+
|
51
|
+
bar
|
52
|
+
RUBY
|
53
|
+
|
54
|
+
regex = Rundoc::Parser::GITHUB_BLOCK
|
58
55
|
parsed = contents.match(/#{regex}/m).to_s
|
59
56
|
assert_equal "```ruby\n$ cd\nyo\nsup\n```\n", parsed
|
60
57
|
end
|
61
58
|
|
62
59
|
def test_command_regex
|
63
|
-
regex
|
60
|
+
regex = Rundoc::Parser::COMMAND_REGEX.call(":::")
|
64
61
|
|
65
62
|
contents = ":::$ mkdir schneems"
|
66
|
-
match
|
67
|
-
assert_equal "",
|
63
|
+
match = contents.match(regex)
|
64
|
+
assert_equal "", match[:tag]
|
68
65
|
assert_equal "$", match[:command]
|
69
66
|
assert_equal "mkdir schneems", match[:statement]
|
70
67
|
|
71
68
|
contents = ":::=$ mkdir schneems"
|
72
|
-
match
|
69
|
+
match = contents.match(regex)
|
73
70
|
assert_equal "=", match[:tag]
|
74
71
|
assert_equal "$", match[:command]
|
75
72
|
assert_equal "mkdir schneems", match[:statement]
|
76
73
|
|
77
74
|
contents = ":::= $ mkdir schneems"
|
78
|
-
match
|
75
|
+
match = contents.match(regex)
|
79
76
|
assert_equal "=", match[:tag]
|
80
77
|
assert_equal "$", match[:command]
|
81
78
|
assert_equal "mkdir schneems", match[:statement]
|
82
79
|
|
83
80
|
contents = ":::-$ mkdir schneems"
|
84
|
-
match
|
81
|
+
match = contents.match(regex)
|
85
82
|
assert_equal "-", match[:tag]
|
86
83
|
assert_equal "$", match[:command]
|
87
84
|
assert_equal "mkdir schneems", match[:statement]
|
88
85
|
|
89
86
|
contents = ":::- $ mkdir schneems"
|
90
|
-
match
|
87
|
+
match = contents.match(regex)
|
91
88
|
assert_equal "-", match[:tag]
|
92
89
|
assert_equal "$", match[:command]
|
93
90
|
assert_equal "mkdir schneems", match[:statement]
|
94
91
|
end
|
95
92
|
|
96
|
-
|
97
93
|
def test_codeblock_regex
|
94
|
+
contents = <<~RUBY
|
95
|
+
foo
|
96
|
+
|
97
|
+
```
|
98
|
+
:::>$ mkdir
|
99
|
+
```
|
100
|
+
|
101
|
+
zoo
|
102
|
+
|
103
|
+
```
|
104
|
+
:::>$ cd ..
|
105
|
+
something
|
106
|
+
```
|
107
|
+
|
108
|
+
bar
|
109
|
+
RUBY
|
98
110
|
|
99
|
-
|
100
|
-
foo
|
101
|
-
|
102
|
-
```
|
103
|
-
:::>$ mkdir
|
104
|
-
```
|
105
|
-
|
106
|
-
zoo
|
107
|
-
|
108
|
-
```
|
109
|
-
:::>$ cd ..
|
110
|
-
something
|
111
|
-
```
|
112
|
-
|
113
|
-
bar
|
114
|
-
RUBY
|
115
|
-
|
116
|
-
regex = Rundoc::Parser::CODEBLOCK_REGEX
|
111
|
+
regex = Rundoc::Parser::CODEBLOCK_REGEX
|
117
112
|
|
118
|
-
actual
|
113
|
+
actual = contents.partition(regex)
|
119
114
|
expected = ["foo\n\n",
|
120
|
-
|
121
|
-
|
115
|
+
"```\n:::>$ mkdir\n```\n",
|
116
|
+
"\nzoo\n\n```\n:::>$ cd ..\nsomething\n```\n\nbar\n"]
|
122
117
|
|
123
|
-
assert_equal
|
118
|
+
assert_equal expected, actual
|
124
119
|
|
125
120
|
str = "```\n:::$ mkdir\n```\n"
|
126
121
|
match = str.match(regex)
|
@@ -134,67 +129,65 @@ RUBY
|
|
134
129
|
end
|
135
130
|
|
136
131
|
def test_complex_regex
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
import
|
144
|
-
import
|
145
|
-
import play.libs.
|
146
|
-
import play.
|
147
|
-
import play.mvc.
|
148
|
-
import play.mvc.
|
149
|
-
import
|
150
|
-
import
|
151
|
-
import
|
152
|
-
import akka.actor.
|
153
|
-
import akka.actor.
|
154
|
-
|
155
|
-
|
156
|
-
public
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
132
|
+
contents = <<~RUBY
|
133
|
+
```java
|
134
|
+
:::>> write app/controllers/Application.java
|
135
|
+
package controllers;
|
136
|
+
|
137
|
+
import static java.util.concurrent.TimeUnit.SECONDS;
|
138
|
+
import models.Pinger;
|
139
|
+
import play.libs.Akka;
|
140
|
+
import play.libs.F.Callback0;
|
141
|
+
import play.mvc.Controller;
|
142
|
+
import play.mvc.Result;
|
143
|
+
import play.mvc.WebSocket;
|
144
|
+
import scala.concurrent.duration.Duration;
|
145
|
+
import views.html.index;
|
146
|
+
import akka.actor.ActorRef;
|
147
|
+
import akka.actor.Cancellable;
|
148
|
+
import akka.actor.Props;
|
149
|
+
|
150
|
+
public class Application extends Controller {
|
151
|
+
public static WebSocket<String> pingWs() {
|
152
|
+
return new WebSocket<String>() {
|
153
|
+
public void onReady(WebSocket.In<String> in, WebSocket.Out<String> out) {
|
154
|
+
final ActorRef pingActor = Akka.system().actorOf(Props.create(Pinger.class, in, out));
|
155
|
+
final Cancellable cancellable = Akka.system().scheduler().schedule(Duration.create(1, SECONDS),
|
156
|
+
Duration.create(1, SECONDS),
|
157
|
+
pingActor,
|
158
|
+
"Tick",
|
159
|
+
Akka.system().dispatcher(),
|
160
|
+
null
|
161
|
+
);
|
162
|
+
|
163
|
+
in.onClose(new Callback0() {
|
164
|
+
@Override
|
165
|
+
public void invoke() throws Throwable {
|
166
|
+
cancellable.cancel();
|
167
|
+
}
|
168
|
+
});
|
173
169
|
}
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
```
|
189
|
-
RUBY
|
170
|
+
|
171
|
+
};
|
172
|
+
}
|
173
|
+
|
174
|
+
public static Result pingJs() {
|
175
|
+
return ok(views.js.ping.render());
|
176
|
+
}
|
177
|
+
|
178
|
+
public static Result index() {
|
179
|
+
return ok(index.render());
|
180
|
+
}
|
181
|
+
}
|
182
|
+
```
|
183
|
+
RUBY
|
190
184
|
|
191
185
|
regex = Rundoc::Parser::CODEBLOCK_REGEX
|
192
186
|
match = contents.match(regex)
|
193
|
-
assert_equal
|
194
|
-
assert_equal
|
195
|
-
assert_equal
|
187
|
+
assert_equal "java", match[:lang]
|
188
|
+
assert_equal "```", match[:fence]
|
189
|
+
assert_equal "`", match[:fence_char]
|
196
190
|
|
197
191
|
assert_equal contents.strip, match.to_s.strip
|
198
192
|
end
|
199
|
-
|
200
193
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "bundler"
|
2
2
|
|
3
3
|
Bundler.require
|
4
4
|
|
5
|
-
|
6
|
-
require 'rundoc'
|
5
|
+
require "rundoc"
|
7
6
|
require "minitest/autorun"
|
8
|
-
require "mocha/
|
9
|
-
require
|
10
|
-
|
7
|
+
require "mocha/minitest"
|
8
|
+
require "tmpdir"
|
11
9
|
|
12
10
|
def assert_tests_run
|
13
11
|
end
|