rubymacros 0.1.5 → 0.1.6

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 +4 -0
  2. data/COPYING.LGPL +503 -158
  3. data/History.txt +115 -5
  4. data/Makefile +68 -0
  5. data/README.txt +29 -6
  6. data/TODO +1 -0
  7. data/bin/macroruby +69 -0
  8. data/example/__dir__.rb +18 -0
  9. data/example/__dir___wrap.rb +18 -0
  10. data/example/andand.rb +18 -0
  11. data/example/andand_wrap.rb +18 -0
  12. data/example/assert.rb +29 -8
  13. data/example/assert0.rb +11 -0
  14. data/example/assert0_wrap.rb +5 -0
  15. data/example/assert_does_nothing_when_disabled.rb +19 -0
  16. data/example/assert_wrap.rb +21 -0
  17. data/example/expected_output.txt +88 -0
  18. data/example/formless_macro.rb +123 -0
  19. data/example/formless_macro_wrap.rb +20 -0
  20. data/example/inline.rb +97 -0
  21. data/example/linenum.rb +19 -1
  22. data/example/linenum_user.rb +18 -0
  23. data/example/linenum_wrap.rb +18 -0
  24. data/example/loop.rb +18 -0
  25. data/example/loop_wrap.rb +18 -0
  26. data/example/meta.rb +25 -0
  27. data/example/meta_wrap.rb +20 -0
  28. data/example/nilresult.rb +26 -0
  29. data/example/nilresult_wrap.rb +21 -0
  30. data/example/pipeline.rb +37 -0
  31. data/example/rescuing.rb +33 -0
  32. data/example/rescuing_wrap.rb +21 -0
  33. data/example/role.rb +103 -0
  34. data/example/role_with_eval.rb +92 -0
  35. data/example/self_in_class.rb +27 -0
  36. data/example/separated_scope.rb +42 -0
  37. data/example/separated_scope_wrap.rb +20 -0
  38. data/example/simple.rb +18 -0
  39. data/example/simple_wrap.rb +18 -0
  40. data/example/unproc.rb +31 -0
  41. data/example/unproc_wrap.rb +21 -0
  42. data/example/unroll.rb +34 -0
  43. data/example/unroll_macros.rb +119 -0
  44. data/example/unroll_wrap.rb +22 -0
  45. data/example/with.rb +50 -7
  46. data/example/with_wrap.rb +19 -0
  47. data/lib/macro.rb +307 -72
  48. data/lib/macro/ReduceWithsFor_RedParse_RedParse__MacroMixin_RedParse__WithMacros_1_8.rb +18880 -0
  49. data/lib/macro/ReduceWithsFor_RedParse_RedParse__MacroMixin_RedParse__WithMacros_1_9.rb +19101 -0
  50. data/lib/macro/form.rb +136 -27
  51. data/lib/macro/node.rb +64 -0
  52. data/lib/macro/version.rb +2 -5
  53. data/lib/rubymacros.rb +19 -0
  54. data/lib/rubymacros/version.rb +23 -0
  55. data/lib/weakkeyhash.rb +18 -0
  56. data/rubymacros.gemspec +60 -0
  57. data/test/test_all.rb +27 -2
  58. data/test/test_examples.rb +91 -0
  59. data/test/test_expand.rb +56 -1
  60. data/test/test_form.rb +108 -10
  61. data/test/test_unroll.rb +120 -0
  62. metadata +93 -65
  63. data/Rakefile +0 -37
