walrus 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. data/bin/walrus +44 -0
  2. data/ext/jindex/extconf.rb +11 -0
  3. data/ext/jindex/jindex.c +79 -0
  4. data/ext/mkdtemp/extconf.rb +11 -0
  5. data/ext/mkdtemp/mkdtemp.c +41 -0
  6. data/lib/walrus/additions/module.rb +36 -0
  7. data/lib/walrus/additions/string.rb +37 -0
  8. data/lib/walrus/additions/test/unit/error_collector.rb +62 -0
  9. data/lib/walrus/compile_error.rb +28 -0
  10. data/lib/walrus/compiler.rb +124 -0
  11. data/lib/walrus/contrib/spec/walruscloth_spec.rb +32 -0
  12. data/lib/walrus/contrib/walruscloth.rb +82 -0
  13. data/lib/walrus/diff.rb +89 -0
  14. data/lib/walrus/document.rb +98 -0
  15. data/lib/walrus/grammar/additions/proc.rb +20 -0
  16. data/lib/walrus/grammar/additions/regexp.rb +21 -0
  17. data/lib/walrus/grammar/additions/string.rb +52 -0
  18. data/lib/walrus/grammar/additions/symbol.rb +42 -0
  19. data/lib/walrus/grammar/and_predicate.rb +40 -0
  20. data/lib/walrus/grammar/array_result.rb +19 -0
  21. data/lib/walrus/grammar/continuation_wrapper_exception.rb +28 -0
  22. data/lib/walrus/grammar/left_recursion_exception.rb +27 -0
  23. data/lib/walrus/grammar/location_tracking.rb +105 -0
  24. data/lib/walrus/grammar/match_data_wrapper.rb +65 -0
  25. data/lib/walrus/grammar/memoizing.rb +41 -0
  26. data/lib/walrus/grammar/memoizing_cache.rb +94 -0
  27. data/lib/walrus/grammar/node.rb +60 -0
  28. data/lib/walrus/grammar/not_predicate.rb +40 -0
  29. data/lib/walrus/grammar/parse_error.rb +39 -0
  30. data/lib/walrus/grammar/parser_state.rb +181 -0
  31. data/lib/walrus/grammar/parslet.rb +28 -0
  32. data/lib/walrus/grammar/parslet_choice.rb +120 -0
  33. data/lib/walrus/grammar/parslet_combination.rb +26 -0
  34. data/lib/walrus/grammar/parslet_combining.rb +154 -0
  35. data/lib/walrus/grammar/parslet_merge.rb +88 -0
  36. data/lib/walrus/grammar/parslet_omission.rb +57 -0
  37. data/lib/walrus/grammar/parslet_repetition.rb +97 -0
  38. data/lib/walrus/grammar/parslet_repetition_default.rb +58 -0
  39. data/lib/walrus/grammar/parslet_sequence.rb +202 -0
  40. data/lib/walrus/grammar/predicate.rb +57 -0
  41. data/lib/walrus/grammar/proc_parslet.rb +52 -0
  42. data/lib/walrus/grammar/regexp_parslet.rb +73 -0
  43. data/lib/walrus/grammar/skipped_substring_exception.rb +36 -0
  44. data/lib/walrus/grammar/string_enumerator.rb +45 -0
  45. data/lib/walrus/grammar/string_parslet.rb +75 -0
  46. data/lib/walrus/grammar/string_result.rb +24 -0
  47. data/lib/walrus/grammar/symbol_parslet.rb +63 -0
  48. data/lib/walrus/grammar.rb +170 -0
  49. data/lib/walrus/no_parameter_marker.rb +19 -0
  50. data/lib/walrus/parser.rb +420 -0
  51. data/lib/walrus/runner.rb +356 -0
  52. data/lib/walrus/template.rb +75 -0
  53. data/lib/walrus/walrus_grammar/assignment_expression.rb +24 -0
  54. data/lib/walrus/walrus_grammar/block_directive.rb +28 -0
  55. data/lib/walrus/walrus_grammar/comment.rb +24 -0
  56. data/lib/walrus/walrus_grammar/def_directive.rb +64 -0
  57. data/lib/walrus/walrus_grammar/echo_directive.rb +44 -0
  58. data/lib/walrus/walrus_grammar/escape_sequence.rb +24 -0
  59. data/lib/walrus/walrus_grammar/import_directive.rb +44 -0
  60. data/lib/walrus/walrus_grammar/include_directive.rb +27 -0
  61. data/lib/walrus/walrus_grammar/instance_variable.rb +24 -0
  62. data/lib/walrus/walrus_grammar/literal.rb +24 -0
  63. data/lib/walrus/walrus_grammar/message_expression.rb +25 -0
  64. data/lib/walrus/walrus_grammar/multiline_comment.rb +54 -0
  65. data/lib/walrus/walrus_grammar/placeholder.rb +40 -0
  66. data/lib/walrus/walrus_grammar/raw_directive.rb +42 -0
  67. data/lib/walrus/walrus_grammar/raw_text.rb +45 -0
  68. data/lib/walrus/walrus_grammar/ruby_directive.rb +29 -0
  69. data/lib/walrus/walrus_grammar/ruby_expression.rb +31 -0
  70. data/lib/walrus/walrus_grammar/set_directive.rb +24 -0
  71. data/lib/walrus/walrus_grammar/silent_directive.rb +44 -0
  72. data/lib/walrus/walrus_grammar/slurp_directive.rb +25 -0
  73. data/lib/walrus/walrus_grammar/super_directive.rb +27 -0
  74. data/lib/walrus.rb +64 -0
  75. data/spec/acceptance/acceptance_spec.rb +97 -0
  76. data/spec/acceptance/block/basic_block.expected +1 -0
  77. data/spec/acceptance/block/basic_block.tmpl +3 -0
  78. data/spec/acceptance/block/nested_blocks.expected +5 -0
  79. data/spec/acceptance/block/nested_blocks.tmpl +11 -0
  80. data/spec/acceptance/comments/comments_and_text.expected +3 -0
  81. data/spec/acceptance/comments/comments_and_text.tmpl +6 -0
  82. data/spec/acceptance/comments/single_comment.expected +0 -0
  83. data/spec/acceptance/comments/single_comment.tmpl +1 -0
  84. data/spec/acceptance/def/alternative_def_calling_conventions.expected +3 -0
  85. data/spec/acceptance/def/alternative_def_calling_conventions.tmpl +18 -0
  86. data/spec/acceptance/def/basic_def_block_no_output.expected +0 -0
  87. data/spec/acceptance/def/basic_def_block_no_output.tmpl +17 -0
  88. data/spec/acceptance/def/defs_can_be_called_multiple_times.expected +3 -0
  89. data/spec/acceptance/def/defs_can_be_called_multiple_times.tmpl +6 -0
  90. data/spec/acceptance/def/defs_can_be_dynamic.expected +4 -0
  91. data/spec/acceptance/def/defs_can_be_dynamic.tmpl +12 -0
  92. data/spec/acceptance/echo/echo_directive_with_numeric_literal.expected +1 -0
  93. data/spec/acceptance/echo/echo_directive_with_numeric_literal.tmpl +1 -0
  94. data/spec/acceptance/echo/echo_expression_list.expected +1 -0
  95. data/spec/acceptance/echo/echo_expression_list.tmpl +1 -0
  96. data/spec/acceptance/echo/echo_short_notation.expected +1 -0
  97. data/spec/acceptance/echo/echo_short_notation.tmpl +1 -0
  98. data/spec/acceptance/echo/echo_simple_expression.expected +1 -0
  99. data/spec/acceptance/echo/echo_simple_expression.tmpl +1 -0
  100. data/spec/acceptance/echo/echo_single_quoted_string_literal.expected +1 -0
  101. data/spec/acceptance/echo/echo_single_quoted_string_literal.tmpl +1 -0
  102. data/spec/acceptance/echo/multiple_echo_statements.expected +1 -0
  103. data/spec/acceptance/echo/multiple_echo_statements.tmpl +2 -0
  104. data/spec/acceptance/includes/basic_included_file.txt +1 -0
  105. data/spec/acceptance/includes/basic_includer.complex +3 -0
  106. data/spec/acceptance/includes/basic_includer.expected +3 -0
  107. data/spec/acceptance/includes/basic_includer.rb +38 -0
  108. data/spec/acceptance/includes/complicated_included_file.txt +3 -0
  109. data/spec/acceptance/includes/complicated_includer.complex +3 -0
  110. data/spec/acceptance/includes/complicated_includer.expected +3 -0
  111. data/spec/acceptance/includes/complicated_includer.rb +41 -0
  112. data/spec/acceptance/includes/nested_include_1.txt +3 -0
  113. data/spec/acceptance/includes/nested_include_2.txt +1 -0
  114. data/spec/acceptance/includes/nested_includer.complex +3 -0
  115. data/spec/acceptance/includes/nested_includer.expected +4 -0
  116. data/spec/acceptance/includes/nested_includer.rb +41 -0
  117. data/spec/acceptance/inheritance/basic_child.complex +10 -0
  118. data/spec/acceptance/inheritance/basic_child.expected +9 -0
  119. data/spec/acceptance/inheritance/basic_child.rb +54 -0
  120. data/spec/acceptance/inheritance/basic_parent.complex +5 -0
  121. data/spec/acceptance/inheritance/basic_parent.expected +3 -0
  122. data/spec/acceptance/inheritance/basic_parent.rb +41 -0
  123. data/spec/acceptance/inheritance/importing_child.complex +8 -0
  124. data/spec/acceptance/inheritance/importing_child.expected +7 -0
  125. data/spec/acceptance/inheritance/importing_child.rb +46 -0
  126. data/spec/acceptance/inheritance/subdirectory/importing_child_in_subdirectory.complex +8 -0
  127. data/spec/acceptance/inheritance/subdirectory/importing_child_in_subdirectory.expected +7 -0
  128. data/spec/acceptance/inheritance/subdirectory/importing_child_in_subdirectory.rb +44 -0
  129. data/spec/acceptance/multiline_comments/multiline_comment_with_directives_inside.expected +0 -0
  130. data/spec/acceptance/multiline_comments/multiline_comment_with_directives_inside.tmpl +15 -0
  131. data/spec/acceptance/multiline_comments/simple_multiline_comment.expected +2 -0
  132. data/spec/acceptance/multiline_comments/simple_multiline_comment.tmpl +4 -0
  133. data/spec/acceptance/raw/complicated_raw_example.expected +57 -0
  134. data/spec/acceptance/raw/complicated_raw_example.tmpl +79 -0
  135. data/spec/acceptance/raw-text/UTF_8.expected +12 -0
  136. data/spec/acceptance/raw-text/UTF_8.tmpl +12 -0
  137. data/spec/acceptance/raw-text/empty_file.expected +0 -0
  138. data/spec/acceptance/raw-text/empty_file.tmpl +0 -0
  139. data/spec/acceptance/raw-text/multi_line.expected +4 -0
  140. data/spec/acceptance/raw-text/multi_line.tmpl +4 -0
  141. data/spec/acceptance/raw-text/single_line.expected +1 -0
  142. data/spec/acceptance/raw-text/single_line.tmpl +1 -0
  143. data/spec/acceptance/raw-text/single_line_whitespace.expected +1 -0
  144. data/spec/acceptance/raw-text/single_line_whitespace.tmpl +1 -0
  145. data/spec/acceptance/ruby/ruby_directive_is_just_like_silent.expected +1 -0
  146. data/spec/acceptance/ruby/ruby_directive_is_just_like_silent.tmpl +4 -0
  147. data/spec/acceptance/ruby/ruby_directive_using_here_doc.expected +1 -0
  148. data/spec/acceptance/ruby/ruby_directive_using_here_doc.tmpl +4 -0
  149. data/spec/acceptance/ruby/ruby_directive_using_here_doc_alt_syntax.expected +1 -0
  150. data/spec/acceptance/ruby/ruby_directive_using_here_doc_alt_syntax.tmpl +4 -0
  151. data/spec/acceptance/ruby/ruby_directive_with_accumulate.expected +1 -0
  152. data/spec/acceptance/ruby/ruby_directive_with_accumulate.tmpl +4 -0
  153. data/spec/acceptance/ruby/ruby_directive_with_accumulate_and_block.expected +1 -0
  154. data/spec/acceptance/ruby/ruby_directive_with_accumulate_and_block.tmpl +6 -0
  155. data/spec/acceptance/set/unused_set.expected +0 -0
  156. data/spec/acceptance/set/unused_set.tmpl +1 -0
  157. data/spec/acceptance/set/used_set.expected +1 -0
  158. data/spec/acceptance/set/used_set.tmpl +2 -0
  159. data/spec/acceptance/silent/silent_and_echo_combined.expected +1 -0
  160. data/spec/acceptance/silent/silent_and_echo_combined.tmpl +2 -0
  161. data/spec/acceptance/silent/silent_short_notation.expected +1 -0
  162. data/spec/acceptance/silent/silent_short_notation.tmpl +1 -0
  163. data/spec/acceptance/silent/simple_silent_directive.expected +0 -0
  164. data/spec/acceptance/silent/simple_silent_directive.tmpl +1 -0
  165. data/spec/acceptance/slurp/basic_slurp_demo.expected +1 -0
  166. data/spec/acceptance/slurp/basic_slurp_demo.tmpl +4 -0
  167. data/spec/acceptance/super/super_with_no_effect.expected +4 -0
  168. data/spec/acceptance/super/super_with_no_effect.tmpl +5 -0
  169. data/spec/additions/module_spec.rb +126 -0
  170. data/spec/additions/string_spec.rb +99 -0
  171. data/spec/compiler_spec.rb +55 -0
  172. data/spec/grammar/additions/proc_spec.rb +25 -0
  173. data/spec/grammar/additions/regexp_spec.rb +37 -0
  174. data/spec/grammar/additions/string_spec.rb +106 -0
  175. data/spec/grammar/and_predicate_spec.rb +29 -0
  176. data/spec/grammar/continuation_wrapper_exception_spec.rb +23 -0
  177. data/spec/grammar/match_data_wrapper_spec.rb +41 -0
  178. data/spec/grammar/memoizing_cache_spec.rb +112 -0
  179. data/spec/grammar/node_spec.rb +126 -0
  180. data/spec/grammar/not_predicate_spec.rb +29 -0
  181. data/spec/grammar/parser_state_spec.rb +172 -0
  182. data/spec/grammar/parslet_choice_spec.rb +49 -0
  183. data/spec/grammar/parslet_combining_spec.rb +287 -0
  184. data/spec/grammar/parslet_merge_spec.rb +33 -0
  185. data/spec/grammar/parslet_omission_spec.rb +58 -0
  186. data/spec/grammar/parslet_repetition_spec.rb +77 -0
  187. data/spec/grammar/parslet_sequence_spec.rb +49 -0
  188. data/spec/grammar/parslet_spec.rb +23 -0
  189. data/spec/grammar/predicate_spec.rb +53 -0
  190. data/spec/grammar/proc_parslet_spec.rb +52 -0
  191. data/spec/grammar/regexp_parslet_spec.rb +347 -0
  192. data/spec/grammar/string_enumerator_spec.rb +94 -0
  193. data/spec/grammar/string_parslet_spec.rb +143 -0
  194. data/spec/grammar/symbol_parslet_spec.rb +30 -0
  195. data/spec/grammar_spec.rb +545 -0
  196. data/spec/parser_spec.rb +1418 -0
  197. data/spec/spec_helper.rb +34 -0
  198. data/spec/walrus_grammar/comment_spec.rb +39 -0
  199. data/spec/walrus_grammar/echo_directive_spec.rb +63 -0
  200. data/spec/walrus_grammar/escape_sequence_spec.rb +85 -0
  201. data/spec/walrus_grammar/literal_spec.rb +41 -0
  202. data/spec/walrus_grammar/message_expression_spec.rb +37 -0
  203. data/spec/walrus_grammar/multiline_comment_spec.rb +58 -0
  204. data/spec/walrus_grammar/placeholder_spec.rb +48 -0
  205. data/spec/walrus_grammar/raw_directive_spec.rb +81 -0
  206. data/spec/walrus_grammar/raw_text_spec.rb +65 -0
  207. data/spec/walrus_grammar/silent_directive_spec.rb +34 -0
  208. metadata +291 -0
