rubymacros 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ =begin
2
+ rubymacros - a macro preprocessor for ruby
3
+ Copyright (C) 2008 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
+
20
+ require 'test/unit'
21
+ require "macro"
22
+ class ExpandTest < Test::Unit::TestCase
23
+ def test_simple_expand
24
+ Macro.eval "macro simple(a,b) :(^a+^b) end"
25
+ ttt=RedParse::CallNode[nil, "p", [RedParse::CallNode[nil, "simple", [RedParse::LiteralNode[1],
26
+ RedParse::LiteralNode[2]], nil, nil]], nil, nil]
27
+ ttt.macro_expand(Macro::GLOBALS,{})
28
+
29
+ assert_equal ttt.unparse({}),'p(1+2)'
30
+
31
+ ttt=Macro.parse "p(simple(1,2))"
32
+ ttt.macro_expand(Macro::GLOBALS,{})
33
+ assert_equal ttt.unparse({}),'p(1+2)'
34
+ end
35
+ end
data/test/test_form.rb ADDED
@@ -0,0 +1,110 @@
1
+ =begin
2
+ rubymacros - a macro preprocessor for ruby
3
+ Copyright (C) 2008 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
+
20
+ require "macro"
21
+ require 'test/unit'
22
+ require 'rubygems'
23
+ require 'rubylexer'
24
+ require "test/code/testcases" #from rubylexer
25
+ require 'pp'
26
+
27
+
28
+ class FormTest< Test::Unit::TestCase
29
+ EXAMPLES=TestCases::TESTCASES
30
+
31
+ EXAMPLES.each_with_index{|x,i|
32
+ next if /__END__/===x
33
+ if / \^[^\s]/===x and x.size>1000
34
+ while x['^']
35
+ warn "disabling tests of '#{x[/^.*\^.*$/]}'"
36
+ x[/^.*\^.*$/]=''
37
+ end
38
+ next
39
+ end
40
+ define_method "test_case_#{i}" do
41
+ check x
42
+ end
43
+ }
44
+
45
+ def check(code)
46
+ begin
47
+ # puts code
48
+ begin as_form=Macro.eval(":(\n"+code+"\n)")
49
+ rescue Exception=>formexc
50
+ 0
51
+ end
52
+
53
+ begin
54
+ as_tree=RedParse.new(" \n"+code).parse
55
+ as_tree=RedParse::VarLikeNode["nil", {:@value=>false}] if RedParse::NopNode===as_tree
56
+ rescue Exception=>treeexc
57
+ 0
58
+ end
59
+
60
+ errs=[formexc,treeexc].compact
61
+ raise errs.first if errs.size==1
62
+
63
+ # as_form.delete_extraneous_ivars! if as_form
64
+ # as_tree.delete_extraneous_ivars! if as_tree
65
+
66
+ assert_equal as_tree, as_form
67
+
68
+ assert_equal as_form, as_form.deep_copy
69
+ end
70
+ end
71
+ end
72
+
73
+ class FormParameterTest< Test::Unit::TestCase
74
+ DATA=[
75
+ "1", "1.1", "nil", "false", "true",
76
+ ":sym", "[1,2,3]", "{'a'=>4,:b=>6}", "'s'",
77
+ ]
78
+ DIFFICULT_CHILDREN=[
79
+ "RedParse::ConstantNode[nil,'Object']","(a=[];a<<a)"
80
+ ]
81
+
82
+ def form_param_setup datum
83
+ $a=[]
84
+ $b=[]
85
+ Macro.eval(":($a.push(^#{datum}))").eval
86
+ datum=eval datum
87
+ end
88
+
89
+ def test_form_params
90
+ DATA.each{|datum|
91
+ datum=form_param_setup datum
92
+ $b.push datum
93
+
94
+ assert_equal( $b, $a)
95
+ }
96
+ end
97
+
98
+ def test_form_params_dc
99
+ DIFFICULT_CHILDREN.each{|datum|
100
+ datum=form_param_setup datum
101
+ if RedParse::Node===datum
102
+ $b.push datum.eval
103
+ else
104
+ $b.push datum
105
+ end
106
+
107
+ assert_equal( $b.inspect, $a.inspect) #byaah, not the best way....
108
+ }
109
+ end
110
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubymacros
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Caleb Clausen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-24 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: redparse
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.8.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.1
34
+ version:
35
+ description: Macros are programmed in ruby itself. And since parse trees are represented in RedParse format, they're easier to use (programatically) and more object-oriented than other available ruby parsetree formats. (RedParse Node format is actually designed to be straightforward to use and to represent the structure of ruby source code very closely.)
36
+ email: rubymacros-owner @at@ inforadical .dot. net
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - Manifest.txt
43
+ - README.txt
44
+ files:
45
+ - COPYING.LGPL
46
+ - Manifest.txt
47
+ - README.txt
48
+ - rubymacros.vpj
49
+ - Rakefile
50
+ - test/test_form.rb
51
+ - test/test_expand.rb
52
+ - lib/macro.rb
53
+ - lib/macro/form.rb
54
+ - lib/macro/version.rb
55
+ - example/andand.rb
56
+ - example/assert.rb
57
+ - example/assert_wrap.rb
58
+ - example/__dir__.rb
59
+ - example/__dir___wrap.rb
60
+ - example/loop.rb
61
+ - example/loop_wrap.rb
62
+ - example/simple.rb
63
+ - example/simple_wrap.rb
64
+ - example/with.rb
65
+ - example/with_wrap.rb
66
+ has_rdoc: true
67
+ homepage: http://rubymacros.rubyforge.org/
68
+ post_install_message:
69
+ rdoc_options:
70
+ - --main
71
+ - README.txt
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ requirements: []
87
+
88
+ rubyforge_project: rubymacros
89
+ rubygems_version: 1.3.0
90
+ signing_key:
91
+ specification_version: 2
92
+ summary: Macros are programmed in ruby itself.
93
+ test_files:
94
+ - test/test_all.rb