rundoc 0.0.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/check_changelog.yml +13 -0
  3. data/.gitignore +9 -0
  4. data/.travis.yml +8 -0
  5. data/CHANGELOG.md +22 -0
  6. data/Dockerfile +24 -0
  7. data/Gemfile +1 -0
  8. data/README.md +276 -74
  9. data/bin/rundoc +4 -52
  10. data/lib/rundoc.rb +15 -1
  11. data/lib/rundoc/cli.rb +84 -0
  12. data/lib/rundoc/code_command.rb +25 -6
  13. data/lib/rundoc/code_command/background.rb +9 -0
  14. data/lib/rundoc/code_command/background/log/clear.rb +17 -0
  15. data/lib/rundoc/code_command/background/log/read.rb +16 -0
  16. data/lib/rundoc/code_command/background/process_spawn.rb +96 -0
  17. data/lib/rundoc/code_command/background/start.rb +38 -0
  18. data/lib/rundoc/code_command/background/stop.rb +17 -0
  19. data/lib/rundoc/code_command/background/wait.rb +19 -0
  20. data/lib/rundoc/code_command/bash.rb +1 -1
  21. data/lib/rundoc/code_command/bash/cd.rb +21 -3
  22. data/lib/rundoc/code_command/file_command/append.rb +16 -11
  23. data/lib/rundoc/code_command/file_command/remove.rb +6 -5
  24. data/lib/rundoc/code_command/no_such_command.rb +4 -0
  25. data/lib/rundoc/code_command/pipe.rb +18 -5
  26. data/lib/rundoc/code_command/raw.rb +18 -0
  27. data/lib/rundoc/code_command/rundoc/depend_on.rb +37 -0
  28. data/lib/rundoc/code_command/rundoc/require.rb +41 -0
  29. data/lib/rundoc/code_command/rundoc_command.rb +6 -2
  30. data/lib/rundoc/code_command/website.rb +7 -0
  31. data/lib/rundoc/code_command/website/driver.rb +111 -0
  32. data/lib/rundoc/code_command/website/navigate.rb +29 -0
  33. data/lib/rundoc/code_command/website/screenshot.rb +28 -0
  34. data/lib/rundoc/code_command/website/visit.rb +47 -0
  35. data/lib/rundoc/code_command/write.rb +22 -7
  36. data/lib/rundoc/code_section.rb +41 -66
  37. data/lib/rundoc/parser.rb +5 -4
  38. data/lib/rundoc/peg_parser.rb +282 -0
  39. data/lib/rundoc/version.rb +2 -2
  40. data/rundoc.gemspec +9 -3
  41. data/test/fixtures/build_logs/rundoc.md +56 -0
  42. data/test/fixtures/depend_on/dependency/rundoc.md +5 -0
  43. data/test/fixtures/depend_on/main/rundoc.md +10 -0
  44. data/test/fixtures/java/rundoc.md +9 -0
  45. data/test/fixtures/rails_4/rundoc.md +151 -188
  46. data/test/fixtures/rails_5/rundoc.md +445 -0
  47. data/test/fixtures/rails_6/rundoc.md +451 -0
  48. data/test/fixtures/require/dependency/rundoc.md +5 -0
  49. data/test/fixtures/require/main/rundoc.md +10 -0
  50. data/test/fixtures/screenshot/rundoc.md +10 -0
  51. data/test/rundoc/code_commands/append_file_test.rb +33 -6
  52. data/test/rundoc/code_commands/background_test.rb +69 -0
  53. data/test/rundoc/code_commands/bash_test.rb +1 -1
  54. data/test/rundoc/code_commands/pipe_test.rb +1 -1
  55. data/test/rundoc/code_commands/remove_contents_test.rb +3 -4
  56. data/test/rundoc/code_section_test.rb +95 -2
  57. data/test/rundoc/parser_test.rb +7 -13
  58. data/test/rundoc/peg_parser_test.rb +381 -0
  59. data/test/rundoc/regex_test.rb +6 -6
  60. data/test/rundoc/test_parse_java.rb +1 -1
  61. data/test/test_helper.rb +1 -3
  62. metadata +143 -18
  63. data/Gemfile.lock +0 -38