@@ -0,0 +1,34 @@
1
+ # Copyright 2007 Wincent Colaiuta
2
+ # This program is distributed in the hope that it will be useful, but WITHOUT
3
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
+ # in the accompanying file, "LICENSE.txt", for more details.
6
+ #
7
+ # $Id$
8
+
9
+ # Individual spec files that require this helper file can be run individually from the commandline.
10
+
11
+ require 'pathname'
12
+ require 'rubygems'
13
+ require 'spec'
14
+
15
+ module Walrus
16
+ module SpecHelper
17
+
18
+ if not const_defined? "LIBDIR"
19
+ # will append the local "lib" and "ext" directories to search path if not already present
20
+ base = File.join(File.dirname(__FILE__), '..')
21
+ LIBDIR = Pathname.new(File.join(base, 'lib')).realpath
22
+ EXTDIR = Pathname.new(File.join(base, 'ext')).realpath
23
+ TOOL = Pathname.new(File.join(base, 'bin', 'walrus')).realpath
24
+ # normalize all paths in the load path (use "rescue" because "realpath" will raise if lstat(2) fails for the path: non-existent paths, relative paths etc)
25
+ normalized = $:.collect { |path| Pathname.new(path).realpath rescue path }
26
+
27
+ # only add the directories if they do not appear to be present already
28
+ [LIBDIR, EXTDIR].each { |path| $:.push(path) unless normalized.include?(path) }
29
+ end
30
+
31
+ end # module SpecHelper
32
+ end # module Walrus
33
+
34
+ require 'walrus'
@@ -0,0 +1,39 @@
1
+ # Copyright 2007 Wincent Colaiuta
2
+ # This program is distributed in the hope that it will be useful, but WITHOUT
3
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
+ # in the accompanying file, "LICENSE.txt", for more details.
6
+ #
7
+ # $Id: /mirrors/Walrus/trunk/walrus/spec/walrus_grammar/comment_spec.rb 6720 2007-04-10T15:33:38.497892Z wincent $
8
+
9
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
10
+ require 'walrus/parser' # ensure that WalrusGrammar is defined before continuing
11
+
12
+ module Walrus
13
+ class WalrusGrammar
14
+
15
+ describe 'compiling a comment instance' do
16
+
17
+ it 'comments should produce no meaningful output' do
18
+ eval(Comment.new(' hello world').compile).should == nil
19
+ end
20
+
21
+ end
22
+
23
+ describe 'producing a Document containing Comment' do
24
+
25
+ setup do
26
+ @parser = Parser.new
27
+ end
28
+
29
+ it 'should produce no output' do
30
+ comment = @parser.compile('## hello world', :class_name => :CommentSpec)
31
+ self.class.class_eval(comment)
32
+ self.class::Walrus::WalrusGrammar::CommentSpec.new.fill.should == ''
33
+ end
34
+
35
+ end
36
+
37
+ end # class WalrusGrammar
38
+ end # module Walrus
39
+
@@ -0,0 +1,63 @@
1
+ # Copyright 2007 Wincent Colaiuta
2
+ # This program is distributed in the hope that it will be useful, but WITHOUT
3
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
+ # in the accompanying file, "LICENSE.txt", for more details.
6
+ #
7
+ # $Id: /mirrors/Walrus/trunk/walrus/spec/walrus_grammar/echo_directive_spec.rb 6720 2007-04-10T15:33:38.497892Z wincent $
8
+
9
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
10
+ require 'walrus/parser' # ensure that WalrusGrammar is defined before continuing
11
+
12
+ module Walrus
13
+ class WalrusGrammar
14
+
15
+ class EchoDirectiveAccumulator
16
+ attr_reader :content
17
+ def initialize
18
+ @content = ''
19
+ end
20
+ def accumulate(string)
21
+ @content << string
22
+ end
23
+ end
24
+
25
+ describe 'compiling an EchoDirective instance' do
26
+
27
+ it 'should be able to round trip' do
28
+ string = StringResult.new('hello world')
29
+ string.source_text = "'hello world'"
30
+ @accumulator = EchoDirectiveAccumulator.new
31
+ @accumulator.instance_eval(EchoDirective.new(SingleQuotedStringLiteral.new(string)).compile)
32
+ @accumulator.content.should == 'hello world'
33
+ end
34
+
35
+ # regression test for inputs that previously raised
36
+ it 'should be able to recognize the short form' do
37
+ @parser = Parser.new
38
+ lambda { @parser.parse('#= Walrus::VERSION #') }.should_not raise_error
39
+ lambda { @parser.parse('<meta name="generator" content="Walrus #= Walrus::VERSION #">') }.should_not raise_error
40
+ end
41
+
42
+ end
43
+
44
+ describe 'producing a Document containing an EchoDirective' do
45
+
46
+ setup do
47
+ @parser = Parser.new
48
+ end
49
+
50
+ it 'should be able to round trip' do
51
+
52
+ # simple example
53
+ compiled = @parser.compile("#echo 'foo'", :class_name => :EchoDirectiveSpecAlpha)
54
+ self.class.class_eval(compiled)
55
+ self.class::Walrus::WalrusGrammar::EchoDirectiveSpecAlpha.new.fill.should == 'foo'
56
+
57
+ end
58
+
59
+ end
60
+
61
+ end # class WalrusGrammar
62
+ end # module Walrus
63
+
@@ -0,0 +1,85 @@
1
+ # Copyright 2007 Wincent Colaiuta
2
+ # This program is distributed in the hope that it will be useful, but WITHOUT
3
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
+ # in the accompanying file, "LICENSE.txt", for more details.
6
+ #
7
+ # $Id: /mirrors/Walrus/trunk/walrus/spec/walrus_grammar/escape_sequence_spec.rb 6720 2007-04-10T15:33:38.497892Z wincent $
8
+
9
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
10
+ require 'walrus/parser' # ensure that WalrusGrammar is defined before continuing
11
+
12
+ module Walrus
13
+ class WalrusGrammar
14
+
15
+ class EscapeSequenceAccumulator
16
+ attr_reader :content
17
+ def initialize
18
+ @content = ''
19
+ end
20
+ def accumulate(string)
21
+ @content << string
22
+ end
23
+ end
24
+
25
+ describe 'compiling an EscapeSequence instance' do
26
+
27
+ setup do
28
+ @accumulator = EscapeSequenceAccumulator.new
29
+ end
30
+
31
+ it 'should be able to round trip ($)' do
32
+ sequence = EscapeSequence.new('$')
33
+ @accumulator.instance_eval(sequence.compile)
34
+ @accumulator.content.should == '$'
35
+ end
36
+
37
+ it 'should be able to round trip (#)' do
38
+ sequence = EscapeSequence.new('#')
39
+ @accumulator.instance_eval(sequence.compile)
40
+ @accumulator.content.should == '#'
41
+ end
42
+
43
+ it 'should be able to round trip (\\)' do
44
+ sequence = EscapeSequence.new('\\')
45
+ @accumulator.instance_eval(sequence.compile)
46
+ @accumulator.content.should == '\\'
47
+ end
48
+
49
+ end
50
+
51
+ describe 'producing a Document containing an EscapeSequence' do
52
+
53
+ setup do
54
+ @parser = Parser.new
55
+ end
56
+
57
+ it 'should be able to round trip' do
58
+
59
+ # single $
60
+ sequence = @parser.compile('\\$', :class_name => :EscapeSequenceSpecAlpha)
61
+ self.class.class_eval(sequence)
62
+ self.class::Walrus::WalrusGrammar::EscapeSequenceSpecAlpha.new.fill.should == '$'
63
+
64
+ # single #
65
+ sequence = @parser.compile('\\#', :class_name => :EscapeSequenceSpecBeta)
66
+ self.class.class_eval(sequence)
67
+ self.class::Walrus::WalrusGrammar::EscapeSequenceSpecBeta.new.fill.should == '#'
68
+
69
+ # single \
70
+ sequence = @parser.compile('\\\\', :class_name => :EscapeSequenceSpecDelta)
71
+ self.class.class_eval(sequence)
72
+ self.class::Walrus::WalrusGrammar::EscapeSequenceSpecDelta.new.fill.should == '\\'
73
+
74
+ # multiple escape markers
75
+ sequence = @parser.compile('\\\\\\#\\$', :class_name => :EscapeSequenceSpecGamma)
76
+ self.class.class_eval(sequence)
77
+ self.class::Walrus::WalrusGrammar::EscapeSequenceSpecGamma.new.fill.should == '\\#$'
78
+
79
+ end
80
+
81
+ end
82
+
83
+ end # class WalrusGrammar
84
+ end # module Walrus
85
+
@@ -0,0 +1,41 @@
1
+ # Copyright 2007 Wincent Colaiuta
2
+ # This program is distributed in the hope that it will be useful, but WITHOUT
3
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
+ # in the accompanying file, "LICENSE.txt", for more details.
6
+ #
7
+ # $Id: /mirrors/Walrus/trunk/walrus/spec/walrus_grammar/literal_spec.rb 6702 2007-04-09T15:04:40.448669Z wincent $
8
+
9
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
10
+ require 'walrus/parser' # ensure that WalrusGrammar is defined before continuing
11
+
12
+ module Walrus
13
+ class WalrusGrammar
14
+
15
+ describe 'compiling a double-quoted string literal instance' do
16
+
17
+ it 'should produce a string literal' do
18
+ string = StringResult.new('hello world') # construct the string result the same way the parser does
19
+ string.source_text = '"hello world"' # the original source text includes the quotes
20
+ compiled = DoubleQuotedStringLiteral.new(string).compile # but the inner lexeme is just the contents
21
+ compiled.should == '"hello world"'
22
+ eval(compiled).should == 'hello world'
23
+ end
24
+
25
+ end
26
+
27
+ describe 'compiling a single-quoted string literal instance' do
28
+
29
+ it 'should produce a string literal' do
30
+ string = StringResult.new('hello world') # construct the string result the same way the parser does
31
+ string.source_text = "'hello world'" # the original source text includes the quotes
32
+ compiled = SingleQuotedStringLiteral.new(string).compile # but the inner lexeme is just the contents
33
+ compiled.should == "'hello world'"
34
+ eval(compiled).should == 'hello world'
35
+ end
36
+
37
+ end
38
+
39
+ end # class WalrusGrammar
40
+ end # module Walrus
41
+
@@ -0,0 +1,37 @@
1
+ # Copyright 2007 Wincent Colaiuta
2
+ # This program is distributed in the hope that it will be useful, but WITHOUT
3
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
+ # in the accompanying file, "LICENSE.txt", for more details.
6
+ #
7
+ # $Id: /mirrors/Walrus/trunk/walrus/spec/walrus_grammar/message_expression_spec.rb 6704 2007-04-09T18:30:00.421185Z wincent $
8
+
9
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
10
+ require 'walrus/parser' # ensure that WalrusGrammar is defined before continuing
11
+
12
+ module Walrus
13
+ class WalrusGrammar
14
+
15
+ describe 'calling source_text on a message expression inside an echo directive' do
16
+
17
+ setup do
18
+ @parser = Parser.new
19
+ end
20
+
21
+ it 'should return the text of the expression only' do
22
+
23
+ directive = @parser.parse '#echo string.downcase'
24
+ directive.column_start.should == 0
25
+ directive.expression.target.column_start.should == 6
26
+ directive.expression.message.column_start.should == 13
27
+
28
+ # ideally we'd report 6 here, but there is no way for Walrus to know that we don't want to count the skipped whitespace
29
+ directive.expression.column_start.should == 5
30
+ directive.expression.source_text.should == ' string.downcase'
31
+
32
+ end
33
+ end
34
+
35
+ end # class WalrusGrammar
36
+ end # module Walrus
37
+
@@ -0,0 +1,58 @@
1
+ # Copyright 2007 Wincent Colaiuta
2
+ # This program is distributed in the hope that it will be useful, but WITHOUT
3
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
+ # in the accompanying file, "LICENSE.txt", for more details.
6
+ #
7
+ # $Id: /mirrors/Walrus/trunk/walrus/spec/walrus_grammar/multiline_comment_spec.rb 6720 2007-04-10T15:33:38.497892Z wincent $
8
+
9
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
10
+ require 'walrus/parser' # ensure that WalrusGrammar is defined before continuing
11
+
12
+ module Walrus
13
+
14
+ class WalrusGrammar
15
+
16
+ describe 'compiling a comment instance' do
17
+
18
+ it 'comments should produce no meaningful output' do
19
+ self.class.class_eval(MultilineComment.new(" hello\n world ").compile).should == nil
20
+ end
21
+
22
+ end
23
+
24
+ describe 'producing a Document containing Comment' do
25
+
26
+ setup do
27
+ @parser = Parser.new
28
+ end
29
+
30
+ it 'should produce no output' do
31
+
32
+ # simple multiline comment
33
+ comment = @parser.compile("#* hello\n world *#", :class_name => :MultilineCommentSpecAlpha)
34
+ self.class.class_eval(comment)
35
+ self.class::Walrus::WalrusGrammar::MultilineCommentSpecAlpha.new.fill.should == ''
36
+
37
+ # nested singleline comment
38
+ comment = @parser.compile("#* hello ## <-- first line\n world *#", :class_name => :MultilineCommentSpecBeta)
39
+ self.class.class_eval(comment)
40
+ self.class::Walrus::WalrusGrammar::MultilineCommentSpecBeta.new.fill.should == ''
41
+
42
+ # nested multiline comment
43
+ comment = @parser.compile("#* hello ## <-- first line\n world #* <-- second line *# *#", :class_name => :MultilineCommentSpecDelta)
44
+ self.class.class_eval(comment)
45
+ self.class::Walrus::WalrusGrammar::MultilineCommentSpecDelta.new.fill.should == ''
46
+
47
+ # multiple comments
48
+ comment = @parser.compile("#* hello *##* world *#", :class_name => :MultilineCommentSpecGamma)
49
+ self.class.class_eval(comment)
50
+ self.class::Walrus::WalrusGrammar::MultilineCommentSpecGamma.new.fill.should == ''
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end # class WalrusGrammar
57
+ end # module Walrus
58
+
@@ -0,0 +1,48 @@
1
+ # Copyright 2007 Wincent Colaiuta
2
+ # This program is distributed in the hope that it will be useful, but WITHOUT
3
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
+ # in the accompanying file, "LICENSE.txt", for more details.
6
+ #
7
+ # $Id: /mirrors/Walrus/trunk/walrus/spec/walrus_grammar/placeholder_spec.rb 6720 2007-04-10T15:33:38.497892Z wincent $
8
+
9
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
10
+ require 'walrus/parser' # ensure that WalrusGrammar is defined before continuing
11
+
12
+ module Walrus
13
+ class WalrusGrammar
14
+
15
+ describe 'a placeholder with no parameters' do
16
+
17
+ setup do
18
+ @parser = Parser.new
19
+ end
20
+
21
+ it 'should be substituted into the output' do
22
+ placeholder = @parser.compile("#set $foo = 'bar'\n$foo", :class_name => :PlaceholderSpecAlpha)
23
+ self.class.class_eval(placeholder)
24
+ self.class::Walrus::WalrusGrammar::PlaceholderSpecAlpha.new.fill.should == 'bar'
25
+ end
26
+
27
+ end
28
+
29
+ describe 'a placeholder that accepts one parameter' do
30
+
31
+ setup do
32
+ @parser = Parser.new
33
+ end
34
+
35
+ it 'should be substituted into the output' do
36
+ placeholder = @parser.compile( %q{#def foo(string)
37
+ #echo string.downcase
38
+ #end
39
+ $foo("HELLO WORLD")}, :class_name => :PlaceholderSpecBeta)
40
+ self.class.class_eval(placeholder)
41
+ self.class::Walrus::WalrusGrammar::PlaceholderSpecBeta.new.fill.should == "hello world"
42
+ end
43
+
44
+ end
45
+
46
+ end # class WalrusGrammar
47
+ end # module Walrus
48
+
@@ -0,0 +1,81 @@
1
+ # Copyright 2007 Wincent Colaiuta
2
+ # This program is distributed in the hope that it will be useful, but WITHOUT
3
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
+ # in the accompanying file, "LICENSE.txt", for more details.
6
+ #
7
+ # $Id: /mirrors/Walrus/trunk/walrus/spec/walrus_grammar/raw_directive_spec.rb 6720 2007-04-10T15:33:38.497892Z wincent $
8
+
9
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
10
+ require 'walrus/parser' # ensure that WalrusGrammar is defined before continuing
11
+
12
+ module Walrus
13
+ class WalrusGrammar
14
+
15
+ class RawDirectiveAccumulator
16
+ attr_reader :content
17
+ def initialize
18
+ @content = ''
19
+ end
20
+ def accumulate(string)
21
+ @content << string
22
+ end
23
+ end
24
+
25
+ describe 'compiling a RawDirective instance' do
26
+
27
+ it 'should be able to round trip' do
28
+ @accumulator = RawDirectiveAccumulator.new
29
+ @raw = RawDirective.new('hello \'world\'\\... € #raw, $raw, \\raw')
30
+ @accumulator.instance_eval(@raw.compile)
31
+ @accumulator.content.should == 'hello \'world\'\\... € #raw, $raw, \\raw'
32
+ end
33
+
34
+ end
35
+
36
+ describe 'producing a Document containing RawText' do
37
+
38
+ setup do
39
+ @parser = Parser.new
40
+ end
41
+
42
+ it 'should be able to round trip' do
43
+
44
+ # simple example
45
+ raw = @parser.compile("#raw\nhello world\n#end", :class_name => :RawDirectiveSpecAlpha)
46
+ self.class.class_eval(raw)
47
+ self.class::Walrus::WalrusGrammar::RawDirectiveSpecAlpha.new.fill.should == "hello world\n"
48
+
49
+ # containing single quotes
50
+ raw = @parser.compile("#raw\nhello 'world'\n#end", :class_name => :RawDirectiveSpecBeta)
51
+ self.class.class_eval(raw)
52
+ self.class::Walrus::WalrusGrammar::RawDirectiveSpecBeta.new.fill.should == "hello 'world'\n"
53
+
54
+ # containing a newline
55
+ raw = @parser.compile("#raw\nhello\nworld\n#end", :class_name => :RawDirectiveSpecDelta)
56
+ self.class.class_eval(raw)
57
+ self.class::Walrus::WalrusGrammar::RawDirectiveSpecDelta.new.fill.should == "hello\nworld\n"
58
+
59
+ # using a "here document"
60
+ raw = @parser.compile("#raw <<HERE
61
+ hello world
62
+ literal #end with no effect
63
+ HERE", :class_name => :RawDirectiveSpecGamma)
64
+ self.class.class_eval(raw)
65
+ self.class::Walrus::WalrusGrammar::RawDirectiveSpecGamma.new.fill.should == "hello world\nliteral #end with no effect\n"
66
+
67
+ # "here document", alternative syntax
68
+ raw = @parser.compile("#raw <<-HERE
69
+ hello world
70
+ literal #end with no effect
71
+ HERE", :class_name => :RawDirectiveSpecIota)
72
+ self.class.class_eval(raw)
73
+ self.class::Walrus::WalrusGrammar::RawDirectiveSpecIota.new.fill.should == "hello world\nliteral #end with no effect\n"
74
+
75
+ end
76
+
77
+ end
78
+
79
+ end # class WalrusGrammar
80
+ end # module Walrus
81
+
@@ -0,0 +1,65 @@
1
+ # Copyright 2007 Wincent Colaiuta
2
+ # This program is distributed in the hope that it will be useful, but WITHOUT
3
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
+ # in the accompanying file, "LICENSE.txt", for more details.
6
+ #
7
+ # $Id: /mirrors/Walrus/trunk/walrus/spec/walrus_grammar/raw_text_spec.rb 6720 2007-04-10T15:33:38.497892Z wincent $
8
+
9
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
10
+ require 'walrus/parser' # ensure that WalrusGrammar is defined before continuing
11
+
12
+ module Walrus
13
+ class WalrusGrammar
14
+
15
+ class RawTextAccumulator
16
+ attr_reader :content
17
+ def initialize
18
+ @content = ''
19
+ end
20
+ def accumulate(string)
21
+ @content << string
22
+ end
23
+ end
24
+
25
+ describe 'compiling a RawText instance' do
26
+
27
+ it 'should be able to round trip' do
28
+ @accumulator = RawTextAccumulator.new
29
+ @raw_text = RawText.new('hello \'world\'\\... €')
30
+ @accumulator.instance_eval(@raw_text.compile)
31
+ @accumulator.content.should == 'hello \'world\'\\... €'
32
+ end
33
+
34
+ end
35
+
36
+ describe 'producing a Document containing RawText' do
37
+
38
+ setup do
39
+ @parser = Parser.new
40
+ end
41
+
42
+ it 'should be able to round trip' do
43
+
44
+ # simple example
45
+ raw_text = @parser.compile('hello world', :class_name => :RawTextSpecAlpha)
46
+ self.class.class_eval(raw_text)
47
+ self.class::Walrus::WalrusGrammar::RawTextSpecAlpha.new.fill.should == 'hello world'
48
+
49
+ # containing single quotes
50
+ raw_text = @parser.compile("hello 'world'", :class_name => :RawTextSpecBeta)
51
+ self.class.class_eval(raw_text)
52
+ self.class::Walrus::WalrusGrammar::RawTextSpecBeta.new.fill.should == "hello 'world'"
53
+
54
+ # containing a newline
55
+ raw_text = @parser.compile("hello\nworld", :class_name => :RawTextSpecDelta)
56
+ self.class.class_eval(raw_text)
57
+ self.class::Walrus::WalrusGrammar::RawTextSpecDelta.new.fill.should == "hello\nworld"
58
+
59
+ end
60
+
61
+ end
62
+
63
+ end # class WalrusGrammar
64
+ end # module Walrus
65
+
@@ -0,0 +1,34 @@
1
+ # Copyright 2007 Wincent Colaiuta
2
+ # This program is distributed in the hope that it will be useful, but WITHOUT
3
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
+ # in the accompanying file, "LICENSE.txt", for more details.
6
+ #
7
+ # $Id: /mirrors/Walrus/trunk/walrus/spec/walrus_grammar/silent_directive_spec.rb 6720 2007-04-10T15:33:38.497892Z wincent $
8
+
9
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
10
+ require 'walrus/parser' # ensure that WalrusGrammar is defined before continuing
11
+
12
+ module Walrus
13
+ class WalrusGrammar
14
+
15
+ describe 'producing a Document containing a SilentDirective' do
16
+
17
+ setup do
18
+ @parser = Parser.new
19
+ end
20
+
21
+ it 'should produce no output' do
22
+
23
+ # simple example
24
+ compiled = @parser.compile("#silent 'foo'", :class_name => :SilentDirectiveSpecAlpha)
25
+ self.class.class_eval(compiled)
26
+ self.class::Walrus::WalrusGrammar::SilentDirectiveSpecAlpha.new.fill.should == ''
27
+
28
+ end
29
+
30
+ end
31
+
32
+ end # class WalrusGrammar
33
+ end # module Walrus
34
+