rgen 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/CHANGELOG +28 -0
  2. data/Rakefile +3 -4
  3. data/lib/ea_support/uml13_ea_metamodel.rb +3 -3
  4. data/lib/ea_support/uml13_ea_to_uml13.rb +33 -2
  5. data/lib/ea_support/uml13_to_uml13_ea.rb +7 -0
  6. data/lib/mmgen/mm_ext/ecore_mmgen_ext.rb +4 -4
  7. data/lib/mmgen/templates/metamodel_generator.tpl +143 -143
  8. data/lib/rgen/ecore/ecore.rb +11 -1
  9. data/lib/rgen/ecore/ecore_interface.rb +47 -0
  10. data/lib/rgen/ecore/ecore_to_ruby.rb +166 -0
  11. data/lib/rgen/ecore/{ecore_transformer.rb → ruby_to_ecore.rb} +11 -11
  12. data/lib/rgen/environment.rb +15 -2
  13. data/lib/rgen/fragment/dump_file_cache.rb +63 -0
  14. data/lib/rgen/fragment/fragmented_model.rb +139 -0
  15. data/lib/rgen/fragment/model_fragment.rb +268 -0
  16. data/lib/rgen/instantiator/abstract_xml_instantiator.rb +44 -72
  17. data/lib/rgen/instantiator/default_xml_instantiator.rb +2 -2
  18. data/lib/rgen/instantiator/ecore_xml_instantiator.rb +16 -1
  19. data/lib/rgen/instantiator/json_instantiator.rb +16 -2
  20. data/lib/rgen/instantiator/nodebased_xml_instantiator.rb +118 -138
  21. data/lib/rgen/instantiator/qualified_name_resolver.rb +5 -1
  22. data/lib/rgen/instantiator/reference_resolver.rb +126 -24
  23. data/lib/rgen/instantiator/xmi11_instantiator.rb +6 -2
  24. data/lib/rgen/metamodel_builder.rb +18 -6
  25. data/lib/rgen/metamodel_builder/builder_extensions.rb +431 -407
  26. data/lib/rgen/metamodel_builder/builder_runtime.rb +8 -8
  27. data/lib/rgen/metamodel_builder/constant_order_helper.rb +4 -4
  28. data/lib/rgen/metamodel_builder/data_types.rb +5 -1
  29. data/lib/rgen/metamodel_builder/intermediate/feature.rb +167 -0
  30. data/lib/rgen/metamodel_builder/module_extension.rb +2 -2
  31. data/lib/rgen/model_builder.rb +10 -5
  32. data/lib/rgen/model_builder/builder_context.rb +17 -1
  33. data/lib/rgen/serializer/opposite_reference_filter.rb +18 -0
  34. data/lib/rgen/serializer/qualified_name_provider.rb +45 -0
  35. data/lib/rgen/template_language/template_container.rb +3 -1
  36. data/lib/rgen/{auto_class_creator.rb → util/auto_class_creator.rb} +6 -1
  37. data/lib/rgen/util/cached_glob.rb +67 -0
  38. data/lib/rgen/util/file_cache_map.rb +104 -0
  39. data/lib/rgen/util/file_change_detector.rb +78 -0
  40. data/lib/rgen/{method_delegation.rb → util/method_delegation.rb} +18 -3
  41. data/lib/rgen/{model_comparator.rb → util/model_comparator.rb} +17 -5
  42. data/lib/rgen/{model_comparator_base.rb → util/model_comparator_base.rb} +6 -1
  43. data/lib/rgen/{model_dumper.rb → util/model_dumper.rb} +6 -1
  44. data/lib/rgen/{name_helper.rb → util/name_helper.rb} +6 -1
  45. data/lib/rgen/util/pattern_matcher.rb +329 -0
  46. data/lib/transformers/uml13_to_ecore.rb +103 -60
  47. data/test/ecore_self_test.rb +43 -42
  48. data/test/json_test.rb +15 -0
  49. data/test/metamodel_builder_test.rb +361 -206
  50. data/test/metamodel_from_ecore_test.rb +45 -0
  51. data/test/metamodel_order_test.rb +10 -4
  52. data/test/metamodel_roundtrip_test.rb +2 -2
  53. data/test/metamodel_roundtrip_test/TestModel_Regenerated.rb +1 -1
  54. data/test/metamodel_roundtrip_test/houseMetamodel_Regenerated.ecore +50 -50
  55. data/test/method_delegation_test.rb +9 -9
  56. data/test/model_builder/ecore_internal.rb +19 -9
  57. data/test/model_builder/serializer_test.rb +1 -1
  58. data/test/reference_resolver_test.rb +79 -12
  59. data/test/rgen_test.rb +2 -0
  60. data/test/template_language_test.rb +7 -0
  61. data/test/template_language_test/templates/callback_indent_test/a.tpl +12 -0
  62. data/test/template_language_test/templates/callback_indent_test/b.tpl +5 -0
  63. data/test/testmodel/ea_testmodel_regenerated.xml +588 -583
  64. data/test/transformer_test.rb +3 -3
  65. data/test/util/file_cache_map_test.rb +91 -0
  66. data/test/util/file_cache_map_test/testdir/fileA +1 -0
  67. data/test/util_test.rb +4 -0
  68. data/test/xml_instantiator_test.rb +139 -135
  69. metadata +49 -104
  70. data/lib/rgen/ecore/ecore_instantiator.rb +0 -31
  71. data/lib/rgen/metamodel_builder/metamodel_description.rb +0 -232
  72. data/redist/xmlscan/ChangeLog +0 -1301
  73. data/redist/xmlscan/README +0 -34
  74. data/redist/xmlscan/THANKS +0 -11
  75. data/redist/xmlscan/doc/changes.html +0 -74
  76. data/redist/xmlscan/doc/changes.rd +0 -80
  77. data/redist/xmlscan/doc/en/conformance.html +0 -136
  78. data/redist/xmlscan/doc/en/conformance.rd +0 -152
  79. data/redist/xmlscan/doc/en/manual.html +0 -356
  80. data/redist/xmlscan/doc/en/manual.rd +0 -402
  81. data/redist/xmlscan/doc/ja/conformance.ja.html +0 -118
  82. data/redist/xmlscan/doc/ja/conformance.ja.rd +0 -134
  83. data/redist/xmlscan/doc/ja/manual.ja.html +0 -325
  84. data/redist/xmlscan/doc/ja/manual.ja.rd +0 -370
  85. data/redist/xmlscan/doc/src/Makefile +0 -41
  86. data/redist/xmlscan/doc/src/conformance.rd.src +0 -256
  87. data/redist/xmlscan/doc/src/langsplit.rb +0 -110
  88. data/redist/xmlscan/doc/src/manual.rd.src +0 -614
  89. data/redist/xmlscan/install.rb +0 -41
  90. data/redist/xmlscan/lib/xmlscan/encoding.rb +0 -311
  91. data/redist/xmlscan/lib/xmlscan/htmlscan.rb +0 -289
  92. data/redist/xmlscan/lib/xmlscan/namespace.rb +0 -352
  93. data/redist/xmlscan/lib/xmlscan/parser.rb +0 -299
  94. data/redist/xmlscan/lib/xmlscan/scanner.rb +0 -1109
  95. data/redist/xmlscan/lib/xmlscan/version.rb +0 -22
  96. data/redist/xmlscan/lib/xmlscan/visitor.rb +0 -158
  97. data/redist/xmlscan/lib/xmlscan/xmlchar.rb +0 -441
  98. data/redist/xmlscan/memo/CONFORMANCE +0 -1249
  99. data/redist/xmlscan/memo/PRODUCTIONS +0 -195
  100. data/redist/xmlscan/memo/contentspec.ry +0 -335
  101. data/redist/xmlscan/samples/chibixml.rb +0 -105
  102. data/redist/xmlscan/samples/getxmlchar.rb +0 -122
  103. data/redist/xmlscan/samples/rexml.rb +0 -159
  104. data/redist/xmlscan/samples/xmlbench.rb +0 -88
  105. data/redist/xmlscan/samples/xmlbench/parser/chibixml.rb +0 -22
  106. data/redist/xmlscan/samples/xmlbench/parser/nqxml.rb +0 -29
  107. data/redist/xmlscan/samples/xmlbench/parser/rexml.rb +0 -62
  108. data/redist/xmlscan/samples/xmlbench/parser/xmlparser.rb +0 -22
  109. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-0.0.10.rb +0 -62
  110. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-chibixml.rb +0 -22
  111. data/redist/xmlscan/samples/xmlbench/parser/xmlscan-rexml.rb +0 -22
  112. data/redist/xmlscan/samples/xmlbench/parser/xmlscan.rb +0 -99
  113. data/redist/xmlscan/samples/xmlbench/xmlbench-lib.rb +0 -116
  114. data/redist/xmlscan/samples/xmlconftest.rb +0 -200
  115. data/redist/xmlscan/test.rb +0 -7
  116. data/redist/xmlscan/tests/deftestcase.rb +0 -73
  117. data/redist/xmlscan/tests/runtest.rb +0 -47
  118. data/redist/xmlscan/tests/testall.rb +0 -14
  119. data/redist/xmlscan/tests/testencoding.rb +0 -438
  120. data/redist/xmlscan/tests/testhtmlscan.rb +0 -752
  121. data/redist/xmlscan/tests/testnamespace.rb +0 -457
  122. data/redist/xmlscan/tests/testparser.rb +0 -591
  123. data/redist/xmlscan/tests/testscanner.rb +0 -1749
  124. data/redist/xmlscan/tests/testxmlchar.rb +0 -143
  125. data/redist/xmlscan/tests/visitor.rb +0 -34