@@ -0,0 +1,5 @@
1
+ ```
2
+ :::>> $ mkdir foo
3
+ :::>> $ cd foo
4
+ :::>> $ echo "hello" >> hello.txt
5
+ ```
@@ -0,0 +1,10 @@
1
+ # Hello
2
+
3
+ ```
4
+ :::-- rundoc.require "../dependency/rundoc.md"
5
+ ```
6
+
7
+ ```
8
+ :::>> $ ruby -e "raise 'nope' unless File.read('hello.txt').chomp == 'hello'"
9
+ ```
10
+
@@ -0,0 +1,10 @@
1
+ # Hello
2
+
3
+ ```
4
+ :::>> website.visit(name: "google", url: "https://www.google.com")
5
+ # session.visit("https://www.codetriage.com")
6
+ :::>> website.screenshot(name: "google", upload: "s3")
7
+ ```
8
+
9
+
10
+ ## There
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class AppendFileTest < Test::Unit::TestCase
3
+ class AppendFileTest < Minitest::Test
4
4
 
5
5
  def test_appends_to_a_file
6
6
  Dir.mktmpdir do |dir|
@@ -15,8 +15,8 @@ class AppendFileTest < Test::Unit::TestCase
15
15
 
16
16
  result = File.read(file)
17
17
 
18
- assert_match /foo/, result
19
- assert_match /bar/, result
18
+ assert_match(/foo/, result)
19
+ assert_match(/bar/, result)
20
20
 
21
21
  cc = Rundoc::CodeCommand::FileCommand::Append.new(file)
22
22
  cc << "baz"
@@ -29,14 +29,14 @@ class AppendFileTest < Test::Unit::TestCase
29
29
  end
30
30
  end
31
31
 
32
- def test_appends_to_a_file_at_line_number
32
+ def test_appends_to_a_file_at_line_number
33
33
  Dir.mktmpdir do |dir|
34
34
  Dir.chdir(dir) do
35
35
 
36
- contents = <<-CONTENTS
36
+ contents = <<-CONTENTS
37
37
  source 'https://rubygems.org'
38
38
  gem 'rails', '4.0.0'
39
- CONTENTS
39
+ CONTENTS
40
40
 
41
41
  file = "foo.rb"
42
42
  line = 2
@@ -52,4 +52,31 @@ CONTENTS
52
52
  end
53
53
  end
54
54
 
55
+ def test_globs_filenames
56
+ Dir.mktmpdir do |dir|
57
+ Dir.chdir(dir) do
58
+ filename = "file-#{Time.now.utc.strftime("%Y%m%d%H%M%S")}.txt"
59
+ FileUtils.touch(filename)
60
+ cc = Rundoc::CodeCommand::FileCommand::Append.new("file-*.txt")
61
+ cc << "some text"
62
+ cc.call
63
+
64
+ assert_equal "\nsome text\n", File.read(filename)
65
+ end
66
+ end
67
+ end
68
+
69
+ def test_glob_multiple_matches_raises
70
+ Dir.mktmpdir do |dir|
71
+ Dir.chdir(dir) do
72
+ FileUtils.touch("file-1234.txt")
73
+ FileUtils.touch("file-5678.txt")
74
+ assert_raises do
75
+ cc = Rundoc::CodeCommand::FileCommand::Append.new("file-*.txt")
76
+ cc << "some text"
77
+ cc.call
78
+ end
79
+ end
80
+ end
81
+ end
55
82
  end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class BackgroundTest < Minitest::Test
