aaronp-zomg 1.0.2.20080827232412
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +25 -0
- data/Manifest.txt +238 -0
- data/README.txt +59 -0
- data/Rakefile +43 -0
- data/bin/omfg +56 -0
- data/lib/scanner.rex +169 -0
- data/lib/yacc.y +861 -0
- data/lib/zomg.rb +22 -0
- data/lib/zomg/idl.rb +14 -0
- data/lib/zomg/idl/nodes/attribute.rb +15 -0
- data/lib/zomg/idl/nodes/binary.rb +19 -0
- data/lib/zomg/idl/nodes/constant.rb +15 -0
- data/lib/zomg/idl/nodes/interface.rb +13 -0
- data/lib/zomg/idl/nodes/interface_header.rb +14 -0
- data/lib/zomg/idl/nodes/member.rb +14 -0
- data/lib/zomg/idl/nodes/node.rb +54 -0
- data/lib/zomg/idl/nodes/operation.rb +17 -0
- data/lib/zomg/idl/nodes/parameter.rb +18 -0
- data/lib/zomg/idl/nodes/typedef.rb +13 -0
- data/lib/zomg/idl/nodes/union.rb +14 -0
- data/lib/zomg/idl/parser.rb +54 -0
- data/lib/zomg/idl/visitable.rb +15 -0
- data/lib/zomg/idl/visitors/duhr.rb +24 -0
- data/lib/zomg/idl/visitors/ruby_sexp.rb +204 -0
- data/lib/zomg/idl/visitors/sexp.rb +274 -0
- data/lib/zomg/version.rb +3 -0
- data/test/assets/array/array1.idl +60 -0
- data/test/assets/array/array2.idl +38 -0
- data/test/assets/array/array3.idl +8 -0
- data/test/assets/array/array4.idl +7 -0
- data/test/assets/array/array5.idl +80 -0
- data/test/assets/attribute/grid_0attribs_2methods.idl +16 -0
- data/test/assets/attribute/grid_1ROattribs_1attribs_0methods.idl +19 -0
- data/test/assets/attribute/grid_1ROattribs_1attribs_1methods.idl +19 -0
- data/test/assets/attribute/grid_1ROattribs_1attribs_2methods.idl +17 -0
- data/test/assets/attribute/grid_1ROattribs_1methods.idl +16 -0
- data/test/assets/attribute/grid_1ROattribs_2methods.idl +16 -0
- data/test/assets/attribute/grid_1attribs_1methods.idl +17 -0
- data/test/assets/attribute/grid_1attribs_2methods.idl +17 -0
- data/test/assets/attribute/grid_2ROattribs_0methods.idl +16 -0
- data/test/assets/attribute/grid_2ROattribs_1methods.idl +16 -0
- data/test/assets/attribute/grid_2ROattribs_2methods.idl +16 -0
- data/test/assets/attribute/grid_2attribs_0methods.idl +19 -0
- data/test/assets/attribute/grid_2attribs_1methods.idl +19 -0
- data/test/assets/attribute/grid_2attribs_2methods.idl +19 -0
- data/test/assets/comment/c_style_comments.idl +63 -0
- data/test/assets/comment/comment1.idl +57 -0
- data/test/assets/comment/cpp_style_comments.idl +168 -0
- data/test/assets/comment/shortform.idl +0 -0
- data/test/assets/complex/TestCodeSets.idl +10 -0
- data/test/assets/complex/TestIntfContext.idl +13 -0
- data/test/assets/complex/TestIntfLongLong.idl +51 -0
- data/test/assets/complex/TestIntfWChar.idl +52 -0
- data/test/assets/complex/any1.idl +22 -0
- data/test/assets/complex/complex1.idl +495 -0
- data/test/assets/complex/complex2.idl +730 -0
- data/test/assets/complex/complex3.idl +181 -0
- data/test/assets/complex/complex4.idl +181 -0
- data/test/assets/complex/interop_wchar.idl +60 -0
- data/test/assets/constant/constant1.idl +37 -0
- data/test/assets/constant/constant2.idl +29 -0
- data/test/assets/constant/constant3.idl +50 -0
- data/test/assets/constant/constant4.idl +21 -0
- data/test/assets/constant/constant5.idl +65 -0
- data/test/assets/constant/constant6.idl +144 -0
- data/test/assets/constant/constant7.idl +30 -0
- data/test/assets/enum/enum1.idl +13 -0
- data/test/assets/exception/TestIntfExceptions.idl +69 -0
- data/test/assets/exception/TestIntfExceptionsExt_2_0.idl +34 -0
- data/test/assets/exception/TestIntfExceptionsExt_2_3.idl +24 -0
- data/test/assets/exception/ex1.idl +6 -0
- data/test/assets/exception/ex2.idl +18 -0
- data/test/assets/exception/ex3.idl +10 -0
- data/test/assets/exception/ex4.idl +20 -0
- data/test/assets/exception/sc.idl +0 -0
- data/test/assets/exception/simple1.idl +18 -0
- data/test/assets/exception/simple2.idl +25 -0
- data/test/assets/factory/factory1.idl +77 -0
- data/test/assets/factory/objref.idl +25 -0
- data/test/assets/forward/forward.idl +15 -0
- data/test/assets/forward/forward1.idl +13 -0
- data/test/assets/forward/fwd_incl1.idl +6 -0
- data/test/assets/forward/fwd_incl2.idl +7 -0
- data/test/assets/include/a.idl +23 -0
- data/test/assets/include/b.idl +16 -0
- data/test/assets/include/employee.idl +12 -0
- data/test/assets/include/include1.idl +10 -0
- data/test/assets/include/include2.idl +5 -0
- data/test/assets/include/manager.idl +10 -0
- data/test/assets/include/pragma.idl +41 -0
- data/test/assets/include/rookie.idl +13 -0
- data/test/assets/include/rookiemanager.idl +15 -0
- data/test/assets/include/sample.idl +58 -0
- data/test/assets/include/sample_incl.idl +406 -0
- data/test/assets/inherit/IDL1.idl +18 -0
- data/test/assets/inherit/IDL2.idl +18 -0
- data/test/assets/inherit/IDL3.idl +18 -0
- data/test/assets/inherit/IDL4.idl +17 -0
- data/test/assets/inherit/diamond_inheritance.idl +31 -0
- data/test/assets/inherit/inherit.idl +27 -0
- data/test/assets/limit/longidentifiers.idl +25 -0
- data/test/assets/limit/namelens.idl +26 -0
- data/test/assets/limit/tpztest.idl +21 -0
- data/test/assets/module/module1.idl +29 -0
- data/test/assets/module/module2.idl +34 -0
- data/test/assets/module/module3.idl +20 -0
- data/test/assets/module/module4.idl +15 -0
- data/test/assets/nested/nested1.idl +5 -0
- data/test/assets/nested/nested2.idl +11 -0
- data/test/assets/operations/Benchmark.idl +331 -0
- data/test/assets/operations/CCS.idl +82 -0
- data/test/assets/operations/TestIntf.idl +40 -0
- data/test/assets/operations/TestIntfBasic.idl +653 -0
- data/test/assets/operations/atomic.idl +40 -0
- data/test/assets/operations/dif2.idl +48 -0
- data/test/assets/operations/interface1.idl +16 -0
- data/test/assets/operations/parameters.idl +111 -0
- data/test/assets/operations/perf.idl +84 -0
- data/test/assets/operations/timer.idl +104 -0
- data/test/assets/preprocess/base_for_diamond_inheritance_with_macros.idl +17 -0
- data/test/assets/preprocess/basic_macro_marshalling.idl +54 -0
- data/test/assets/preprocess/diamond_inheritance_with_macros.idl +74 -0
- data/test/assets/preprocess/macro1.idl +52 -0
- data/test/assets/preprocess/preprocess1.idl +246 -0
- data/test/assets/preprocess/preprocess2.idl +3 -0
- data/test/assets/recursion/loop.idl +28 -0
- data/test/assets/recursion/recursion1.idl +47 -0
- data/test/assets/recursion/recursion2.idl +74 -0
- data/test/assets/scenarios/filestat.idl +69 -0
- data/test/assets/scenarios/gateway.idl +176 -0
- data/test/assets/scenarios/library.idl +20 -0
- data/test/assets/scenarios/phone.idl +24 -0
- data/test/assets/scenarios/ticketservice.idl +118 -0
- data/test/assets/scope/scope01.idl +58 -0
- data/test/assets/scope/scope02.idl +25 -0
- data/test/assets/scope/scope03.idl +22 -0
- data/test/assets/scope/scope04.idl +27 -0
- data/test/assets/scope/scope05.idl +30 -0
- data/test/assets/scope/scope06.idl +51 -0
- data/test/assets/scope/scope07.idl +20 -0
- data/test/assets/scope/scope08.idl +88 -0
- data/test/assets/scope/scope09.idl +21 -0
- data/test/assets/scope/scope10.idl +95 -0
- data/test/assets/scope/scope11.idl +62 -0
- data/test/assets/scope/scope12.idl +117 -0
- data/test/assets/scope/scope13.idl +117 -0
- data/test/assets/scope/scope14.idl +117 -0
- data/test/assets/scope/scope15.idl +117 -0
- data/test/assets/scope/scope16.idl +117 -0
- data/test/assets/scope/scope17.idl +117 -0
- data/test/assets/scope/scope18.idl +117 -0
- data/test/assets/scope/scope19.idl +117 -0
- data/test/assets/scope/scope20.idl +215 -0
- data/test/assets/scope/scope21.idl +215 -0
- data/test/assets/scope/scope22.idl +205 -0
- data/test/assets/scope/scope23.idl +261 -0
- data/test/assets/scope/scope24.idl +376 -0
- data/test/assets/scope/scope25.idl +266 -0
- data/test/assets/scope/scope26.idl +180 -0
- data/test/assets/scope/scope27.idl +184 -0
- data/test/assets/scope/scope28.idl +182 -0
- data/test/assets/scope/scope29.idl +182 -0
- data/test/assets/scope/scope30.idl +40 -0
- data/test/assets/scope/scope31.idl +33 -0
- data/test/assets/scope/scope32.idl +37 -0
- data/test/assets/scope/scope33.idl +50 -0
- data/test/assets/scope/scope34.idl +97 -0
- data/test/assets/scope/scope35.idl +72 -0
- data/test/assets/scope/scope36.idl +167 -0
- data/test/assets/scope/scope37.idl +57 -0
- data/test/assets/scope/scope38.idl +38 -0
- data/test/assets/scope/scope39.idl +38 -0
- data/test/assets/scope/scope40.idl +38 -0
- data/test/assets/scope/scope41.idl +24 -0
- data/test/assets/scope/scope42.idl +64 -0
- data/test/assets/scope/scope43.idl +66 -0
- data/test/assets/scope/scope44.idl +52 -0
- data/test/assets/sequence/sequence1.idl +24 -0
- data/test/assets/sequence/sequence2.idl +9 -0
- data/test/assets/simple/basictypes1.idl +80 -0
- data/test/assets/simple/basictypes2.idl +197 -0
- data/test/assets/simple/basictypes3.idl +23 -0
- data/test/assets/simple/basictypes4.idl +73 -0
- data/test/assets/simple/basictypes5.idl +29 -0
- data/test/assets/simple/basictypes6.idl +63 -0
- data/test/assets/simple/simple1.idl +45 -0
- data/test/assets/simple/simple2.idl +61 -0
- data/test/assets/simple/simple3.idl +36 -0
- data/test/assets/string/string1.idl +11 -0
- data/test/assets/string/string2.idl +29 -0
- data/test/assets/struct/struct1.idl +20 -0
- data/test/assets/struct/struct2.idl +21 -0
- data/test/assets/struct/struct3.idl +42 -0
- data/test/assets/struct/struct4.idl +57 -0
- data/test/assets/struct/struct5.idl +71 -0
- data/test/assets/typecode/orb.idl +0 -0
- data/test/assets/typecode/pseudo.idl +25 -0
- data/test/assets/typedef/shorthand_typedef_struct_insideIF.idl +17 -0
- data/test/assets/typedef/shorthand_typedef_struct_insideIF_noMO.idl +16 -0
- data/test/assets/typedef/shorthand_typedef_struct_insideMO.idl +17 -0
- data/test/assets/typedef/shorthand_typedef_struct_outsideMO.idl +17 -0
- data/test/assets/typedef/typedef1.idl +8 -0
- data/test/assets/typedef/typedef2.idl +22 -0
- data/test/assets/typedef/typedef_struct_insideIF.idl +18 -0
- data/test/assets/typedef/typedef_struct_insideMO.idl +18 -0
- data/test/assets/typedef/typedef_struct_outsideMO.idl +18 -0
- data/test/assets/union/union1.idl +31 -0
- data/test/assets/union/union2.idl +22 -0
- data/test/assets/union/union3.idl +26 -0
- data/test/conversions/test_attribute.rb +46 -0
- data/test/conversions/test_enum.rb +25 -0
- data/test/conversions/test_exception.rb +24 -0
- data/test/conversions/test_forward_declaration.rb +22 -0
- data/test/conversions/test_interface.rb +30 -0
- data/test/conversions/test_module.rb +24 -0
- data/test/conversions/test_struct.rb +25 -0
- data/test/conversions/test_typedef.rb +22 -0
- data/test/conversions/test_union.rb +27 -0
- data/test/conversions/test_value_box_dcl.rb +22 -0
- data/test/helper.rb +23 -0
- data/test/simple/test_basictypes1.rb +87 -0
- data/test/simple/test_basictypes2.rb +18 -0
- data/test/simple/test_basictypes3.rb +32 -0
- data/test/simple/test_basictypes4.rb +25 -0
- data/test/simple/test_basictypes5.rb +17 -0
- data/test/simple/test_basictypes6.rb +19 -0
- data/test/simple/test_simple1.rb +40 -0
- data/test/simple/test_simple2.rb +48 -0
- data/test/simple/test_simple3.rb +20 -0
- data/test/test_array.rb +22 -0
- data/test/test_assets.rb +33 -0
- data/test/test_complex.rb +17 -0
- data/test/test_node.rb +16 -0
- data/test/test_parser.rb +17 -0
- data/test/test_scanner.rb +234 -0
- metadata +334 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Simple1Test < ZOMG::Test
|
4
|
+
def setup
|
5
|
+
@tree = ZOMG::IDL::Parser.parse_file(simple('simple1.idl'))
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_parse_simple1
|
9
|
+
assert_instance_of(Specification, @tree)
|
10
|
+
assert_equal(1, @tree.children.length)
|
11
|
+
|
12
|
+
idl_module = @tree.children.first
|
13
|
+
assert_instance_of(Module, idl_module)
|
14
|
+
assert_equal('OneWaySimpleTest', idl_module.name)
|
15
|
+
|
16
|
+
assert_equal(1, idl_module.children.length)
|
17
|
+
idl_interface = idl_module.children.first
|
18
|
+
assert_instance_of(Interface, idl_interface)
|
19
|
+
assert_equal('sim1wcor', idl_interface.header.name)
|
20
|
+
|
21
|
+
assert_equal(1, idl_interface.children.length)
|
22
|
+
idl_op_decl = idl_interface.children.first
|
23
|
+
assert_equal('OneWayMethod', idl_op_decl.name)
|
24
|
+
assert_equal(:void, idl_op_decl.returns.to_sexp)
|
25
|
+
assert_equal('oneway', idl_op_decl.attribute)
|
26
|
+
|
27
|
+
assert_equal(2, idl_op_decl.children.length)
|
28
|
+
|
29
|
+
idl_op_decl.children.each do |child|
|
30
|
+
assert_instance_of(Parameter, child)
|
31
|
+
assert_equal(:in, child.attribute.to_sexp)
|
32
|
+
end
|
33
|
+
|
34
|
+
in_str = idl_op_decl.children.first
|
35
|
+
in_long = idl_op_decl.children[1]
|
36
|
+
|
37
|
+
assert_equal('inStr', in_str.name)
|
38
|
+
assert_equal('inLong', in_long.name)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Simple2Test < ZOMG::Test
|
4
|
+
def setup
|
5
|
+
@tree = ZOMG::IDL::Parser.parse_file(simple('simple2.idl'))
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_parse_simple2
|
9
|
+
assert_instance_of(Specification, @tree)
|
10
|
+
assert_equal(1, @tree.children.length)
|
11
|
+
|
12
|
+
idl_module = @tree.children.first
|
13
|
+
assert_instance_of(Module, idl_module)
|
14
|
+
assert_equal('TwoWaySimpleTest', idl_module.name)
|
15
|
+
|
16
|
+
assert_equal(2, idl_module.children.length)
|
17
|
+
exception = idl_module.children[0]
|
18
|
+
assert_instance_of(Exception, exception)
|
19
|
+
assert_equal('SimpleEx', exception.name)
|
20
|
+
|
21
|
+
idl_interface = idl_module.children[1]
|
22
|
+
assert_instance_of(Interface, idl_interface)
|
23
|
+
assert_equal('sim2wcor', idl_interface.header.name)
|
24
|
+
|
25
|
+
assert_equal(1, idl_interface.children.length)
|
26
|
+
idl_op_decl = idl_interface.children.first
|
27
|
+
assert_equal('TwoWayMethod', idl_op_decl.name)
|
28
|
+
assert_instance_of(String, idl_op_decl.returns)
|
29
|
+
assert_nil(idl_op_decl.attribute)
|
30
|
+
assert_equal(1, idl_op_decl.raises.length)
|
31
|
+
assert_equal('SimpleEx', idl_op_decl.raises.first.name)
|
32
|
+
|
33
|
+
assert_equal(3, idl_op_decl.children.length)
|
34
|
+
idl_op_decl.children.each do |child|
|
35
|
+
assert_instance_of(Parameter, child)
|
36
|
+
end
|
37
|
+
assert_equal([:in, :in_out, :out], idl_op_decl.children.map { |x|
|
38
|
+
x.attribute.to_sexp
|
39
|
+
})
|
40
|
+
assert_equal( [String, Long, UnsignedShort],
|
41
|
+
idl_op_decl.children.map { |x|
|
42
|
+
x.type.class
|
43
|
+
})
|
44
|
+
assert_equal(%w{ inStr inoutLong outUShort }, idl_op_decl.children.map { |x|
|
45
|
+
x.name
|
46
|
+
})
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Simple3Test < ZOMG::Test
|
4
|
+
def setup
|
5
|
+
@tree = ZOMG::IDL::Parser.parse_file(simple('simple3.idl'))
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_parse_tree
|
9
|
+
assert_equal(1, @tree.children.length)
|
10
|
+
idl_module = @tree.children.first
|
11
|
+
assert_equal(1, idl_module.children.length)
|
12
|
+
|
13
|
+
interface = idl_module.children.first
|
14
|
+
assert_equal(1, interface.children.length)
|
15
|
+
attribute = interface.children.first
|
16
|
+
assert_instance_of(Attribute, attribute)
|
17
|
+
assert_equal(1, attribute.children.length)
|
18
|
+
assert_equal('test', attribute.children.first.name)
|
19
|
+
end
|
20
|
+
end
|
data/test/test_array.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Array1Test < ZOMG::Test
|
4
|
+
def setup
|
5
|
+
@tree = ZOMG::IDL::Parser.parse_file(array('array1.idl'))
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_string_sequence
|
9
|
+
assert_sexp(
|
10
|
+
[:typedef, [:sequence, [[:scoped_name, "arr", []], [:int, 2]]], [[:decl, "arrseq"]]], @tree.duhr.Typedef[7])
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_forward_declaration
|
14
|
+
assert_sexp([:forward_decl, 'foo'], @tree.duhr.ForwardDeclaration[0])
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_to_sexp
|
18
|
+
assert_nothing_raised {
|
19
|
+
@tree.to_sexp
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
data/test/test_assets.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module ZOMG
|
4
|
+
module AssetTests
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
Dir[File.join(ZOMG::Test::ASSETS, '*')].each do |dir|
|
9
|
+
next unless File.directory?(dir)
|
10
|
+
klass = Class.new(ZOMG::Test) {
|
11
|
+
Dir[File.join(dir, '*.idl')].each do |file|
|
12
|
+
name = File.basename(file)
|
13
|
+
define_method(:setup) do
|
14
|
+
@tree = ZOMG::IDL::Parser.parse_file(file)
|
15
|
+
end
|
16
|
+
|
17
|
+
define_method(:"test_#{name.gsub('.', '_')}_to_sexp") do
|
18
|
+
assert_nothing_raised {
|
19
|
+
@tree.to_sexp
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
define_method(:"test_#{name.gsub('.', '_')}_to_ruby") do
|
24
|
+
ruby = nil
|
25
|
+
assert_nothing_raised { ruby = @tree.to_ruby }
|
26
|
+
x = Module.new
|
27
|
+
assert_nothing_raised { x.module_eval(ruby) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
}
|
31
|
+
test_name = File.basename(dir)
|
32
|
+
ZOMG::AssetTests.const_set(:"#{test_name.capitalize}Test", klass)
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ComplexTest < ZOMG::Test
|
4
|
+
COMPLEX = File.join(ASSETS, 'complex')
|
5
|
+
|
6
|
+
def test_constant_sexp
|
7
|
+
tree = ZOMG::IDL::Parser.parse_file(complex('complex4.idl'))
|
8
|
+
assert_sexp([:const, [:scoped_name, "longT", []], "long_c", [:int, 1]],
|
9
|
+
tree.duhr.Constant[0])
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_context_sexp
|
13
|
+
tree = ZOMG::IDL::Parser.parse_file(complex('TestIntfContext.idl'))
|
14
|
+
operation = tree.duhr.Module[0].Interface[0].Operation[0].tree
|
15
|
+
assert_sexp([:context, [[:string_lit, ["\"A*\""]], [:string_lit, ["\"C*\""]], [:string_lit, ["\"X\""]], [:string_lit, ["\"Z\""]]]], operation.context)
|
16
|
+
end
|
17
|
+
end
|
data/test/test_node.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class NodeTest < ZOMG::Test
|
4
|
+
def setup
|
5
|
+
@tree = ZOMG::IDL::Parser.parse_file(array('array1.idl'))
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_to_ruby
|
9
|
+
assert_nothing_raised {
|
10
|
+
@tree.to_ruby
|
11
|
+
}
|
12
|
+
ruby_with_prefix = @tree.to_ruby('A::B')
|
13
|
+
assert_match(/module A/, ruby_with_prefix)
|
14
|
+
assert_match(/module B/, ruby_with_prefix)
|
15
|
+
end
|
16
|
+
end
|
data/test/test_parser.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ParserTest < ZOMG::Test
|
4
|
+
def setup
|
5
|
+
@parser = ZOMG::IDL::Parser.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_valuetype
|
9
|
+
tree = @parser.parse(<<-eoidl)
|
10
|
+
module dom
|
11
|
+
{
|
12
|
+
valuetype DOMString sequence<unsigned short>;
|
13
|
+
};
|
14
|
+
eoidl
|
15
|
+
assert_nothing_raised { tree.to_sexp }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ScannerTest < ZOMG::Test
|
4
|
+
def setup
|
5
|
+
@scanner = ZOMG::IDL::Scanner.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_load_file
|
9
|
+
@scanner.load_file(simple('simple1.idl'))
|
10
|
+
tokens = []
|
11
|
+
while token = @scanner.next_token
|
12
|
+
tokens << token
|
13
|
+
end
|
14
|
+
assert tokens.length > 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_typedef_object
|
18
|
+
assert_tokens([
|
19
|
+
[:T_TYPEDEF, "typedef"],
|
20
|
+
[:T_OBJECT, "Object"],
|
21
|
+
[:T_IDENTIFIER, "ObjectAlias"],
|
22
|
+
], 'typedef Object ObjectAlias;')
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_const_long
|
26
|
+
assert_tokens([
|
27
|
+
[:T_CONST, "const"],
|
28
|
+
[:T_LONG, "long"],
|
29
|
+
[:T_IDENTIFIER, "ConstLong"],
|
30
|
+
[:T_EQUAL, "="],
|
31
|
+
[:T_MINUS_SIGN, "-"],
|
32
|
+
], 'const long ConstLong = -1234;')
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_escaped_string
|
36
|
+
assert_tokens([
|
37
|
+
[:T_CONST, "const"],
|
38
|
+
[:T_CHAR, "char"],
|
39
|
+
[:T_IDENTIFIER, "ConstChar5"],
|
40
|
+
[:T_EQUAL, "="],
|
41
|
+
[:T_CHARACTER_LITERAL, "'\\''"],
|
42
|
+
], 'const char ConstChar5 = \'\\\'\'')
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_vertical_pipe
|
46
|
+
assert_tokens([
|
47
|
+
[:T_CONST, "const"],
|
48
|
+
[:T_LONG, "long"],
|
49
|
+
[:T_IDENTIFIER, "ConstLong"],
|
50
|
+
[:T_EQUAL, "="],
|
51
|
+
[:T_LEFT_PARANTHESIS, "("],
|
52
|
+
[:T_INTEGER_LITERAL, "0xf"],
|
53
|
+
[:T_VERTICAL_LINE, "|"],
|
54
|
+
], "const long ConstLong = (0xf | 0xf000) & 0xfffe")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_instr
|
58
|
+
assert_tokens([
|
59
|
+
[:T_IN, "in"],
|
60
|
+
[:T_STRING, "string"],
|
61
|
+
[:T_IDENTIFIER, "inStr"],
|
62
|
+
], "in string inStr")
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_comment
|
66
|
+
assert_tokens([[:T_COMMENT, "// boner"]], "// boner")
|
67
|
+
assert_tokens([[:T_COMMENT, "/* boner */"]], "/* boner */")
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_pragma
|
71
|
+
assert_tokens([[:T_PRAGMA, "#pragma awesome\n"]], "#pragma awesome\n")
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_preprocessor_directive
|
75
|
+
assert_tokens([[:T_PREPROCESSOR, "#awesome\n"]], "#awesome\n")
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_curlies
|
79
|
+
assert_tokens([[:T_LEFT_CURLY_BRACKET, "{"]], "{")
|
80
|
+
assert_tokens([[:T_RIGHT_CURLY_BRACKET, "}"]], "}")
|
81
|
+
assert_tokens([
|
82
|
+
[:T_LEFT_CURLY_BRACKET, "{"],
|
83
|
+
[:T_RIGHT_CURLY_BRACKET, "}"]
|
84
|
+
], "{ }\n")
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_squares
|
88
|
+
assert_tokens([[:T_LEFT_SQUARE_BRACKET, "["]], "[")
|
89
|
+
assert_tokens([[:T_RIGHT_SQUARE_BRACKET, "]"]], "]")
|
90
|
+
assert_tokens([
|
91
|
+
[:T_LEFT_SQUARE_BRACKET, "["],
|
92
|
+
[:T_RIGHT_SQUARE_BRACKET, "]"]
|
93
|
+
], " [ ] \n")
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_parens
|
97
|
+
assert_tokens([[:T_LEFT_PARANTHESIS, "("]], "(")
|
98
|
+
assert_tokens([[:T_RIGHT_PARANTHESIS, ")"]], ")")
|
99
|
+
assert_tokens([
|
100
|
+
[:T_LEFT_PARANTHESIS, "("],
|
101
|
+
[:T_RIGHT_PARANTHESIS, ")"]
|
102
|
+
], " ( ) \n")
|
103
|
+
end
|
104
|
+
|
105
|
+
# Test literals
|
106
|
+
{
|
107
|
+
:const => [:T_CONST, 'const'],
|
108
|
+
:typedef => [:T_TYPEDEF, 'typedef'],
|
109
|
+
:float => [:T_FLOAT, 'float'],
|
110
|
+
:double => [:T_DOUBLE, 'double'],
|
111
|
+
:char => [:T_CHAR, 'char'],
|
112
|
+
:wchar => [:T_WCHAR, 'wchar'],
|
113
|
+
:fixed => [:T_FIXED, 'fixed'],
|
114
|
+
:boolean => [:T_BOOLEAN, 'boolean'],
|
115
|
+
:string => [:T_STRING, 'string'],
|
116
|
+
:wstring => [:T_WSTRING, 'wstring'],
|
117
|
+
:void => [:T_VOID, 'void'],
|
118
|
+
:unsigned => [:T_UNSIGNED, 'unsigned'],
|
119
|
+
:long => [:T_LONG, 'long'],
|
120
|
+
:short => [:T_SHORT, 'short'],
|
121
|
+
:struct => [:T_STRUCT, 'struct'],
|
122
|
+
:union => [:T_UNION, 'union'],
|
123
|
+
:switch => [:T_SWITCH, 'switch'],
|
124
|
+
:case => [:T_CASE, 'case'],
|
125
|
+
:default => [:T_DEFAULT, 'default'],
|
126
|
+
:enum => [:T_ENUM, 'enum'],
|
127
|
+
:in => [:T_IN, 'in'],
|
128
|
+
:out => [:T_OUT, 'out'],
|
129
|
+
:interface => [:T_INTERFACE, 'interface'],
|
130
|
+
:abstract => [:T_ABSTRACT, 'abstract'],
|
131
|
+
:valuetype => [:T_VALUETYPE, 'valuetype'],
|
132
|
+
:truncatable => [:T_TRUNCATABLE, 'truncatable'],
|
133
|
+
:supports => [:T_SUPPORTS, 'supports'],
|
134
|
+
:custom => [:T_CUSTOM, 'custom'],
|
135
|
+
:public => [:T_PUBLIC, 'public'],
|
136
|
+
:private => [:T_PRIVATE, 'private'],
|
137
|
+
:factory => [:T_FACTORY, 'factory'],
|
138
|
+
:native => [:T_NATIVE, 'native'],
|
139
|
+
:module => [:T_MODULE, 'module'],
|
140
|
+
:octet => [:T_OCTET, 'octet'],
|
141
|
+
:any => [:T_ANY, 'any'],
|
142
|
+
:sequence => [:T_SEQUENCE, 'sequence'],
|
143
|
+
:readonly => [:T_READONLY, 'readonly'],
|
144
|
+
:attribute => [:T_ATTRIBUTE, 'attribute'],
|
145
|
+
:exception => [:T_EXCEPTION, 'exception'],
|
146
|
+
:oneway => [:T_ONEWAY, 'oneway'],
|
147
|
+
:inout => [:T_INOUT, 'inout'],
|
148
|
+
:raises => [:T_RAISES, 'raises'],
|
149
|
+
:context => [:T_CONTEXT, 'context'],
|
150
|
+
}.each do |type, token|
|
151
|
+
define_method(:"test_#{type}") do
|
152
|
+
parse_text = token.length == 3 ? token.pop : token.last
|
153
|
+
assert_tokens([token], parse_text)
|
154
|
+
assert_tokens([
|
155
|
+
[:T_LEFT_SQUARE_BRACKET, "["],
|
156
|
+
token,
|
157
|
+
[:T_RIGHT_SQUARE_BRACKET, "]"]
|
158
|
+
], " [\n#{parse_text}] \n")
|
159
|
+
assert_tokens([
|
160
|
+
[:T_IN, "in"],
|
161
|
+
[:T_STRING, "string"],
|
162
|
+
[:T_IDENTIFIER, "#{parse_text}Str"],
|
163
|
+
], "in string #{parse_text}Str")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
{
|
168
|
+
:minus => [:T_MINUS_SIGN, '-'],
|
169
|
+
:plus => [:T_PLUS_SIGN, '+'],
|
170
|
+
:shift_left => [:T_SHIFTLEFT, '<<'],
|
171
|
+
:shift_right => [:T_SHIFTRIGHT, '>>'],
|
172
|
+
:equal => [:T_EQUAL, '='],
|
173
|
+
:semicolon => [:T_SEMICOLON, ';'],
|
174
|
+
:comma => [:T_COMMA, ','],
|
175
|
+
:colon => [:T_COLON, ':'],
|
176
|
+
:asterisk => [:T_ASTERISK, '*'],
|
177
|
+
:solidus => [:T_SOLIDUS, '/'],
|
178
|
+
:percent => [:T_PERCENT_SIGN, '%'],
|
179
|
+
:tilde => [:T_TILDE, '~'],
|
180
|
+
:pipe => [:T_VERTICAL_LINE, '|'],
|
181
|
+
:caret => [:T_CIRCUMFLEX, '^'],
|
182
|
+
:ampersand => [:T_AMPERSAND, '&'],
|
183
|
+
:less_than => [:T_LESS_THAN_SIGN, '<'],
|
184
|
+
:greater_than => [:T_GREATER_THAN_SIGN, '>'],
|
185
|
+
:FALSE => [:T_FALSE, 'FALSE'],
|
186
|
+
:TRUE => [:T_TRUE, 'TRUE'],
|
187
|
+
:ValueBase => [:T_VALUEBASE, 'ValueBase'],
|
188
|
+
:scope => [:T_SCOPE, '::'],
|
189
|
+
:object => [:T_OBJECT, 'Object'],
|
190
|
+
:principal => [:T_PRINCIPAL, 'Principal'],
|
191
|
+
:identifier => [:T_IDENTIFIER, 'hello'],
|
192
|
+
:float_lit_1 => [:T_FLOATING_PT_LITERAL, '123.2e10'],
|
193
|
+
:float_lit_11 => [:T_FLOATING_PT_LITERAL, '123.2E10'],
|
194
|
+
:float_lit_2 => [:T_FLOATING_PT_LITERAL, '123.0E-5', '123.E-5'],
|
195
|
+
:float_lit_3 => [:T_FLOATING_PT_LITERAL, '123e10'],
|
196
|
+
:float_lit_31 => [:T_FLOATING_PT_LITERAL, '123E+10'],
|
197
|
+
:float_lit_4 => [:T_FLOATING_PT_LITERAL, '12.2'],
|
198
|
+
:float_lit_5 => [:T_FLOATING_PT_LITERAL, '12.0', '12.'],
|
199
|
+
:float_lit_6 => [:T_FLOATING_PT_LITERAL, '0.12e10', '.12e10'],
|
200
|
+
:float_lit_61 => [:T_FLOATING_PT_LITERAL, '0.12e+10', '.12e+10'],
|
201
|
+
:float_lit_7 => [:T_FLOATING_PT_LITERAL, '0.12', '.12'],
|
202
|
+
:fixed_lit_1 => [:T_FIXED_PT_LITERAL, '123', '123d'],
|
203
|
+
:fixed_lit_2 => [:T_FIXED_PT_LITERAL, '123', '123.d'],
|
204
|
+
:fixed_lit_21 => [:T_FIXED_PT_LITERAL, '123', '123.D'],
|
205
|
+
:fixed_lit_3 => [:T_FIXED_PT_LITERAL, '0.123', '.123d'],
|
206
|
+
:fixed_lit_31 => [:T_FIXED_PT_LITERAL, '0.123', '.123D'],
|
207
|
+
:fixed_lit_4 => [:T_FIXED_PT_LITERAL, '0.123', '0.123d'],
|
208
|
+
:fixed_lit_41 => [:T_FIXED_PT_LITERAL, '0.123', '0.123D'],
|
209
|
+
:hex_lit => [:T_INTEGER_LITERAL, '0x23'],
|
210
|
+
:hex_lit_1 => [:T_INTEGER_LITERAL, '0X23'],
|
211
|
+
:oct_lit => [:T_INTEGER_LITERAL, '023'],
|
212
|
+
:int_lit => [:T_INTEGER_LITERAL, '23'],
|
213
|
+
:char_lit => [:T_CHARACTER_LITERAL, "'a'"],
|
214
|
+
:string_lit => [:T_STRING_LITERAL, '"abc"'],
|
215
|
+
:unknown => [:T_UNKNOWN, '.'],
|
216
|
+
}.each do |type, token|
|
217
|
+
define_method(:"test_#{type}") do
|
218
|
+
parse_text = token.length == 3 ? token.pop : token.last
|
219
|
+
assert_tokens([token], parse_text)
|
220
|
+
assert_tokens([
|
221
|
+
[:T_LEFT_SQUARE_BRACKET, "["],
|
222
|
+
token,
|
223
|
+
[:T_RIGHT_SQUARE_BRACKET, "]"]
|
224
|
+
], " [\n#{parse_text}] \n")
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def assert_tokens(tokens, string)
|
229
|
+
@scanner.scan_evaluate(string)
|
230
|
+
tokens.each do |token|
|
231
|
+
assert_equal(token, @scanner.next_token)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|