@@ -1,200 +0,0 @@
1
- #!/usr/bin/ruby
2
- #
3
- # samples/xmlconftest.rb - OASIS XML Conformance Test
4
- #
5
- # Copyright (C) UENO Katsuhiro 2002
6
- #
7
- # $Id: xmlconftest.rb,v 1.3 2003/01/22 16:46:32 katsu Exp $
8
- #
9
- #
10
- # OASIS - Technical Committees - XML Conformance
11
- # http://www.oasis-open.org/committees/xml-conformance/xml-test-suite.shtml
12
- #
13
-
14
- require 'samples/xmlbench/xmlbench-lib'
15
-
16
- $KCODE = 'U'
17
-
18
- # you must edit here as your environment.
19
- XMLCONFDIR = "./xmlconf/"
20
- XMLCONFLOG = "./xmlconftest.log"
21
-
22
-
23
-
24
- PositiveTests = Dir.glob(XMLCONFDIR + '*/valid/*/*.xml') +
25
- Dir.glob(XMLCONFDIR + 'oasis/p*pass*.xml')
26
-
27
- NegativeTests = Dir.glob(XMLCONFDIR + '*/not-wf/*/*.xml') +
28
- Dir.glob(XMLCONFDIR + 'oasis/p*fail*.xml')
29
-
30
- NegativeTestRejects = [
31
- # non-validating processors may accept these instances.
32
- 'oasis/p06fail1.xml',
33
- 'oasis/p08fail1.xml',
34
- 'oasis/p08fail2.xml',
35
- # non-validating processors may accept these instances
36
- # since they require XML processors to read external entites.
37
- 'ibm/not-wf/P30/ibm30n01.xml',
38
- 'ibm/not-wf/P31/ibm31n01.xml',
39
- 'ibm/not-wf/P61/ibm61n01.xml',
40
- 'ibm/not-wf/P62/ibm62n01.xml',
41
- 'ibm/not-wf/P62/ibm62n02.xml',
42
- 'ibm/not-wf/P62/ibm62n03.xml',
43
- 'ibm/not-wf/P62/ibm62n04.xml',
44
- 'ibm/not-wf/P62/ibm62n05.xml',
45
- 'ibm/not-wf/P62/ibm62n06.xml',
46
- 'ibm/not-wf/P62/ibm62n07.xml',
47
- 'ibm/not-wf/P62/ibm62n08.xml',
48
- 'ibm/not-wf/P63/ibm63n01.xml',
49
- 'ibm/not-wf/P63/ibm63n02.xml',
50
- 'ibm/not-wf/P63/ibm63n03.xml',
51
- 'ibm/not-wf/P63/ibm63n04.xml',
52
- 'ibm/not-wf/P63/ibm63n05.xml',
53
- 'ibm/not-wf/P63/ibm63n06.xml',
54
- 'ibm/not-wf/P63/ibm63n07.xml',
55
- 'ibm/not-wf/P64/ibm64n01.xml',
56
- 'ibm/not-wf/P64/ibm64n02.xml',
57
- 'ibm/not-wf/P64/ibm64n03.xml',
58
- 'ibm/not-wf/P65/ibm65n01.xml',
59
- 'ibm/not-wf/P65/ibm65n02.xml',
60
- 'ibm/not-wf/P77/ibm77n03.xml',
61
- 'ibm/not-wf/P77/ibm77n04.xml',
62
- 'ibm/not-wf/P78/ibm78n01.xml',
63
- 'ibm/not-wf/P78/ibm78n02.xml',
64
- 'ibm/not-wf/P79/ibm79n01.xml',
65
- 'ibm/not-wf/P79/ibm79n02.xml',
66
- 'oasis/p09fail1.xml',
67
- 'oasis/p09fail2.xml',
68
- 'oasis/p30fail1.xml',
69
- 'oasis/p31fail1.xml',
70
- 'oasis/p61fail1.xml',
71
- 'oasis/p62fail1.xml',
72
- 'oasis/p62fail2.xml',
73
- 'oasis/p63fail1.xml',
74
- 'oasis/p63fail2.xml',
75
- 'oasis/p64fail1.xml',
76
- 'oasis/p64fail2.xml',
77
- 'xmltest/not-wf/ext-sa/001.xml',
78
- 'xmltest/not-wf/ext-sa/002.xml',
79
- 'xmltest/not-wf/ext-sa/003.xml',
80
- 'xmltest/not-wf/not-sa/001.xml',
81
- 'xmltest/not-wf/not-sa/003.xml',
82
- 'xmltest/not-wf/not-sa/004.xml',
83
- 'xmltest/not-wf/not-sa/005.xml',
84
- 'xmltest/not-wf/not-sa/006.xml',
85
- 'xmltest/not-wf/not-sa/007.xml',
86
- 'xmltest/not-wf/not-sa/008.xml',
87
- ]
88
-
89
- #NegativeTests.reject! { |i|
90
- # NegativeTestRejects.include? i[XMLCONFDIR.size..-1]
91
- #}
92
-
93
-
94
-
95
- class XMLConfTest
96
-
97
- def initialize(parser)
98
- @parser = parser
99
- @result = {}
100
- end
101
-
102
- def class_name
103
- @parser.class.name
104
- end
105
-
106
- def name
107
- @parser.name
108
- end
109
-
110
- def total
111
- @result.size
112
- end
113
-
114
- def success
115
- @result.select{ |k,v| v }.collect{ |k,v| k }.sort
116
- end
117
-
118
- def failure
119
- @result.select{ |k,v| not v }.collect{ |k,v| k }.sort
120
- end
121
-
122
- def success_percent
123
- 100.0 * success.size / total
124
- end
125
-
126
- def failure_percent
127
- 100.0 * failure.size / total
128
- end
129
-
130
- def check(format, *files)
131
- total = 0
132
- ok = 0
133
- failed = 0
134
- files.each { |i|
135
- total += 1
136
- File.open(i) { |f|
137
- result = true
138
- begin
139
- @parser.parse f.read
140
- rescue Exception
141
- result = false
142
- end
143
- @result[i] = result
144
- if result then
145
- ok += 1
146
- else
147
- failed += 1
148
- end
149
- }
150
- printf format+"\r",
151
- name, total, ok, ok*100.0/total, failed, failed*100.0/total
152
- }
153
- print "\n"
154
- end
155
-
156
- end
157
-
158
-
159
-
160
- XMLBench.weight_limit = 10
161
-
162
- if ARGV.empty? then
163
- subjects = XMLBench.setup_all
164
- else
165
- subjects = XMLBench.setup(*ARGV)
166
- end
167
-
168
-
169
-
170
- log = File.open(XMLCONFLOG, 'w')
171
- END { log.close }
172
-
173
-
174
- puts ' '*30+' total success failure'
175
-
176
- puts "** POSITIVE TEST **"
177
-
178
- subjects.each { |parser|
179
- conf = XMLConfTest.new(parser)
180
- conf.check("%-30s %4d %4d (%5.1f%%) %4d (%5.1f%%)",
181
- *PositiveTests)
182
- if conf.failure.size > 0 then
183
- log.puts "---- #{conf.name} couldn't parse the following files:"
184
- conf.failure.each { |i| log.puts "P #{conf.class_name} #{i}" }
185
- log.puts
186
- end
187
- }
188
-
189
- puts "** NEGATIVE TEST **"
190
-
191
- subjects.each { |parser|
192
- conf = XMLConfTest.new(parser)
193
- conf.check("%-30s %4d %4d (%5.1f%%) %4d (%5.1f%%)",
194
- *NegativeTests)
195
- if conf.success.size > 0 then
196
- log.puts "---- #{conf.name} could parse the following files:"
197
- conf.success.each { |i| log.puts "N #{conf.class_name} #{i}" }
198
- log.puts
199
- end
200
- }
@@ -1,7 +0,0 @@
1
- #!/usr/bin/ruby
2
- $-w = true
3
- $LOAD_PATH.unshift 'lib'
4
- $LOAD_PATH.unshift 'tests'
5
- Dir.chdir File.dirname($0)
6
- require 'testall'
7
- load 'runtest.rb'
@@ -1,73 +0,0 @@
1
- #
2
- # tests/deftestcase.rb
3
- #
4
- # Copyright (C) UENO Katsuhiro 2002
5
- #
6
- # $Id: deftestcase.rb,v 1.7 2003/02/28 12:31:07 katsu Exp $
7
- #
8
-
9
- module DefTestCase
10
-
11
- class << self
12
- private
13
- def append_features(mod)
14
- super
15
- mod.extend DefTestCaseSingleton
16
- end
17
- end
18
-
19
-
20
- module DefTestCaseSingleton
21
-
22
- private
23
-
24
- def deftestcase(prefix, testcases)
25
- filename, lineno = caller.first.split(':')
26
- lineno = lineno.to_i + 1
27
- testno = 0
28
- testcases.split(/^\s+?^/).each { |test|
29
- test = test.split(/^/)
30
- test.each { |i| i.strip! }
31
- args = test.reject { |i| i.empty? or /\A#/ =~ i }
32
- unless args.empty? then
33
- name = sprintf('test_%s_%03d', prefix, testno += 1)
34
- src = "def #{name} ; do_testcase(#{args.join(',')}) ; end"
35
- module_eval src, filename, lineno
36
- end
37
- lineno += test.size + 1
38
- }
39
- end
40
-
41
- end
42
-
43
-
44
- private
45
-
46
- def do_testcase(src, *expected)
47
- expected = [ [:on_start_document] ] + expected + [ [:on_end_document] ]
48
- result = parse(src)
49
- begin
50
- assert_equal expected, result
51
- rescue Test::Unit::AssertionFailedError => e
52
- was = ''
53
- result.each_with_index { |i,n|
54
- was << "\t#{i.inspect}"
55
- was << " <= !!!!" unless i == expected[n]
56
- was << "\n"
57
- }
58
- msg = "\ntestcase:\n\t" + src +
59
- "\nexpected:\n" + expected.collect{|i|"\t#{i.inspect}\n"}.join +
60
- "but was:\n" + was
61
- backtrace = e.backtrace.reject { |i|
62
- /\A#{__FILE__}:\d+:in `do_testcase'/n =~ i
63
- }
64
- raise e, msg, backtrace
65
- end
66
- end
67
-
68
-
69
- def parse(src)
70
- raise NotImplementedError, "abstract method"
71
- end
72
-
73
- end
@@ -1,47 +0,0 @@
1
- #!/usr/bin/ruby
2
- #
3
- # runtest.rb
4
- #
5
- # $Id: runtest.rb,v 1.6 2005/05/22 07:07:12 nahi Exp $
6
- #
7
-
8
- require 'test/unit'
9
- require 'test/unit/testsuite'
10
- require 'test/unit/ui/console/testrunner'
11
-
12
- $SAFE = 2 rescue nil
13
- STDOUT.sync = true
14
- STDERR.sync = true
15
-
16
-
17
- if ARGV[0] == '-v' then
18
- output_level = Test::Unit::UI::VERBOSE
19
- ARGV.shift
20
- else
21
- output_level = Test::Unit::UI::NORMAL
22
- end
23
-
24
-
25
- argv = ARGV.collect { |i| i.split(/[#:]/, 2) } # [ class, testcase ]
26
-
27
- def argv.exactly_include?(classname)
28
- empty? or find{ |i| i == [classname] }
29
- end
30
- def argv.testcases(classname)
31
- select{ |i| i.first == classname }.collect{ |i| i.last }
32
- end
33
-
34
-
35
- suite = Test::Unit::TestSuite.new
36
- ObjectSpace.each_object(Class) { |c|
37
- if /\ATest/ =~ c.name and not c.equal? Test::Unit::TestCase and
38
- c.ancestors.include? Test::Unit::TestCase then
39
- if argv.exactly_include? c.name then
40
- suite << c.suite
41
- else
42
- argv.testcases(c.name).each { |i| suite << c.new(i) }
43
- end
44
- end
45
- }
46
-
47
- Test::Unit::UI::Console::TestRunner.run suite, output_level
@@ -1,14 +0,0 @@
1
- #
2
- # tests/testall.rb
3
- #
4
- # $Id: testall.rb,v 1.6 2003/01/12 04:10:59 katsu Exp $
5
- #
6
-
7
- require 'testscanner'
8
- require 'testhtmlscan'
9
- require 'testparser'
10
- require 'testnamespace'
11
- require 'testxmlchar'
12
- require 'testencoding'
13
-
14
- load "#{File.dirname($0)}/runtest.rb" if __FILE__ == $0
@@ -1,438 +0,0 @@
1
- #
2
- # tests/xmlchar.rb
3
- #
4
- # Copyright (C) Ueno Katsuhiro 2002
5
- #
6
- # $Id: testencoding.rb,v 1.5 2003/02/28 12:31:07 katsu Exp $
7
- #
8
-
9
- require 'test/unit'
10
- require 'xmlscan/encoding'
11
-
12
-
13
- class TestEncoding < Test::Unit::TestCase
14
-
15
- NoMethodError = NameError unless defined? NoMethodError
16
-
17
- class MyEncodingClass < XMLScan::EncodingClass
18
- class << self
19
- public :new
20
- end
21
- end
22
-
23
- EncodingError = XMLScan::EncodingError
24
-
25
- class FugaConverter < XMLScan::Converter
26
- def initialize
27
- @hoge = 'FUGA'
28
- end
29
- def convert(s)
30
- ret = "#{@hoge}:#{s}:BUYO"
31
- @hoge = ''
32
- ret
33
- end
34
- def finish
35
- "FOOBAR"
36
- end
37
- end
38
-
39
-
40
- NONE = //n.kcode
41
- EUC = //e.kcode
42
- SJIS = //s.kcode
43
- UTF8 = //u.kcode
44
-
45
-
46
- def setup
47
- @e = MyEncodingClass.new
48
- @e.add_converter('hoge', 'fuga', 10) { |s| "HOGE:#{s}:FUGA" }
49
- @e.add_converter('fuga', 'buyo', 10, FugaConverter)
50
- @e.set_kcode 'hoge', 'E'
51
- @e.set_kcode 'fuga', 'S'
52
- end
53
-
54
-
55
- def test_s_new
56
- assert_raises(NoMethodError) { XMLScan::EncodingClass.new }
57
- end
58
-
59
- def test_s_instance
60
- assert_kind_of XMLScan::EncodingClass, XMLScan::Encoding
61
- end
62
-
63
- def test_preset_kcode
64
- assert_equal UTF8, XMLScan::Encoding.kcode('utf-8')
65
- assert_equal nil, XMLScan::Encoding.kcode('utf-16')
66
- assert_equal nil, XMLScan::Encoding.kcode('iso-10646-ucs-2')
67
- assert_equal nil, XMLScan::Encoding.kcode('iso-10646-ucs-4')
68
- assert_equal NONE, XMLScan::Encoding.kcode('iso-8859-1')
69
- assert_equal NONE, XMLScan::Encoding.kcode('iso-8859-2')
70
- assert_equal NONE, XMLScan::Encoding.kcode('iso-8859-3')
71
- assert_equal NONE, XMLScan::Encoding.kcode('iso-8859-4')
72
- assert_equal NONE, XMLScan::Encoding.kcode('iso-8859-5')
73
- assert_equal NONE, XMLScan::Encoding.kcode('iso-8859-6')
74
- assert_equal NONE, XMLScan::Encoding.kcode('iso-8859-7')
75
- assert_equal NONE, XMLScan::Encoding.kcode('iso-8859-8')
76
- assert_equal NONE, XMLScan::Encoding.kcode('iso-8859-9')
77
- assert_equal nil, XMLScan::Encoding.kcode('iso-2022-jp')
78
- assert_equal SJIS, XMLScan::Encoding.kcode('shift_jis')
79
- assert_equal SJIS, XMLScan::Encoding.kcode('windows-31J')
80
- assert_equal EUC, XMLScan::Encoding.kcode('euc-jp')
81
- assert_equal EUC, XMLScan::Encoding.kcode('euc-kr')
82
- end
83
-
84
-
85
- def test_alias
86
- assert_nil @e.alias('foo', 'hoge')
87
- assert_equal EUC, @e.kcode('foo')
88
- c = nil
89
- assert_nothing_raised { c = @e.converter('foo', 'fuga') }
90
- assert_equal "HOGE:foo:FUGA", c.convert("foo")
91
- end
92
-
93
- def test_alias_share
94
- assert_nil @e.alias('foo', 'hoge')
95
- @e.add_converter('hoge', 'buyo', 10) { |s| "HOGE:#{s}:BUYO" }
96
- c = nil
97
- assert_nothing_raised { c = @e.converter('foo', 'buyo') }
98
- assert_equal "HOGE:foo:BUYO", c.convert("foo")
99
- end
100
-
101
- def test_alias_chain
102
- assert_nil @e.alias('foo', 'hoge')
103
- assert_nil @e.alias('bar', 'foo')
104
- assert_equal EUC, @e.kcode('bar')
105
- c = nil
106
- assert_nothing_raised { c = @e.converter('bar', 'fuga') }
107
- assert_equal "HOGE:foo:FUGA", c.convert("foo")
108
- end
109
-
110
- def test_alias_caseinsensitive
111
- assert_nil @e.alias('FOO', 'hoge')
112
- assert_equal EUC, @e.kcode('foo')
113
- c = nil
114
- assert_nothing_raised { c = @e.converter('foo', 'fuga') }
115
- assert_equal "HOGE:foo:FUGA", c.convert("foo")
116
- end
117
-
118
- def test_alias_doubled
119
- assert_nil @e.alias('foo', 'hoge')
120
- assert_raises(EncodingError) { @e.alias('foo', 'fuga') }
121
- end
122
-
123
- def test_alias_doubled_2
124
- assert_raises(EncodingError) { @e.alias('fuga', 'hoge') }
125
- end
126
-
127
- def test_alias_doubled_3
128
- assert_raises(EncodingError) { @e.alias('hoge', 'hoge') }
129
- end
130
-
131
- def test_alias_undeclared
132
- assert_raises(EncodingError) { @e.alias('foo', 'bar') }
133
- end
134
-
135
-
136
- def test_kcode
137
- assert_equal EUC, @e.kcode('hoge')
138
- assert_equal SJIS, @e.kcode('fuga')
139
- assert_equal NONE, @e.kcode('buyo')
140
- end
141
-
142
- def test_kcode_undeclared
143
- assert_equal NONE, @e.kcode('foo')
144
- end
145
-
146
- def test_kcode_caseinsensitive
147
- assert_equal EUC, @e.kcode('HOGE')
148
- assert_equal SJIS, @e.kcode('FUGA')
149
- assert_equal NONE, @e.kcode('BUYO')
150
- end
151
-
152
-
153
- def test_set_kcode_e
154
- assert_equal NONE, @e.kcode('buyo')
155
- assert_equal EUC, @e.set_kcode('buyo', 'e')
156
- assert_equal EUC, @e.kcode('buyo')
157
- end
158
-
159
- def test_set_kcode_u
160
- assert_equal NONE, @e.kcode('buyo')
161
- assert_equal UTF8, @e.set_kcode('buyo', 'u')
162
- assert_equal UTF8, @e.kcode('buyo')
163
- end
164
-
165
- def test_set_kcode_s
166
- assert_equal NONE, @e.kcode('buyo')
167
- assert_equal SJIS, @e.set_kcode('buyo', 's')
168
- assert_equal SJIS, @e.kcode('buyo')
169
- end
170
-
171
- def test_set_kcode_n
172
- assert_equal NONE, @e.kcode('buyo')
173
- assert_equal NONE, @e.set_kcode('buyo', 'n')
174
- assert_equal NONE, @e.kcode('buyo')
175
- end
176
-
177
- def test_set_kcode_emp
178
- assert_equal NONE, @e.kcode('buyo')
179
- assert_equal nil, @e.set_kcode('buyo', '')
180
- assert_equal nil, @e.kcode('buyo')
181
- end
182
-
183
- def test_set_kcode_nil
184
- assert_equal NONE, @e.kcode('buyo')
185
- assert_equal nil, @e.set_kcode('buyo', nil)
186
- assert_equal nil, @e.kcode('buyo')
187
- end
188
-
189
- def test_set_kcode_reset
190
- assert_nothing_raised { @e.set_kcode('hoge', 'e') }
191
- assert_nothing_raised { @e.set_kcode('fuga', 's') }
192
- end
193
-
194
- def test_set_kcode_conflict
195
- assert_raises(EncodingError) { @e.set_kcode('hoge', 'u') }
196
- assert_raises(EncodingError) { @e.set_kcode('fuga', 'u') }
197
- end
198
-
199
- def test_set_kcode_conflict_2
200
- assert_equal NONE, @e.kcode('buyo')
201
- assert_nothing_raised { @e.set_kcode 'buyo', 'e' }
202
- assert_equal EUC, @e.kcode('buyo')
203
- assert_raises(EncodingError) { @e.set_kcode('buyo', 'n') }
204
- end
205
-
206
- def test_set_kcode_conflict_nil
207
- assert_equal NONE, @e.kcode('buyo')
208
- assert_nothing_raised { @e.set_kcode 'buyo', 'n' }
209
- assert_equal NONE, @e.kcode('buyo')
210
- assert_raises(EncodingError) { @e.set_kcode('buyo', 'e') }
211
- end
212
-
213
- def test_set_kcode_caseinsensitive
214
- @e.set_kcode 'Buyo', 'E'
215
- assert_equal EUC, @e.kcode('buyo')
216
- assert_raises(EncodingError) { @e.set_kcode('BUYO', 's') }
217
- end
218
-
219
-
220
- def test_converter
221
- c = @e.converter('hoge', 'fuga')
222
- assert_kind_of XMLScan::SimpleConverter, c
223
- assert_equal "HOGE:foo:FUGA", c.convert('foo')
224
- assert_equal '', c.finish
225
- c = @e.converter('fuga', 'buyo')
226
- assert_kind_of FugaConverter, c
227
- assert_equal "FUGA:foo:BUYO", c.convert('foo')
228
- assert_equal ":bar:BUYO", c.convert('bar')
229
- assert_equal 'FOOBAR', c.finish
230
- end
231
-
232
- def test_converter_same
233
- assert_nil @e.converter('hoge', 'hoge')
234
- assert_nil @e.converter('fuga', 'fuga')
235
- end
236
-
237
- def test_converter_unregistered
238
- assert_raises(EncodingError) { @e.converter('hoge', 'buyo') }
239
- assert_raises(EncodingError) { @e.converter('buyo', 'hoge') }
240
- assert_raises(EncodingError) { @e.converter('fuga', 'hoge') }
241
- assert_raises(EncodingError) { @e.converter('foo', 'bar') }
242
- end
243
-
244
- def test_converter_caseinsensitive
245
- assert_nothing_raised { @e.converter('HOGE', 'fuGA') }
246
- assert_raises(EncodingError) { @e.converter('HogE', 'BuYo') }
247
- end
248
-
249
-
250
- def test_add_converter
251
- assert_nil @e.add_converter('buyo', 'foo', 0) { |s| "BUYO:#{s}:FOO" }
252
- c = nil
253
- assert_nothing_raised { c = @e.converter('buyo', 'foo') }
254
- assert_equal "BUYO:foo:FOO", c.convert("foo")
255
- end
256
-
257
- def test_add_converter_proc
258
- assert_nil @e.add_converter('hoge', 'buyo', 20) { |s| "HOGE:#{s}:BUYO" }
259
- c = @e.converter('hoge', 'buyo')
260
- assert_kind_of XMLScan::SimpleConverter, c
261
- assert_equal "HOGE:foo:BUYO", c.convert('foo')
262
- end
263
-
264
- def test_add_converter_proc_2
265
- assert_nil @e.add_converter('hoge', 'buyo', 20, proc{|s| "HOGE:#{s}:BUYO"})
266
- c = @e.converter('hoge', 'buyo')
267
- assert_kind_of XMLScan::SimpleConverter, c
268
- assert_equal "HOGE:foo:BUYO", c.convert('foo')
269
- end
270
-
271
- def test_add_converter_klass
272
- assert_nil @e.add_converter('hoge', 'buyo', 20, FugaConverter)
273
- c = @e.converter('hoge', 'buyo')
274
- assert_kind_of FugaConverter, c
275
- assert_equal "FUGA:foo:BUYO", c.convert('foo')
276
- end
277
-
278
- def test_add_converter_argerror
279
- assert_raises(ArgumentError) { @e.add_converter('hoge', 'buyo', 20) }
280
- assert_raises(ArgumentError) {
281
- @e.add_converter('hoge', 'buyo', 20, FugaConverter) { }
282
- }
283
- end
284
-
285
- def test_add_converter_invalid
286
- assert_nil @e.add_converter('hoge', 'buyo', 20, Object.new)
287
- assert_raises(NoMethodError) { @e.converter('hoge', 'buyo') }
288
- end
289
-
290
- def test_add_converter_heavier
291
- assert_nil @e.add_converter('hoge', 'fuga', 20) { |s| "hOGE:#{s}:fUGA" }
292
- c = @e.converter('hoge', 'fuga')
293
- assert_equal "HOGE:foo:FUGA", c.convert("foo")
294
- end
295
-
296
- def test_add_converter_lighter
297
- assert_nil @e.add_converter('hoge', 'fuga', 0) { |s| "hoge:#{s}:fuga" }
298
- c = @e.converter('hoge', 'fuga')
299
- assert_equal "hoge:foo:fuga", c.convert("foo")
300
- end
301
-
302
- def test_add_converter_as_heavy_as
303
- assert_nil @e.add_converter('hoge', 'fuga', 10) { |s| "hOGe:#{s}:fUGa" }
304
- c = @e.converter('hoge', 'fuga')
305
- assert_equal "hOGe:foo:fUGa", c.convert("foo")
306
- end
307
-
308
- def test_add_converter_same_encoding
309
- assert_raises(EncodingError) { @e.add_converter('hoge', 'hoge', 10){} }
310
- end
311
-
312
- def test_add_converter_same_encoding_alias
313
- @e.alias 'foo', 'hoge'
314
- assert_raises(EncodingError) { @e.add_converter('hoge', 'foo', 10){} }
315
- assert_raises(EncodingError) { @e.add_converter('foo', 'hoge', 10){} }
316
- end
317
-
318
- def test_add_converter_caseinsensitive
319
- assert_nil @e.add_converter('HOGE', 'BUYO', 10) { |s| "HOGE:#{s}:BUYO" }
320
- c = nil
321
- assert_nothing_raised { c = @e.converter('hoge', 'buyo') }
322
- assert_equal 'HOGE:foo:BUYO', c.convert('foo')
323
- end
324
-
325
-
326
- def test_converter3
327
- c1, kcode, c2 = @e.converter3('hoge', 'buyo')
328
- assert_equal "HOGE:foo:FUGA", c1.convert('foo')
329
- assert_equal SJIS, kcode
330
- assert_equal "FUGA:bar:BUYO", c2.convert('bar')
331
- end
332
-
333
- def test_converter3_2
334
- c1, kcode, c2 = @e.converter3('hoge', nil)
335
- assert_equal nil, c1
336
- assert_equal EUC, kcode
337
- assert_equal nil, c2
338
- c1, kcode, c2 = @e.converter3('hoge')
339
- assert_equal nil, c1
340
- assert_equal EUC, kcode
341
- assert_equal nil, c2
342
- end
343
-
344
- def test_converter3_3
345
- c1, kcode, c2 = @e.converter3('hoge', 'fuga')
346
- if c1 then
347
- assert_equal "HOGE:foo:FUGA", c1.convert('foo')
348
- assert_equal SJIS, kcode
349
- assert_equal nil, c2
350
- else
351
- assert_equal nil, c1
352
- assert_equal EUC, kcode
353
- assert_equal "HOGE:foo:FUGA", c2.convert('foo')
354
- end
355
- end
356
-
357
- def test_converter3_4
358
- c1, kcode, c2 = @e.converter3('fuga', 'buyo')
359
- assert_equal nil, c1
360
- assert_equal SJIS, kcode
361
- assert_equal "FUGA:foo:BUYO", c2.convert('foo')
362
- end
363
-
364
- def test_converter3_5
365
- c1, kcode, c2 = @e.converter3('buyo')
366
- assert_equal nil, c1
367
- assert_equal NONE, kcode
368
- assert_equal nil, c2
369
- end
370
-
371
- def test_converter3_6
372
- assert_raises(EncodingError) { @e.converter3('buyo', 'hoge') }
373
- end
374
-
375
- def test_conveter3_select
376
- @e.add_converter('hoge', 'foo', 8) { |s| "HOGE:#{s}:FOO" }
377
- @e.add_converter('foo', 'buyo', 10) { |s| "FOO:#{s}:BUYO" }
378
- @e.set_kcode 'foo', 'U'
379
- c1, kcode, c2 = @e.converter3('hoge', 'buyo')
380
- assert_equal "HOGE:foo:FOO", c1.convert('foo')
381
- assert_equal UTF8, kcode
382
- assert_equal "FOO:bar:BUYO", c2.convert('bar')
383
- end
384
-
385
- def test_conveter3_select_2
386
- @e.add_converter('hoge', 'foo', 8) { |s| "HOGE:#{s}:FOO" }
387
- @e.set_kcode 'foo', 'U'
388
- c1, kcode, c2 = @e.converter3('hoge', 'buyo')
389
- assert_equal "HOGE:foo:FUGA", c1.convert('foo')
390
- assert_equal SJIS, kcode
391
- assert_equal "FUGA:bar:BUYO", c2.convert('bar')
392
- end
393
-
394
- def test_conveter3_select_3
395
- @e.add_converter('hoge', 'foo', 8) { |s| "HOGE:#{s}:FOO" }
396
- @e.add_converter('foo', 'buyo', 20) { |s| "FOO:#{s}:BUYO" }
397
- @e.set_kcode 'foo', 'U'
398
- c1, kcode, c2 = @e.converter3('hoge', 'buyo')
399
- assert_equal "HOGE:foo:FUGA", c1.convert('foo')
400
- assert_equal SJIS, kcode
401
- assert_equal "FUGA:bar:BUYO", c2.convert('bar')
402
- end
403
-
404
- def test_conveter3_select_4
405
- @e.add_converter('hoge', 'foo', 20) { |s| "HOGE:#{s}:FOO" }
406
- @e.add_converter('foo', 'buyo', 8) { |s| "FOO:#{s}:BUYO" }
407
- @e.set_kcode 'foo', 'U'
408
- c1, kcode, c2 = @e.converter3('hoge', 'buyo')
409
- assert_equal "HOGE:foo:FUGA", c1.convert('foo')
410
- assert_equal SJIS, kcode
411
- assert_equal "FUGA:bar:BUYO", c2.convert('bar')
412
- end
413
-
414
- def test_conveter3_select_5
415
- @e.add_converter('hoge', 'foo', 5) { |s| "HOGE:#{s}:FOO" }
416
- @e.add_converter('foo', 'buyo', 5) { |s| "FOO:#{s}:BUYO" }
417
- @e.set_kcode 'foo', nil
418
- c1, kcode, c2 = @e.converter3('hoge', 'buyo')
419
- assert_equal "HOGE:foo:FUGA", c1.convert('foo')
420
- assert_equal SJIS, kcode
421
- assert_equal "FUGA:bar:BUYO", c2.convert('bar')
422
- end
423
-
424
- def test_conveter3_select_6
425
- @e.add_converter('hoge', 'foo', 5) { |s| "HOGE:#{s}:FOO" }
426
- @e.add_converter('foo', 'buyo', 5) { |s| "FOO:#{s}:BUYO" }
427
- c1, kcode, c2 = @e.converter3('hoge', 'buyo')
428
- assert_equal "HOGE:foo:FUGA", c1.convert('foo')
429
- assert_equal SJIS, kcode
430
- assert_equal "FUGA:bar:BUYO", c2.convert('bar')
431
- end
432
-
433
- end
434
-
435
-
436
-
437
-
438
- load "#{File.dirname($0)}/runtest.rb" if __FILE__ == $0