4
+ def test_process_spawn_gc
5
+ Dir.mktmpdir do |dir|
6
+ Dir.chdir(dir) do
7
+ file = "foo.txt"
8
+ `echo 'foo' >> #{file}`
9
+
10
+ background_start = Rundoc::CodeCommand::Background::Start.new("tail -f #{file}",
11
+ name: "tail2",
12
+ wait: "f"
13
+ )
14
+
15
+ GC.start
16
+
17
+ output = background_start.call
18
+
19
+ assert_match("foo", output)
20
+ assert_equal(true, background_start.alive?)
21
+
22
+ background_stop = Rundoc::CodeCommand::Background::Stop.new(name: "tail2")
23
+ background_stop.call
24
+
25
+ assert_equal(false, background_start.alive?)
26
+ end
27
+ end
28
+ end
29
+
30
+ def test_background_start
31
+ Dir.mktmpdir do |dir|
32
+ Dir.chdir(dir) do
33
+
34
+ file = "foo.txt"
35
+ `echo 'foo' >> #{file}`
36
+
37
+ background_start = Rundoc::CodeCommand::Background::Start.new("tail -f #{file}",
38
+ name: "tail",
39
+ wait: "f"
40
+ )
41
+ output = background_start.call
42
+
43
+ assert_match("foo", output)
44
+ assert_equal(true, background_start.alive?)
45
+
46
+ log_read = Rundoc::CodeCommand::Background::Log::Read.new(name: "tail")
47
+ output = log_read.call
48
+
49
+ assert_equal("foo", output.chomp)
50
+
51
+ log_clear = Rundoc::CodeCommand::Background::Log::Clear.new(name: "tail")
52
+ output = log_clear.call
53
+ assert_equal("", output)
54
+
55
+ `echo 'bar' >> #{file}`
56
+
57
+ log_read = Rundoc::CodeCommand::Background::Log::Read.new(name: "tail")
58
+ output = log_read.call
59
+
60
+ assert_equal("bar", output.chomp)
61
+
62
+ background_stop = Rundoc::CodeCommand::Background::Stop.new(name: "tail")
63
+ background_stop.call
64
+
65
+ assert_equal(false, background_start.alive?)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class BashTest < Test::Unit::TestCase
3
+ class BashTest < Minitest::Test
4
4
 
5
5
  def test_bash_returns_cd
6
6
  original_dir = `pwd`
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class PipeTest < Test::Unit::TestCase
3
+ class PipeTest < Minitest::Test
4
4
 
5
5
  def test_pipe
6
6
  pipe_cmd = "tail -n 2"
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class RemoveContentsTest < Test::Unit::TestCase
3
+ class RemoveContentsTest < Minitest::Test
4
4
 
5
5
  def setup
6
6
  @gemfile = <<-RUBY
@@ -21,14 +21,13 @@ class RemoveContentsTest < Test::Unit::TestCase
21
21
  @file = "foo.rb"
22
22
  `echo "#{@gemfile}" >> #{@file}`
23
23
 
24
- assert_match /sqlite3/, File.read(@file)
24
+ assert_match(/sqlite3/, File.read(@file))
25
25
 
26
26
  cc = Rundoc::CodeCommand::FileCommand::Remove.new(@file)
27
27
  cc << "gem 'sqlite3'"
28
28
  cc.call
29
29
 
30
- result = File.read(@file)
31
- refute_match /sqlite3/, File.read(@file)
30
+ refute_match(/sqlite3/, File.read(@file))
32
31
 
33
32
  env = {}