@@ -1,4 +1,114 @@
1
- === 0.1.5 / 2009-07-04
1
+ === 0.1.6 / 4apr2012
2
+ * Big things:
3
+ * allow macros to have receivers
4
+ * redparse coalescer: coalescer is faster!
5
+ * nothingness macros:
6
+ * macros that expand to nil should disappear entirely
7
+ * except expansion to nothing inside array literal; that makes a nil
8
+ * NopNode is only deleted in these cases, nilified otherwise:
9
+ * UndefNode,AssigneeList,ArrayLiteralNode,SequenceNode,ListInNode
10
+ * 2 new syntaces for form escapes
11
+ * Little things:
12
+ * allow macros to work in irb!
13
+ * error msgs from macros now mention original macro source file
14
+ * importing macro-specific lexer hacks from rubylexer
15
+ * moving my RedParse extensions into a module
16
+ * erase linenumbers of nodes interpolated into elsewhere in a parsetree
17
+ * put correct linenums in nodes inserted in macro expansion
18
+ * refine detection of unsupported varargs or block
19
+ * Reg::Formula objs are defanged when quoted
20
+ * other Reg objects are left untouched when quoted
21
+ * hacky node class that just wraps a string and unparses to it
22
+ * fixed warnings
23
+ * hacky: form escape (troublesome) level of quotitude error check disabled
24
+ * Experimental Changes:
25
+ * optional, experimental macro_expand of forms inline
26
+ * instead of the usual way: deep_copy of a entry from a pre-built table
27
+ * Forms and Form Escapes:
28
+ * added new keyword op: 'v', like unary caret, but very low precedence
29
+ * and make sure any inputs with the ident v in them get renamed
30
+ * added yet another syntax for form escapes, enclosed by <+ and +>
31
+ * support for the argument of a form escape (^) being a splat expr
32
+ * (^* is needed so 1 formesc can expand to multiple actual exprs)
33
+ * added rule for 'doubled parens'
34
+ * (where name of called method is in a form esc)
35
+ * fixed rule for forms to allow nothing between parens
36
+ * parens around form escapes in lhs is required right now
37
+ * Convenience Apis:
38
+ * allow 1st arg to Macro.eval to be a Node, was required to be a String
39
+ * added macro-like things for flow control directives (return, next, etc)
40
+ * methods for listing and deleting all macros in a module
41
+ * make array in the lexer parameter slot to constructor work
42
+ * MacroMixin module can be #extend'd to a parser after it's created
43
+ * in Macro.expand, input can now be an IO
44
+ * ListInNode[whatever] now works
45
+ * filename param to Macro.expand defaults to "(eval)" if not given
46
+ * renamed classes:
47
+ * renamed RedParseWithMacros class to RedParse::WithMacros
48
+ * renamed Macro::Macro_ParserMixin to RedParse::MacroMixin,
49
+ * always keeping old names as an aliases
50
+ * rubymacros.rb is an alias for macro.rb
51
+ * first pass at macroruby cmd-line interpreter
52
+ * like ruby but with macros autoenabled
53
+ * Serializing/Copying Objects: marshal unparse pretty_print inspect dup clone
54
+ * FormNode is now marshalable
55
+ * FormNode is now dup/clone-able
56
+ * make form escape in assign lhs unparse correctly (needs extra parens)
57
+ * don't panic if no rescues in MacroNode#unparse
58
+ * shortcut pretty printing of forms and form escapes (and ListInNodes)
59
+ * when we know it will just be evaled again
60
+ * pretty up the #inspect output for FormNode
61
+ * serialization of FormNode via #inspect works better
62
+ * Node Api:
63
+ * made alias names (#body and #text) for the contents of a form
64
+ * FormParameterNode renamed to FormEscapeNode
65
+ * made FormEscapeNode#body alias to #val (contents of form esc)
66
+ * in FormEscapeNode, prefer #body to #first as the name of the contents
67
+ * FormEscapeNode#initialize now takes just 1 arg (the expr to escape)
68
+ * tolerate plain array inside MetaClassNode
69
+ * FormNode's @parameters should be made into ListInNode
70
+ * Examples:
71
+ * added a new, more complete unroll implementation
72
+ * adding 1st pass at handling flow control for some unrolled loops
73
+ * make deep copies of s-exps duplicated by unroll,
74
+ * to ensure the tree doesn't become a dag
75
+ * improvements to inline
76
+ * hacky manual rebuild_transform on result of inline macro
77
+ * walk only part of inline result that contains user's original body
78
+ * don't stop walking inlined method body early
79
+ * inlined method params should be parenthesized as well as escaped
80
+ * improvements to with
81
+ * reimplemented to take a block instead
82
+ * an even fancier version uses xform_tree!,
83
+ * but that doesnt work yet, so its disabled
84
+ * improvements to assert
85
+ * improved wording of assert err msg in non-op case
86
+ * improved assert's detection of compare operators
87
+ * new example, simpified version of assert
88
+ * added another formless_macro implementation
89
+ * new example, simple forwarding to a method
90
+ * inspired by roger pack. not working right now
91
+ * added a bunch of examples
92
+ * Tests:
93
+ * define some more mutators of test data
94
+ * to check for problems with form escs, etc
95
+ * a test which verifies each example prints its expected output.
96
+ * delete existing macros before starting various tests
97
+ * skip form testcases for test data that are not legal ruby
98
+ * skipping some random selection of slower tests.
99
+ * add test/ directory to $: for ruby 1.9
100
+ * warn, not error on diff in just Node#offset after wrapping in a form
101
+ * tests of specific features:
102
+ * first pass at a test for the loop unroller
103
+ * testing form as receiver of method call seems to work more or less.
104
+ * test marshaling a particular form that's failing in ruby < 1.9.2
105
+ * test of escape from inner form
106
+ * fixed test of second formless macro to actually test the 2nd macro
107
+ * test macros that expand to nothing
108
+ * test form escape on assign lhs
109
+ * testing assertions work right when disabled as well.
110
+
111
+ === 0.1.5 / 4jul2009
2
112
  * 4 Major Enhancements:
3
113
  * all macros are now immediate, not delayed
4
114
  * macro calls can accept blocks
@@ -10,18 +120,18 @@
10
120
  * forms can now be catenated together with + in the obvious way
11
121
  * HashLiteralNode can be treated somewhat like a real hash, using #get
12
122
 
13
- === 0.1.4 / 2009-05-21
123
+ === 0.1.4 / 21may2009
14
124
  * 1 Major Enhancement:
15
125
  * line numbers are now preserved in preprocessed code;
16
126
  * backtraces should make more sense.
17
127
  * 1 Minor Enhancement:
18
128
  * updated to keep in sync with the latest RedParse api (sigh)
19
129
 
20
- === 0.1.3 / 2009-05-02
130
+ === 0.1.3 / 2may2009
21
131
  * 1 Minor Enhancement:
22
132
  * depend on redparse>=0.8.1, since 0.8.0 had a stupid permission problem
23
133
 
24
- === 0.1.2 / 2009-04-26
134
+ === 0.1.2 / 26apr2009
25
135
  * 7 Minor Enhancements
26
136
  * lots of nice comments added, thanks to Paul Brannan and Tatsuji Kawai
27
137
  * Paul fixed the weird rdoc failure too!
@@ -31,7 +141,7 @@
31
141
  * in test_form.rb, don't test deep_copy on nil forms
32
142
  * all files should be world-readable now
33
143
 
34
- === 0.1.0 / 2008-10-24
144
+ === 0.1.0 / 24oct2008
35
145
  * 1 Major Enhancement
36
146
  * Birthday!
37
147
 
@@ -0,0 +1,68 @@
1
+ # rubymacros - a macro preprocessor for ruby
2
+ # Copyright (C) 2008, 2016 Caleb Clausen
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU Lesser General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ name=RubyMacros
18
+ lname=rubymacros
19
+ gemname=rubymacros
20
+
21
+ lib/macro/ReduceWithsFor_RedParse_RedParse__MacroMixin_RedParse__WithMacros_1_8.rb: lib/macro.rb
22
+ redparse -r=lib/macro.rb --cache=no -o=lib/macro/ -c WithMacros
23
+
24
+ lib/macro/ReduceWithsFor_RedParse_RedParse__MacroMixin_RedParse__WithMacros_1_9.rb: lib/macro.rb
25
+ redparse -r=lib/macro.rb --cache=no -o=lib/macro/ -c 'WithMacros 1.9'
26
+
27
+ parser: lib/macro/ReduceWithsFor_RedParse_RedParse__MacroMixin_RedParse__WithMacros_1_8.rb lib/macro/ReduceWithsFor_RedParse_RedParse__MacroMixin_RedParse__WithMacros_1_9.rb
28
+ .PHONY: parser
29
+
30
+ #everything after this line is generic
31
+
32
+ version=$(shell ruby -r ./lib/$(lname)/version.rb -e "puts $(name)::VERSION")
33
+ filelist=$(shell git ls-files)
34
+
35
+ .PHONY: all test docs gem tar pkg email
36
+ all: test
37
+
38
+ test:
39
+ ruby -Ilib test/test_all.rb
40
+
41
+ docs:
42
+ rdoc lib/*
43
+
44
+ pkg: gem tar
45
+
46
+ gem:
47
+ gem build $(lname).gemspec
48
+
49
+ tar:
50
+ tar cf - $(filelist) | ( mkdir $(gemname)-$(version); cd $(gemname)-$(version); tar xf - )
51
+ tar czf $(gemname)-$(version).tar.gz $(gemname)-$(version)
52
+ rm -rf $(gemname)-$(version)
53
+
54
+ email: README.txt History.txt
55
+ ruby -e ' \
56
+ require "rubygems"; \
57
+ load "./$(lname).gemspec"; \
58
+ spec= Gem::Specification.list.find{|x| x.name=="$(gemname)"}; \
59
+ puts "\
60
+ Subject: [ANN] $(name) #{spec.version} Released \
61
+ \n\n$(name) version #{spec.version} has been released! \n\n\
62
+ #{Array(spec.homepage).map{|url| " * #{url}\n" }} \
63
+ \n\
64
+ #{$(name)::Description} \
65
+ \n\nChanges:\n\n \
66
+ #{$(name)::Latest_changes} \
67
+ "\
68
+ '
data/README.txt CHANGED
@@ -26,10 +26,6 @@ Although in theory already as powerful as lisp macros, the current
26
26
  implementation has a number of problems which added together make it merely
27
27
  a proof of concept or toy at this point:
28
28
  * pre-processing is very, very slow (because of RedParse)
29
- * macro calls must be inside some sort of method;
30
- * straight out macro calls at the top level won't work
31
- * macros can't have blocks or receivers
32
- * some ruby syntax is unsupported in files using macros
33
29
  * files using macros must be loaded via Macro.require;
34
30
  * Kernel#require will not recognize macros
35
31
  * macros cannot be scoped
@@ -77,7 +73,7 @@ result of an escaped expression (which should be a Node) is interpolated
77
73
  into the form at that point. The whole effect is much like that of string
78
74
  interpolations (#{}) inside string literals.
79
75
 
80
- == How Macros Work
76
+ == How Macros Work:
81
77
  Typically, macros return a single form literal, which contains form escape
82
78
  expressions within it which make use of the macro's parameters. However,
83
79
  macro bodies may contain anything at all; more complicated macros will
@@ -91,6 +87,33 @@ The parsetrees for the arguments to the callsite are passed as arguments to
91
87
  the macro. The macro is expected to return a parsetree, which replaces the
92
88
  macro callsite in the parsetree which contained it.
93
89
 
90
+ === How to use the examples:
91
+ All the example code in the example/ directory is split into 2 parts; the
92
+ actual example file itself (say, example/foo.rb) and a wrapper around it
93
+ (say, example/foo_wrap.rb) which requires 'macro' and then Macro.requires
94
+ the example itself. To run the examples, you should run the _wrap file, not
95
+ the example file itself. For example, to try out assert.rb, you would
96
+ issue this command line:
97
+ ruby example/assert_wrap.rb
98
+ The example wrappers all expect to be run from the main rubymacros
99
+ directory, not the example/ subdirectory.
100
+
101
+ I wish this 2-level scheme were not necessary, so that you could directly
102
+ execute a file containing macros, with perhaps a -rmacro preceding it on
103
+ the command line. However, it isn't possible to override how the interpreter
104
+ treats it command line arguments. I would hope that files named on the
105
+ command line (with or without a -r option) would be pulled in via
106
+ Kernel#require, but this is not the case.
107
+
108
+
109
+ == Hacker's guide (well, section)
110
+ If you modify the parse rules (that is, RedParse::MacroMixin#RULES) you will
111
+ need to recompile them before they will work. To do that, run 'make parser'.
112
+ This will, unfortunately, take a little while to run. Running 'make parser'
113
+ will regenerate two files:
114
+ lib/macro/ReduceWithsFor_RedParse_RedParse__MacroMixin_RedParse__WithMacros_1_8.rb
115
+ lib/macro/ReduceWithsFor_RedParse_RedParse__MacroMixin_RedParse__WithMacros_1_9.rb
116
+ which normally come pre-generated with rubymacros.
94
117
 
95
118
 
96
119
  == Known Problems
@@ -102,7 +125,7 @@ macro callsite in the parsetree which contained it.
102
125
 
103
126
 
104
127
  == License:
105
- Copyright (C) 2008 Caleb Clausen
128
+ Copyright (C) 2008, 2016 Caleb Clausen
106
129
 
107
130
  This program is free software: you can redistribute it and/or modify
108
131
  it under the terms of the GNU Lesser General Public License as published by
data/TODO CHANGED
@@ -3,6 +3,7 @@ macro options
3
3
  'protected' vs unprotected macros -- params and result surrounded by ()
4
4
  precedence for operator macros
5
5
  hygienic vs unhygienic
6
+ simple vs complete?
6
7
 
7
8
  need to insert extra parens around form params
8
9
  except only if it stands in for an rvalue...
@@ -0,0 +1,69 @@
1
+ =begin
2
+ rubymacros - a macro preprocessor for ruby
3
+ Copyright (C) 2008, 2016 Caleb Clausen
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ =end
18
+
19
+ #!/usr/bin/env ruby
20
+
21
+ prelude=['require "macro"']
22
+
23
+ i=0
24
+ while i<ARGV.size
25
+
26
+ #end of interpreter options?
27
+ break if /\A(?:[^-]|-?-\z)/===ARGV[i]
28
+
29
+ all,er,rest=ARGV[i].match /\A[Sacdhlnpsvwy]*([er])(.*)\z/
30
+
31
+ case er
32
+ when 'r' #input could come from file named w/ -r on cmd line
33
+ if !rest.empty?
34
+ prelude<<"Macro.require "+rest.inspect
35
+ else
36
+ ARGV[i]=nil
37
+ prelude<<"Macro.require "+ARGV[i+=1].inspect
38
+ end
39
+ ARGV[i]=nil
40
+
41
+ when 'e' #input could come from -e string on the cmd line
42
+ if !rest.empty?
43
+ prelude<<rest
44
+ else
45
+ ARGV[i]=nil
46
+ prelude<<ARGV[i+=1]
47
+ end
48
+ ARGV[i]=nil
49
+ got_e=true
50
+ end
51
+
52
+ i+=1
53
+ end
54
+
55
+ #input could come from stdin
56
+ if "-"==ARGV[i] or !ARGV[i]
57
+ ARGV[i]="-"
58
+ else
59
+ prelude<<"Macro.load "+ARGV[i].inspect
60
+ ARGV[i]=nil
61
+ end unless got_e
62
+
63
+ ARGV.compact!
64
+
65
+ ARGV.push "-e", prelude.join('; ')
66
+
67
+ p ARGV
68
+ ruby=RbConfig::CONFIG['bindir']+'/'+RbConfig::CONFIG["ruby_install_name"]
69
+ #exec ruby,*ARGV #does not return
@@ -1,3 +1,21 @@
1
+ =begin
2
+ rubymacros - a macro preprocessor for ruby
3
+ Copyright (C) 2008, 2016 Caleb Clausen
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ =end
18
+
1
19
  macro __DIR__
2
20
  :(File.dirname(__FILE__))
3
21
  end
@@ -1,3 +1,21 @@
1
+ =begin
2
+ rubymacros - a macro preprocessor for ruby
3
+ Copyright (C) 2008, 2016 Caleb Clausen
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ =end
18
+
1
19
  require 'macro'
2
20
  Macro.require 'example/__dir__.rb'
3
21
 
@@ -1,3 +1,21 @@
1
+ =begin
2
+ rubymacros - a macro preprocessor for ruby
3
+ Copyright (C) 2008, 2016 Caleb Clausen
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ =end
18
+
1
19
  macro andand(a,b)
2
20
  :(^a and ^b)
3
21
  end
@@ -1,2 +1,20 @@
1
+ =begin
2
+ rubymacros - a macro preprocessor for ruby
3
+ Copyright (C) 2008, 2016 Caleb Clausen
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ =end
18
+
1
19
  require "macro"
2
20
  Macro.require "example/andand"
@@ -1,12 +1,32 @@
1
+ =begin
2
+ rubymacros - a macro preprocessor for ruby
3
+ Copyright (C) 2008, 2016 Caleb Clausen
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ =end
18
+
1
19
  #this file uses macros! won't parse in normal ruby
2
20
  macro assert(cond)
3
21
  if $Debug
4
- if RedParse::OpNode===cond and /\A[=!]=\Z/===cond.op
5
- left,op,right=*cond
22
+ if RedParse::OpNode===cond and
23
+ /\A(?:[=!][=~]|[<>]=?|===)\Z/===cond.op
24
+ #left,op,right=*cond
25
+ left=cond.left; op=cond.op; right=cond.right
6
26
  :(fail 'expected '+^left.unparse+"(==#{^left}) to be "+
7
27
  ^op+" "+^right.unparse+"(==#{^right})" unless ^cond)
8
28
  else
9
- :(fail "expected #{:(^^cond)}, but was not true" unless ^cond)
29
+ :(fail "I expected that #{:(^^cond)}" unless ^cond)
10
30
  end
11
31
  end
12
32
  end
@@ -25,14 +45,15 @@ def test_assert
25
45
  assert(a==b) #oops, fails. msg="expected a(==1) to be == b(==2)"
26
46
  rescue Exception=>e
27
47
  assert("expected a(==1) to be == b(==2)"== e.message) #better be ok
28
- else puts "exception expected but was not seen"
48
+ else fail "exception expected but was not seen"
29
49
  end
30
50
 
31
51
  begin
32
- assert(nil) #oops, fails. msg="expected nil, but was not true"
52
+ assert(!a) #oops, fails. msg="expected nil, but was not true"
33
53
  rescue Exception=>e
34
- assert("expected nil, but was not true"== e.message) #better be ok
35
- #ok, that message didn't make a lot of sense...
36
- else puts "exception expected but was not seen"
54
+ assert(/^I expected that ! *a$/=== e.message) #better be ok
55
+ else fail "exception expected but was not seen"
37
56
  end
57
+
58
+ puts "all assertions passed"
38
59
  end