34
33
  env[:commands] = []
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class CodeSectionTest < Test::Unit::TestCase
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
- :::- $ mkdir foo
13
+ :::-- $ mkdir foo
14
14
  ```
15
15
 
16
16
  yo
@@ -39,4 +39,97 @@ RUBY
39
39
  assert_equal contents, result
40
40
  end
41
41
 
42
+ def test_show_command_hide_render
43
+ contents = <<-RUBY
44
+ ```
45
+ :::>- $ echo "foo"
46
+ ```
47
+ RUBY
48
+
49
+ match = contents.match(Rundoc::Parser::CODEBLOCK_REGEX)
50
+ code_section = Rundoc::CodeSection.new(match, keyword: ":::")
51
+ code_section.render
52
+
53
+ code_command = code_section.commands.first
54
+ assert_equal true, code_command.render_command
55
+ assert_equal false, code_command.render_result
56
+
57
+ contents = <<-RUBY
58
+ ```
59
+ :::>- $ echo "foo"
60
+ ```
61
+ RUBY
62
+
63
+ match = contents.match(Rundoc::Parser::CODEBLOCK_REGEX)
64
+ code_section = Rundoc::CodeSection.new(match, keyword: ":::")
65
+ code_section.render
66
+
67
+ code_command = code_section.commands.first
68
+ assert_equal true, code_command.render_command
69
+ assert_equal false, code_command.render_result
70
+ end
71
+
72
+ def test_show_command_show_render
73
+ contents = <<-RUBY
74
+ ```
75
+ :::>> $ echo "foo"
76
+ ```
77
+ RUBY
78
+
79
+ match = contents.match(Rundoc::Parser::CODEBLOCK_REGEX)
80
+ code_section = Rundoc::CodeSection.new(match, keyword: ":::")
81
+ code_section.render
82
+
83
+ puts code_section.commands.inspect
84
+ code_command = code_section.commands.first
85
+ assert_equal true, code_command.render_command
86
+ assert_equal true, code_command.render_result
87
+ end
88
+
89
+ def test_hide_command_hide_render
90
+ contents = <<-RUBY
91
+ ```
92
+ :::-- $ echo "foo"
93
+ ```
94
+ RUBY
95
+
96
+ match = contents.match(Rundoc::Parser::CODEBLOCK_REGEX)
97
+ code_section = Rundoc::CodeSection.new(match, keyword: ":::")
98
+ code_section.render
99
+
100
+ code_command = code_section.commands.first
101
+ assert_equal false, code_command.render_command
102
+ assert_equal false, code_command.render_result
103
+
104
+ contents = <<-RUBY
105
+ ```
106
+ :::-- $ echo "foo"
107
+ ```
108
+ RUBY
109
+
110
+ match = contents.match(Rundoc::Parser::CODEBLOCK_REGEX)
111
+ code_section = Rundoc::CodeSection.new(match, keyword: ":::")
112
+ code_section.render
113
+
114
+ code_command = code_section.commands.first
115
+ assert_equal false, code_command.render_command
116
+ assert_equal false, code_command.render_result
117
+ end
118
+
119
+ def test_hide_command_show_render
120
+ contents = <<-RUBY
121
+ ```
122
+ :::-> $ echo "foo"
123
+ ```
124
+ RUBY
125
+
126
+ match = contents.match(Rundoc::Parser::CODEBLOCK_REGEX)
127
+ code_section = Rundoc::CodeSection.new(match, keyword: ":::")
128
+ code_section.render
129
+
130
+ code_command = code_section.commands.first
131
+ assert_equal false, code_command.render_command
132
+ assert_equal true, code_command.render_result
133
+ end
134
+
42
135
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class ParserTest < Test::Unit::TestCase
3
+ class ParserTest < Minitest::Test
4
4
 
5
5
  def setup
6
6
  end
@@ -10,8 +10,8 @@ class ParserTest < Test::Unit::TestCase
10
10
  sup
11
11
 
12
12
  ```
13
- ::: $ mkdir foo
14
- :::= $ ls
13
+ :::>- $ mkdir foo
14
+ :::>> $ ls
15
15
  ```
16
16
 
17
17
  yo
@@ -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
@@ -39,7 +34,7 @@ RUBY
39
34
  sup
40
35
 
41
36
  ```
42
- :::= write foo/code.rb
37
+ :::>> write foo/code.rb
43
38
  a = 1 + 1
44
39
  b = a * 2
45
40
  ```
@@ -60,9 +55,9 @@ RUBY
60
55
  contents = <<-RUBY
61
56
 
62
57
  ```
63
- :::= write foo/newb.rb
58
+ :::>> write foo/newb.rb
64
59
  puts 'hello world'
65
- :::= $ cat foo/newb.rb
60
+ :::>> $ cat foo/newb.rb
66
61
  ```
67
62
  RUBY
68
63
 
@@ -81,14 +76,13 @@ RUBY
81
76
 
82
77
  contents = <<-RUBY
83
78
  ```
84
- :::= irb --simple-prompt
79
+ :::>> irb --simple-prompt
85
80
  a = 3
86
81
  b = "foo" * a
87
82
  puts b
88
83
  ```
89
84
  RUBY
90
85
 
91
-
92
86
  Dir.mktmpdir do |dir|
93
87
  Dir.chdir(dir) do
94
88
 
@@ -0,0 +1,381 @@
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
+ def test_rundoc_sub_commands_no_quotes
265
+ input = String.new
266
+ input << %Q{:::-- rundoc.depend_on ../foo/bar.md\n}
267
+
268
+ parser = Rundoc::PegParser.new.command_with_stdin
269
+ tree = parser.parse_with_debug(input)
270
+
271
+ actual = @transformer.apply(tree)
272
+ assert_equal :"rundoc.depend_on", actual.keyword
273
+ end
274
+
275
+ def test_seattle_style_method_call
276
+ input = String.new
277
+ input << %Q{rundoc.depend_on '../foo/bar.md'}
278
+ parser = Rundoc::PegParser.new.method_call
279
+ tree = parser.parse_with_debug(input)
280
+
281
+ actual = @transformer.apply(tree)
282
+
283
+ assert_equal :"rundoc.depend_on", actual.keyword
284
+ end
285
+
286
+ def test_rundoc_seattle_sub_command
287
+ input = String.new
288
+ input << %Q{:::>> rundoc.depend_on '../foo/bar.md'\n}
289
+
290
+ parser = Rundoc::PegParser.new.command
291
+ tree = parser.parse_with_debug(input)
292
+
293
+ actual = @transformer.apply(tree)
294
+
295
+ assert_equal :"rundoc.depend_on", actual.keyword
296
+ end
297
+
298
+ def test_positional_args
299
+ input = +""
300
+ input << %Q{call("foo", "bar", biz: "baz")}
301
+
302
+ parser = Rundoc::PegParser.new.method_call
303
+ tree = parser.parse_with_debug(input)
304
+
305
+ # =====================================
306
+ #
307
+ # Handles more than one value, but not only one value
308
+ actual = @transformer.apply(tree)
309
+ assert_equal ["foo", "bar", { biz: "baz"}], actual.original_args
310
+
311
+ input = +""
312
+ input << %Q{call("foo", biz: "baz")}
313
+
314
+ parser = Rundoc::PegParser.new.method_call
315
+ tree = parser.parse_with_debug(input)
316
+
317
+ actual = @transformer.apply(tree)
318
+ assert_equal ["foo", { biz: "baz"}], actual.original_args
319
+
320
+ input = +""
321
+ input << %Q{call("rails server", name: "server")}
322
+
323
+ parser = Rundoc::PegParser.new.method_call
324
+ tree = parser.parse_with_debug(input)
325
+
326
+ actual = @transformer.apply(tree)
327
+ assert_equal ["rails server", {name: "server"}], actual.original_args
328
+
329
+ # input = +""
330
+ # input << %Q{background.start("rails server", name: "server")}
331
+ # parser = Rundoc::PegParser.new.method_call
332
+
333
+ # tree = parser.parse_with_debug(input)
334
+
335
+ # puts tree.inspect
336
+
337
+ # actual = @transformer.apply(tree)
338
+ # assert_equal :"background.start", actual.keyword
339
+
340
+ # ================
341
+
342
+ input = +""
343
+ input << %Q{call("foo", "bar")}
344
+
345
+ parser = Rundoc::PegParser.new.method_call
346
+ tree = parser.parse_with_debug(input)
347
+
348
+ # puts tree.inspect
349
+
350
+ actual = @transformer.apply(tree)
351
+ assert_equal ["foo", "bar"], actual.original_args
352
+
353
+ # ======================
354
+
355
+ input = +""
356
+ input << %Q{call("foo", "bar", biz: "baz")}
357
+
358
+ parser = Rundoc::PegParser.new.method_call
359
+ tree = parser.parse_with_debug(input)
360
+
361
+ actual = @transformer.apply(tree)
362
+ assert_equal ["foo", "bar", { biz: "baz"}], actual.original_args
363
+ end
364
+
365
+ def test_positional_args_code_block
366
+
367
+ input = +""
368
+ input << %Q{:::>> background.start("rails server", name: "server")\n}
369
+ # input << %Q{:::-- background.stop(name: "server")\n}
370
+
371
+ parser = Rundoc::PegParser.new.command
372
+
373
+ tree = parser.parse_with_debug(input)
374
+
375
+ # puts tree.inspect
376
+
377
+ actual = @transformer.apply(tree)
378
+ assert_equal :"background.start", actual.keyword
379
+ assert_equal ["rails server", {:name=>"server"}], actual.original_args
380
+ end
381
+ end