mkrf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +2 -0
  2. data/MIT-LICENSE +7 -0
  3. data/README +54 -0
  4. data/Rakefile +107 -0
  5. data/lib/mkrf.rb +4 -0
  6. data/lib/mkrf/availability.rb +219 -0
  7. data/lib/mkrf/generator.rb +146 -0
  8. data/test/abstract_unit.rb +4 -0
  9. data/test/fixtures/down_a_directory/header_down_a_directory.h +1 -0
  10. data/test/fixtures/stdmkrf.h +1 -0
  11. data/test/sample_files/libtrivial/Rakefile +31 -0
  12. data/test/sample_files/libtrivial/extconf.rb +3 -0
  13. data/test/sample_files/libtrivial/lib/libtrivial.c +5 -0
  14. data/test/sample_files/libtrivial/lib/libtrivial.o +0 -0
  15. data/test/sample_files/libtrivial/libtrivial_so.bundle +0 -0
  16. data/test/sample_files/libtrivial/mkrf.log +1 -0
  17. data/test/sample_files/libxml-ruby-0.3.8/CHANGELOG +74 -0
  18. data/test/sample_files/libxml-ruby-0.3.8/LICENSE +22 -0
  19. data/test/sample_files/libxml-ruby-0.3.8/README +144 -0
  20. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/cbg.c +76 -0
  21. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/extconf.rb +49 -0
  22. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.c +86 -0
  23. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.h +82 -0
  24. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.rb +107 -0
  25. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/mkrf.log +1 -0
  26. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/old_extconf.rb +95 -0
  27. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.c +372 -0
  28. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.h +21 -0
  29. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.c +224 -0
  30. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.h +21 -0
  31. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.c +1159 -0
  32. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.h +27 -0
  33. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.c +168 -0
  34. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.h +17 -0
  35. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.c +167 -0
  36. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.h +21 -0
  37. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.c +2139 -0
  38. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.h +28 -0
  39. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.c +248 -0
  40. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.h +26 -0
  41. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.c +153 -0
  42. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.h +21 -0
  43. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.c +1417 -0
  44. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.h +31 -0
  45. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.c +715 -0
  46. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.h +22 -0
  47. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.c +426 -0
  48. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.h +52 -0
  49. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.c +142 -0
  50. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.h +16 -0
  51. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.c +43 -0
  52. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.h +12 -0
  53. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.c +20 -0
  54. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.h +13 -0
  55. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.c +363 -0
  56. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.h +24 -0
  57. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.c +125 -0
  58. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.h +24 -0
  59. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.c +100 -0
  60. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.h +27 -0
  61. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.c +21 -0
  62. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.h +18 -0
  63. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/sax_parser_callbacks.inc +202 -0
  64. data/test/sample_files/syck-0.55/CHANGELOG +186 -0
  65. data/test/sample_files/syck-0.55/COPYING +54 -0
  66. data/test/sample_files/syck-0.55/Makefile +582 -0
  67. data/test/sample_files/syck-0.55/Makefile.am +5 -0
  68. data/test/sample_files/syck-0.55/Makefile.in +582 -0
  69. data/test/sample_files/syck-0.55/README +105 -0
  70. data/test/sample_files/syck-0.55/README.BYTECODE +484 -0
  71. data/test/sample_files/syck-0.55/README.EXT +444 -0
  72. data/test/sample_files/syck-0.55/RELEASE +123 -0
  73. data/test/sample_files/syck-0.55/TODO +25 -0
  74. data/test/sample_files/syck-0.55/aclocal.m4 +883 -0
  75. data/test/sample_files/syck-0.55/bootstrap +7 -0
  76. data/test/sample_files/syck-0.55/config.h +79 -0
  77. data/test/sample_files/syck-0.55/config.h.in +78 -0
  78. data/test/sample_files/syck-0.55/config.status +1197 -0
  79. data/test/sample_files/syck-0.55/config/README +14 -0
  80. data/test/sample_files/syck-0.55/config/depcomp +529 -0
  81. data/test/sample_files/syck-0.55/config/install-sh +323 -0
  82. data/test/sample_files/syck-0.55/config/missing +357 -0
  83. data/test/sample_files/syck-0.55/configure +6728 -0
  84. data/test/sample_files/syck-0.55/configure.in +36 -0
  85. data/test/sample_files/syck-0.55/ext/ruby/CHANGELOG +303 -0
  86. data/test/sample_files/syck-0.55/ext/ruby/README +400 -0
  87. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/MANIFEST +1 -0
  88. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/bytecode.c +1170 -0
  89. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/emitter.c +1224 -0
  90. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/extconf.rb +10 -0
  91. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.c +1894 -0
  92. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.h +79 -0
  93. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/handler.c +174 -0
  94. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/implicit.c +2989 -0
  95. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/mkrf.log +1 -0
  96. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/node.c +407 -0
  97. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/rubyext.c +2385 -0
  98. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.c +504 -0
  99. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.h +458 -0
  100. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/token.c +2707 -0
  101. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yaml2byte.c +250 -0
  102. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yamlbyte.h +170 -0
  103. data/test/sample_files/syck-0.55/ext/ruby/install.rb +1022 -0
  104. data/test/sample_files/syck-0.55/ext/ruby/lib/okay.rb +161 -0
  105. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/news.rb +69 -0
  106. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/rpc.rb +434 -0
  107. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml.rb +436 -0
  108. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/baseemitter.rb +247 -0
  109. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/basenode.rb +216 -0
  110. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/compat.rb +26 -0
  111. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/constants.rb +45 -0
  112. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/dbm.rb +111 -0
  113. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/emitter.rb +107 -0
  114. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/encoding.rb +33 -0
  115. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/error.rb +34 -0
  116. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/rubytypes.rb +438 -0
  117. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/store.rb +29 -0
  118. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stream.rb +40 -0
  119. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb +83 -0
  120. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/syck.rb +19 -0
  121. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/tag.rb +86 -0
  122. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/types.rb +188 -0
  123. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/yamlnode.rb +54 -0
  124. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/ypath.rb +52 -0
  125. data/test/sample_files/syck-0.55/ext/ruby/lib/yod.rb +1168 -0
  126. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-modules.rb +27 -0
  127. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-sample.rb +336 -0
  128. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-validate.rb +341 -0
  129. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-client.rb +51 -0
  130. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-server.rb +85 -0
  131. data/test/sample_files/syck-0.55/ext/ruby/samples/yaml-sortHashKeys.rb +128 -0
  132. data/test/sample_files/syck-0.55/ext/ruby/tests/basic.rb +1653 -0
  133. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsAnchorAlias.yml +51 -0
  134. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBasicTests.yml +282 -0
  135. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockMapping.yml +78 -0
  136. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockSequence.yml +0 -0
  137. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsDocumentSeparator.yml +102 -0
  138. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsErrorTests.yml +23 -0
  139. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFlowCollections.yml +73 -0
  140. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFoldedScalars.yml +215 -0
  141. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsMapInSeq.yml +0 -0
  142. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsNullsAndEmpties.yml +66 -0
  143. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsRubyTests.yml +182 -0
  144. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsSpecificationExamples.yml +2699 -0
  145. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsTypeTransfers.yml +265 -0
  146. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsYpath.yml +221 -0
  147. data/test/sample_files/syck-0.55/ext/ruby/yts/cookbook.rb +159 -0
  148. data/test/sample_files/syck-0.55/ext/ruby/yts/index.yml +10 -0
  149. data/test/sample_files/syck-0.55/ext/ruby/yts/yts.rb +193 -0
  150. data/test/sample_files/syck-0.55/lib/Makefile +497 -0
  151. data/test/sample_files/syck-0.55/lib/Makefile.am +27 -0
  152. data/test/sample_files/syck-0.55/lib/Makefile.in +497 -0
  153. data/test/sample_files/syck-0.55/lib/bytecode.c +1170 -0
  154. data/test/sample_files/syck-0.55/lib/bytecode.re +525 -0
  155. data/test/sample_files/syck-0.55/lib/emitter.c +1224 -0
  156. data/test/sample_files/syck-0.55/lib/gram.c +1894 -0
  157. data/test/sample_files/syck-0.55/lib/gram.h +79 -0
  158. data/test/sample_files/syck-0.55/lib/gram.output +2005 -0
  159. data/test/sample_files/syck-0.55/lib/gram.y +481 -0
  160. data/test/sample_files/syck-0.55/lib/handler.c +174 -0
  161. data/test/sample_files/syck-0.55/lib/implicit.c +2989 -0
  162. data/test/sample_files/syck-0.55/lib/implicit.re +206 -0
  163. data/test/sample_files/syck-0.55/lib/node.c +407 -0
  164. data/test/sample_files/syck-0.55/lib/syck.c +504 -0
  165. data/test/sample_files/syck-0.55/lib/syck.h +458 -0
  166. data/test/sample_files/syck-0.55/lib/syck_st.c +577 -0
  167. data/test/sample_files/syck-0.55/lib/syck_st.h +46 -0
  168. data/test/sample_files/syck-0.55/lib/token.c +2707 -0
  169. data/test/sample_files/syck-0.55/lib/token.re +1139 -0
  170. data/test/sample_files/syck-0.55/lib/yaml2byte.c +250 -0
  171. data/test/sample_files/syck-0.55/lib/yamlbyte.h +170 -0
  172. data/test/sample_files/syck-0.55/stamp-h1 +1 -0
  173. data/test/sample_files/syck-0.55/tests/Basic.c +141 -0
  174. data/test/sample_files/syck-0.55/tests/CuTest.c +294 -0
  175. data/test/sample_files/syck-0.55/tests/CuTest.h +84 -0
  176. data/test/sample_files/syck-0.55/tests/Emit.c +87 -0
  177. data/test/sample_files/syck-0.55/tests/Makefile +480 -0
  178. data/test/sample_files/syck-0.55/tests/Makefile.am +13 -0
  179. data/test/sample_files/syck-0.55/tests/Makefile.in +480 -0
  180. data/test/sample_files/syck-0.55/tests/Parse.c +208 -0
  181. data/test/sample_files/syck-0.55/tests/YTS.c +2310 -0
  182. data/test/sample_files/syck-0.55/tests/YTS.c.erb +326 -0
  183. data/test/sample_files/syck-0.55/tests/YTS.c.rb +44 -0
  184. data/test/test_availability.rb +68 -0
  185. data/test/test_generator.rb +74 -0
  186. metadata +252 -0
@@ -0,0 +1,51 @@
1
+ #
2
+ # Simple client to read metadata from whytheluckystiff.net's
3
+ # demo !okay/rpc server.
4
+ #
5
+ require 'okay/rpc'
6
+
7
+ host = 'whytheluckystiff.net'
8
+ c = Okay::RPC::Client.new( host )
9
+
10
+ # Wrapping strings for display
11
+ class String
12
+ def wordwrap( len )
13
+ gsub( /\n/, "\n\n" ).gsub( /(.{1,#{len}})(\s+|$)/, "\\1\n" )
14
+ end
15
+ end
16
+
17
+ puts "** Sample Client for !okay/rpc using client version #{Okay::RPC::VERSION} **"
18
+ puts "** Using !okay/rpc server at #{host} **"
19
+ puts "-- system.about() --"
20
+ puts
21
+ about = c.call( 'system.about' )
22
+ if about.is_a? Okay::RPC::Fault
23
+ puts " Fault: " + about.inspect
24
+ exit
25
+ end
26
+
27
+ puts " Server: #{ about['name'] }"
28
+ puts " Version: #{ about['version'] }"
29
+ puts
30
+ puts about['about'].wordwrap( 30 ).gsub!( /^/, ' ' )
31
+ puts
32
+
33
+ puts "-- system.listMethods() --"
34
+ puts
35
+ methods = c.call( 'system.listMethods' )
36
+ puts "** #{methods.length} methods available on server **"
37
+ puts "** Requesting method signatures and docs **"
38
+ methods.each { |m|
39
+ c.qcall( 'system.methodSignature', m )
40
+ c.qcall( 'system.methodHelp', m )
41
+ }
42
+ methodSigs = c.qrun.documents
43
+
44
+ methods.each { |m|
45
+ sig = methodSigs.shift
46
+ help = methodSigs.shift
47
+ puts
48
+ puts "-- !#{sig.shift} #{m}(#{sig.collect { |p| '!' + p }.join( ', ' )}) --"
49
+ puts help.wordwrap( 30 ).gsub( /^/, ' ' )
50
+ }
51
+
@@ -0,0 +1,85 @@
1
+ #
2
+ # The demo server from whytheluckystiff.net.
3
+ #
4
+ require 'okay/rpc'
5
+
6
+ s = Okay::RPC::ModRubyServer.new
7
+
8
+ s.name = "The !okay/rpc Demo Server"
9
+ s.add_author( 'why the lucky stiff', 'okay-rpc@whytheluckystiff.net', 'http://whytheluckystiff.net/' )
10
+ s.about = <<EOY
11
+
12
+ Welcome to the !okay/rpc server at whytheluckystiff.net.
13
+ This server acts as an example to the inhabited world
14
+ concerning the possibilities of using YAML for remote
15
+ procedure calls.
16
+
17
+ Yeah, so, it's a real treat having you use the
18
+ system.about method. I can't imagine what it must
19
+ feel like from your end. Provocative, I'm sure.
20
+ Issuing the single statement and getting back this
21
+ gorgeous reply. Yes, life has started for you in
22
+ a very real way, hasn't it?
23
+
24
+ EOY
25
+
26
+ # currentTime.getCurrentTime
27
+ s.add_handler( "currentTime.getCurrentTime", %w(time), "Returns the current server time." ) { |meth|
28
+ Time.now
29
+ }
30
+
31
+ # examples.getStateName
32
+ stateName = [
33
+ "Alabama", "Alaska", "Arizona", "Arkansas", "California",
34
+ "Colorado", "Columbia", "Connecticut", "Delaware", "Florida",
35
+ "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas",
36
+ "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan",
37
+ "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada",
38
+ "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina",
39
+ "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island",
40
+ "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont",
41
+ "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"
42
+ ]
43
+ s.add_handler( "examples.getStateName", %w(str int), "When passed an integer between 1 and 51 returns the name of a US state, where the integer is the index of that state name in an alphabetic order." ) { |meth|
44
+ stateName[ meth.params[0] - 1 ]
45
+ }
46
+
47
+ # examples.sortByAge
48
+ s.add_handler( "examples.sortByAge", %w(seq seq), "Send this method an array of [str, int] sequences and the array will be returned with the entries sorted by their numbers." ) { |meth|
49
+ meth.params[0].sort { |x,y|
50
+ x[1] <=> y[1]
51
+ }
52
+ }
53
+
54
+ # examples.addtwo
55
+ s.add_handler( "examples.addtwo", %w(int int int), "Add two integers together and return the result." ) { |meth|
56
+ meth.params[0] + meth.params[1]
57
+ }
58
+
59
+ # examples.addtwofloat
60
+ s.add_handler( "examples.addtwofloat", %w(float float float), "Add two floats together and return the result." ) { |meth|
61
+ meth.params[0] + meth.params[1]
62
+ }
63
+
64
+ # examples.stringecho
65
+ s.add_handler( "examples.stringecho", %w(str str), "Accepts a string parameter, returns the string." ) { |meth|
66
+ meth.params[0]
67
+ }
68
+
69
+ # examples.echo
70
+ s.add_handler( "examples.echo", %w(str str), "Accepts a string parameter, returns the entire incoming payload." ) { |meth|
71
+ meth
72
+ }
73
+
74
+ # examples.base64
75
+ s.add_handler( "examples.base64", %w(str str), "Accepts a base64 parameter and returns it decoded as a string." ) { |meth|
76
+ [meth.params[0]].pack( "m" )
77
+ }
78
+
79
+ # examples.invertBooleans
80
+ s.add_handler( "examples.invertBooleans", %w(seq seq), "Accepts an array of booleans, and returns them inverted." ) { |meth|
81
+ meth.params[0].collect{ |x| !x }
82
+ }
83
+
84
+ s.serve
85
+
@@ -0,0 +1,128 @@
1
+ require 'yaml'
2
+
3
+ class String
4
+ def wordwrap( len )
5
+ gsub( /\n/, "\n\n" ).gsub( /.{#{len},}?\s+/, "\\0\n" )
6
+ end
7
+ end
8
+
9
+ puts "** Ordering YAML mapping keys **"
10
+ puts
11
+
12
+ #
13
+ # Robert Feldt wrote:
14
+ #
15
+ # > ...when I use Yaml for ini files I'd like to be able to
16
+ # > spec an order for map pairs to be serialized in. Obviously Ruby hashes has
17
+ # > no garantuee for this but are there any plans on supporting this? If not
18
+ # > I'll whip something up myself; I really wanna make sure the most important
19
+ # > stuff comes out on top...
20
+ #
21
+ # I had three suggestions:
22
+ #
23
+ # 1. When using objects, you can specify the ordering of your properties
24
+ # explicitly by defining a `to_yaml_properties' method.
25
+ #
26
+
27
+ class Instrument
28
+
29
+ attr_accessor :name, :key, :is_woodwind
30
+
31
+ def initialize( n, k, ww )
32
+ @name, @key, @is_woodwind = n, k, ww
33
+ end
34
+
35
+ def to_yaml_properties
36
+ [ '@name', '@key', '@is_woodwind' ]
37
+ end
38
+
39
+ end
40
+
41
+ puts "-- 1. Instrument object --"
42
+ test1 = Instrument.new( 'Alto Saxophone', 'Eb', true )
43
+ puts test1.inspect.wordwrap( 30 ).gsub( /^/, ' ' )
44
+ puts
45
+
46
+ puts "** With ordered properties **"
47
+ puts test1.to_yaml.gsub( /^/, ' ' )
48
+ puts
49
+
50
+ #
51
+ # 2. The same can't be done for Hashes because the key set isn't
52
+ # predictable. But if the :SortKeys method is called, then
53
+ # the Hash will be sorted with Hash#sort. You could define a
54
+ # singleton `sort' method to sort certain Hashes.
55
+ #
56
+
57
+ test2 = { 'name' => 'Alto Saxophone', 'key' => 'Eb',
58
+ 'is_woodwind' => true }
59
+ def test2.sort
60
+ order = [ 'name', 'key', 'is_woodwind' ]
61
+ super { |a, b| order.index( a[0] ) <=> order.index( b[0] ) }
62
+ end
63
+
64
+ puts "-- 2. Instrument hash --"
65
+ puts test2.inspect.wordwrap( 30 ).gsub( /^/, ' ' )
66
+ puts
67
+
68
+ puts "** With ordered keys **"
69
+ puts test2.to_yaml( :SortKeys => true ).gsub( /^/, ' ' )
70
+ puts
71
+
72
+ #
73
+ # Alternatively, you could define a singleton `to_a' to sort
74
+ # correctly and skip the :SortKeys option.
75
+ #
76
+ # 3. Finally, the YAML spec now defines an !omap type. This type is
77
+ # an ordered mapping with unique keys. YAML.rb will load this
78
+ # into a Hash-like class.
79
+ #
80
+
81
+ test3 = YAML::Omap[
82
+ 'name', 'Alto Saxophone',
83
+ 'key', 'Eb',
84
+ 'is_woodwind', true
85
+ ]
86
+
87
+ puts "-- 3. Instrument Omap --"
88
+ puts test3.inspect.wordwrap( 30 ).gsub( /^/, ' ' )
89
+ puts
90
+
91
+ puts "** With ordered keys **"
92
+ puts test3.to_yaml.gsub( /^/, ' ' )
93
+ puts
94
+
95
+ #
96
+ # Robert's answer was great. He used a mixin to add a singleton `to_a'
97
+ # method, which allows him to easily sort many hashes.
98
+ #
99
+
100
+ module SortableToAKeys
101
+
102
+ def key_order=( keys )
103
+ @__key_order = keys
104
+ end
105
+
106
+ def to_a
107
+ ks, out = self.keys, []
108
+ (@__key_order + (ks - @__key_order)).each do |key|
109
+ out << [key, self[key]] if ks.include?(key)
110
+ end
111
+ out
112
+ end
113
+
114
+ end
115
+
116
+ test4 = { 'name' => 'Alto Saxophone', 'key' => 'Eb',
117
+ 'is_woodwind' => true }
118
+ puts "-- 4. Instrument SortableToAKeys --"
119
+ puts test4.inspect.wordwrap( 30 ).gsub( /^/, ' ' )
120
+ puts
121
+
122
+ test4.extend SortableToAKeys
123
+ test4.key_order = [ 'name', 'key', 'is_woodwind' ]
124
+
125
+ puts "** With ordered keys **"
126
+ puts test4.to_yaml.gsub( /^/, ' ' )
127
+ puts
128
+
@@ -0,0 +1,1653 @@
1
+ # vim:sw=4:ts=4
2
+ # $Id: basic.rb,v 1.23 2005/02/09 01:06:30 why Exp $
3
+ #
4
+ require 'runit/testcase'
5
+ require 'runit/cui/testrunner'
6
+ require 'yaml'
7
+
8
+ # [ruby-core:01946]
9
+ module YAML_Tests
10
+ StructTest = Struct::new( :c )
11
+ end
12
+
13
+ class YAML_Unit_Tests < RUNIT::TestCase
14
+ #
15
+ # Convert between YAML and the object to verify correct parsing and
16
+ # emitting
17
+ #
18
+ def assert_to_yaml( obj, yaml )
19
+ assert_equal( obj, YAML::load( yaml ) )
20
+ # assert_equal( obj, YAML::parse( yaml ).transform )
21
+ assert_equal( obj, YAML::load( obj.to_yaml ) )
22
+ # assert_equal( obj, YAML::parse( obj.to_yaml ).transform )
23
+ # assert_equal( obj, YAML::load(
24
+ # obj.to_yaml( :UseVersion => true, :UseHeader => true, :SortKeys => true )
25
+ # ) )
26
+
27
+ # yb = YAML::Parser.new
28
+ # yb.resolver = YAML.resolver
29
+ # yb.input = :bytecode
30
+ # assert_equal( obj, yb.load( YAML::Syck::compile( yaml ) ) )
31
+ end
32
+
33
+ #
34
+ # Test bytecode parser
35
+ #
36
+ def assert_bytecode( obj, yaml )
37
+ # assert_equal( obj, YAML::Syck::Parser.new( :Input => :Bytecode ).load( yaml ) )
38
+ end
39
+
40
+ #
41
+ # Test parser only
42
+ #
43
+ def assert_parse_only( obj, yaml )
44
+ assert_equal( obj, YAML::load( yaml ) )
45
+ # assert_equal( obj, YAML::parse( yaml ).transform )
46
+ # assert_equal( obj, YAML::Syck::Parser.new( :Input => :Bytecode ).load( YAML::Syck::compile( yaml ) ) )
47
+ end
48
+
49
+ def assert_path_segments( path, segments )
50
+ YAML::YPath.each_path( path ) { |choice|
51
+ assert_equal( choice.segments, segments.shift )
52
+ }
53
+ assert_equal( segments.length, 0, "Some segments leftover: #{ segments.inspect }" )
54
+ end
55
+
56
+ #
57
+ # Make a time with the time zone
58
+ #
59
+ def mktime( year, mon, day, hour, min, sec, usec, zone = "Z" )
60
+ usec = usec.to_s.to_f * 1000000
61
+ val = Time::utc( year.to_i, mon.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i, usec )
62
+ if zone != "Z"
63
+ hour = zone[0,3].to_i * 3600
64
+ min = zone[3,2].to_i * 60
65
+ ofs = (hour + min)
66
+ val = Time.at( val.to_f - ofs )
67
+ end
68
+ return val
69
+ end
70
+
71
+ #
72
+ # Tests modified from 00basic.t in YAML.pm
73
+ #
74
+ def test_basic_map
75
+ # Simple map
76
+ map = { 'one' => 'foo', 'three' => 'baz', 'two' => 'bar' }
77
+ assert_to_yaml(
78
+ map, <<EOY
79
+ one: foo
80
+ two: bar
81
+ three: baz
82
+ EOY
83
+ )
84
+ assert_bytecode( map, "D\nM\nSone\nSfoo\nStwo\nSbar\nSthree\nSbaz\nE\n" )
85
+ end
86
+
87
+ def test_basic_strings
88
+ # Common string types
89
+ basic = { 1 => 'simple string', 2 => 42, 3 => '1 Single Quoted String',
90
+ 4 => 'YAML\'s Double "Quoted" String', 5 => "A block\n with several\n lines.\n",
91
+ 6 => "A \"chomped\" block", 7 => "A folded\n string\n" }
92
+ assert_to_yaml(
93
+ basic, <<EOY
94
+ 1: simple string
95
+ 2: 42
96
+ 3: '1 Single Quoted String'
97
+ 4: "YAML's Double \\\"Quoted\\\" String"
98
+ 5: |
99
+ A block
100
+ with several
101
+ lines.
102
+ 6: |-
103
+ A "chomped" block
104
+ 7: >
105
+ A
106
+ folded
107
+ string
108
+ EOY
109
+ )
110
+ assert_bytecode( basic,
111
+ "D\nM\nS1\nSsimple string\nS2\nS42\nS3\nS1 Single Quoted String\nS4\nSYAML's Double \"Quoted\" String\n" +
112
+ "S5\nSA block\nN\nC with several\nN\nC lines.\nN\nS6\nSA \"chomped\" block\nS7\nSA folded\nN\nC string\nN\nE\n" )
113
+ end
114
+
115
+ #
116
+ # Test the specification examples
117
+ # - Many examples have been changes because of whitespace problems that
118
+ # caused the two to be inequivalent, or keys to be sorted wrong
119
+ #
120
+
121
+ def test_spec_simple_implicit_sequence
122
+ # Simple implicit sequence
123
+ seq = [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ]
124
+ assert_to_yaml(
125
+ seq, <<EOY
126
+ - Mark McGwire
127
+ - Sammy Sosa
128
+ - Ken Griffey
129
+ EOY
130
+ )
131
+ assert_bytecode( seq, "D\nQ\nSMark McGwire\nSSammy Sosa\nSKen Griffey\nE\n" )
132
+ end
133
+
134
+ def test_spec_simple_implicit_map
135
+ # Simple implicit map
136
+ map = { 'hr' => 65, 'avg' => 0.278, 'rbi' => 147 }
137
+ assert_to_yaml(
138
+ map, <<EOY
139
+ avg: 0.278
140
+ hr: 65
141
+ rbi: 147
142
+ EOY
143
+ )
144
+ assert_bytecode( map, "D\nM\nSavg\nS0.278\nShr\nS65\nSrbi\nS147\nE\n" )
145
+ end
146
+
147
+ def test_spec_simple_map_with_nested_sequences
148
+ # Simple mapping with nested sequences
149
+ nest = { 'american' =>
150
+ [ 'Boston Red Sox', 'Detroit Tigers', 'New York Yankees' ],
151
+ 'national' =>
152
+ [ 'New York Mets', 'Chicago Cubs', 'Atlanta Braves' ] }
153
+ assert_to_yaml(
154
+ nest, <<EOY
155
+ american:
156
+ - Boston Red Sox
157
+ - Detroit Tigers
158
+ - New York Yankees
159
+ national:
160
+ - New York Mets
161
+ - Chicago Cubs
162
+ - Atlanta Braves
163
+ EOY
164
+ )
165
+ assert_bytecode( nest, "D\nM\nSamerican\nQ\nSBoston Red Sox\nSDetroit Tigers\nSNew York Yankees\nE\n" +
166
+ "Snational\nQ\nSNew York Mets\nSChicago Cubs\nSAtlanta Braves\nE\n" )
167
+ end
168
+
169
+ def test_spec_simple_sequence_with_nested_map
170
+ # Simple sequence with nested map
171
+ nest = [
172
+ {'name' => 'Mark McGwire', 'hr' => 65, 'avg' => 0.278},
173
+ {'name' => 'Sammy Sosa', 'hr' => 63, 'avg' => 0.288}
174
+ ]
175
+ assert_to_yaml(
176
+ nest, <<EOY
177
+ -
178
+ avg: 0.278
179
+ hr: 65
180
+ name: Mark McGwire
181
+ -
182
+ avg: 0.288
183
+ hr: 63
184
+ name: Sammy Sosa
185
+ EOY
186
+ )
187
+ assert_bytecode( nest, "D\nQ\nM\nSavg\nS0.278\nShr\nS65\nSname\nSMark McGwire\nE\n" +
188
+ "M\nSavg\nS0.288\nShr\nS63\nSname\nSSammy Sosa\nE\nE\n" )
189
+ end
190
+
191
+ def test_spec_sequence_of_sequences
192
+ # Simple sequence with inline sequences
193
+ seq = [
194
+ [ 'name', 'hr', 'avg' ],
195
+ [ 'Mark McGwire', 65, 0.278 ],
196
+ [ 'Sammy Sosa', 63, 0.288 ]
197
+ ]
198
+ assert_to_yaml(
199
+ seq, <<EOY
200
+ - [ name , hr , avg ]
201
+ - [ Mark McGwire , 65 , 0.278 ]
202
+ - [ Sammy Sosa , 63 , 0.288 ]
203
+ EOY
204
+ )
205
+ assert_bytecode( seq, "D\nQ\nQ\nSname\nShr\nSavg\nE\nQ\nSMark McGwire\nS65\nS0.278\nE\n" +
206
+ "Q\nSSammy Sosa\nS63\nS0.288\nE\nE\n" )
207
+ end
208
+
209
+ def test_spec_mapping_of_mappings
210
+ # Simple map with inline maps
211
+ map = { 'Mark McGwire' =>
212
+ { 'hr' => 65, 'avg' => 0.278 },
213
+ 'Sammy Sosa' =>
214
+ { 'hr' => 63, 'avg' => 0.288 }
215
+ }
216
+ assert_to_yaml(
217
+ map, <<EOY
218
+ Mark McGwire: {hr: 65, avg: 0.278}
219
+ Sammy Sosa: {hr: 63,
220
+ avg: 0.288}
221
+ EOY
222
+ )
223
+ assert_bytecode( map, "D\nM\nSMark McGwire\nM\nShr\nS65\nSavg\nS0.278\nE\n" +
224
+ "SSammy Sosa\nM\nShr\nS63\nSavg\nS0.288\nE\nE\n" )
225
+ end
226
+
227
+ def test_ambiguous_comments
228
+ assert_to_yaml( "Call the method #dave", <<EOY )
229
+ --- "Call the method #dave"
230
+ EOY
231
+ end
232
+
233
+ def test_spec_nested_comments
234
+ # Map and sequences with comments
235
+ nest = { 'hr' => [ 'Mark McGwire', 'Sammy Sosa' ],
236
+ 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] }
237
+ assert_to_yaml(
238
+ nest, <<EOY
239
+ hr: # 1998 hr ranking
240
+ - Mark McGwire
241
+ - Sammy Sosa
242
+ rbi:
243
+ # 1998 rbi ranking
244
+ - Sammy Sosa
245
+ - Ken Griffey
246
+ EOY
247
+ )
248
+ assert_bytecode( nest, "D\nM\nShr\nc 1998 hr ranking\nQ\nSMark McGwire\nSSammy Sosa\nE\n" +
249
+ "Srbi\nc 1998 rbi ranking\nQ\nSSammy Sosa\nSKen Griffey\nE\nE\n" )
250
+ end
251
+
252
+ def test_spec_anchors_and_aliases
253
+ # Anchors and aliases
254
+ anc1 = { 'hr' =>
255
+ [ 'Mark McGwire', 'Sammy Sosa' ],
256
+ 'rbi' =>
257
+ [ 'Sammy Sosa', 'Ken Griffey' ] }
258
+ assert_to_yaml( anc1, <<EOY )
259
+ hr:
260
+ - Mark McGwire
261
+ # Name "Sammy Sosa" scalar SS
262
+ - &SS Sammy Sosa
263
+ rbi:
264
+ # So it can be referenced later.
265
+ - *SS
266
+ - Ken Griffey
267
+ EOY
268
+
269
+ assert_bytecode( anc1, "D\nM\nShr\nQ\nSMark McGwire\nc Name \"Sammy Sosa\" scalar SS\n" +
270
+ "ASS\nSSammy Sosa\nE\nSrbi\nc So it can be referenced later\nQ\nRSS\nSKen Griffey\nE\nE\n" )
271
+
272
+ anc2 = [{"arrival"=>"EDI", "departure"=>"LAX", "fareref"=>"DOGMA", "currency"=>"GBP"}, {"arrival"=>"MEL", "departure"=>"SYD", "fareref"=>"MADF", "currency"=>"AUD"}, {"arrival"=>"MCO", "departure"=>"JFK", "fareref"=>"DFSF", "currency"=>"USD"}]
273
+ assert_to_yaml(
274
+ anc2, <<EOY
275
+ -
276
+ &F fareref: DOGMA
277
+ &C currency: GBP
278
+ &D departure: LAX
279
+ &A arrival: EDI
280
+ - { *F: MADF, *C: AUD, *D: SYD, *A: MEL }
281
+ - { *F: DFSF, *C: USD, *D: JFK, *A: MCO }
282
+ EOY
283
+ )
284
+
285
+ assert_bytecode( anc2, "D\nQ\nM\nAF\nSfareref\nSDOGMA\nAC\nScurrency\nSGBP\n" +
286
+ "AD\nSdeparture\nSLAX\nAA\nSarrival\nSEDI\nE\n" +
287
+ "M\nRF\nSMADF\nRC\nSAUD\nRD\nSSYD\nRA\nSMEL\nE\n" +
288
+ "M\nRF\nSDFSF\nRC\nSUSD\nRD\nSJFK\nRA\nSMCO\nE\n" +
289
+ "E\n" )
290
+
291
+ anc3 = {"ALIASES"=>["fareref", "currency", "departure", "arrival"], "FARES"=>[{"arrival"=>"EDI", "departure"=>"LAX", "fareref"=>"DOGMA", "currency"=>"GBP"}, {"arrival"=>"MEL", "departure"=>"SYD", "fareref"=>"MADF", "currency"=>"AUD"}, {"arrival"=>"MCO", "departure"=>"JFK", "fareref"=>"DFSF", "currency"=>"USD"}]}
292
+ assert_to_yaml(
293
+ anc3, <<EOY
294
+ ---
295
+ ALIASES: [&f fareref, &c currency, &d departure, &a arrival]
296
+ FARES:
297
+ - *f: DOGMA
298
+ *c: GBP
299
+ *d: LAX
300
+ *a: EDI
301
+
302
+ - *f: MADF
303
+ *c: AUD
304
+ *d: SYD
305
+ *a: MEL
306
+
307
+ - *f: DFSF
308
+ *c: USD
309
+ *d: JFK
310
+ *a: MCO
311
+
312
+ EOY
313
+ )
314
+ assert_bytecode( anc3, "D\nM\nSALIASES\nQ\nAf\nSfareref\nAc\nScurrency\nAd\nSdeparture\nAa\nSarrival\nE\n" +
315
+ "SFARES\nQ\nM\nRf\nSDOGMA\nRc\nSGBP\nRd\nSLAX\nRa\nSEDI\nE\n" +
316
+ "M\nRf\nSMADF\nRc\nSAUD\nRd\nSSYD\nRa\nSMEL\nE\n" +
317
+ "M\nRf\nSDFSF\nRc\nSUSD\nRd\nSJFK\nRa\nSMCO\nE\n" +
318
+ "E\nE\n" )
319
+ end
320
+
321
+ def test_spec_mapping_between_sequences
322
+ # Complex key #1
323
+ dj = Date.new( 2001, 7, 23 )
324
+ complex = { [ 'Detroit Tigers', 'Chicago Cubs' ] => [ Date.new( 2001, 7, 23 ) ],
325
+ [ 'New York Yankees', 'Atlanta Braves' ] => [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ), Date.new( 2001, 8, 14 ) ] }
326
+ assert_to_yaml(
327
+ complex, <<EOY
328
+ ? # PLAY SCHEDULE
329
+ - Detroit Tigers
330
+ - Chicago Cubs
331
+ :
332
+ - 2001-07-23
333
+
334
+ ? [ New York Yankees,
335
+ Atlanta Braves ]
336
+ : [ 2001-07-02, 2001-08-12,
337
+ 2001-08-14 ]
338
+ EOY
339
+ )
340
+
341
+ # Complex key #2
342
+ assert_to_yaml(
343
+ { [ 'New York Yankees', 'Atlanta Braves' ] =>
344
+ [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ),
345
+ Date.new( 2001, 8, 14 ) ],
346
+ [ 'Detroit Tigers', 'Chicago Cubs' ] =>
347
+ [ Date.new( 2001, 7, 23 ) ]
348
+ }, <<EOY
349
+ ?
350
+ - New York Yankees
351
+ - Atlanta Braves
352
+ :
353
+ - 2001-07-02
354
+ - 2001-08-12
355
+ - 2001-08-14
356
+ ?
357
+ - Detroit Tigers
358
+ - Chicago Cubs
359
+ :
360
+ - 2001-07-23
361
+ EOY
362
+ )
363
+ end
364
+
365
+ def test_spec_sequence_key_shortcut
366
+ # Shortcut sequence map
367
+ seq = { 'invoice' => 34843, 'date' => Date.new( 2001, 1, 23 ),
368
+ 'bill-to' => 'Chris Dumars', 'product' =>
369
+ [ { 'item' => 'Super Hoop', 'quantity' => 1 },
370
+ { 'item' => 'Basketball', 'quantity' => 4 },
371
+ { 'item' => 'Big Shoes', 'quantity' => 1 } ] }
372
+ assert_to_yaml(
373
+ seq, <<EOY
374
+ invoice: 34843
375
+ date : 2001-01-23
376
+ bill-to: Chris Dumars
377
+ product:
378
+ - item : Super Hoop
379
+ quantity: 1
380
+ - item : Basketball
381
+ quantity: 4
382
+ - item : Big Shoes
383
+ quantity: 1
384
+ EOY
385
+ )
386
+
387
+ # assert_bytecode( seq, "D\nM\nSinvoice\nS34843\nSdate\nS2001-01-03\nSbill-to\nSChris Dumars\nSproduct\n" +
388
+ # "Q\nM\nSitem\nSSuper Hoop\nSquantity\nS1\nE\nM\nSitem\nSBasketball\nSquantity\nS4\nE\n" +
389
+ # "M\nSitem\nSBig Shoes\nSquantity\nS1\nE\nE\nE\n" )
390
+ end
391
+
392
+ def test_spec_sequence_in_sequence_shortcut
393
+ # Seq-in-seq
394
+ seq = [ [ [ 'one', 'two', 'three' ] ] ]
395
+ assert_to_yaml( seq, <<EOY )
396
+ - - - one
397
+ - two
398
+ - three
399
+ EOY
400
+
401
+ assert_bytecode( seq, "D\nQ\nQ\nQ\nSone\nStwo\nSthree\nE\nE\nE\n" )
402
+ end
403
+
404
+ def test_spec_sequence_shortcuts
405
+ # Sequence shortcuts combined
406
+ seq = [
407
+ [
408
+ [ [ 'one' ] ],
409
+ [ 'two', 'three' ],
410
+ { 'four' => nil },
411
+ [ { 'five' => [ 'six' ] } ],
412
+ [ 'seven' ]
413
+ ],
414
+ [ 'eight', 'nine' ]
415
+ ]
416
+ assert_to_yaml( seq, <<EOY )
417
+ - - - - one
418
+ - - two
419
+ - three
420
+ - four:
421
+ - - five:
422
+ - six
423
+ - - seven
424
+ - - eight
425
+ - nine
426
+ EOY
427
+
428
+ assert_bytecode( seq, "D\nQ\nQ\nQ\nQ\nSone\nE\nE\nQ\nStwo\nSthree\nE\n" +
429
+ "M\nSfour\nS~\nE\nQ\nM\nSfive\nQ\nSsix\nE\nE\nE\n" +
430
+ "Q\nSseven\nE\nE\nQ\nSeight\nSnine\nE\nE\n" )
431
+ end
432
+
433
+ def test_spec_single_literal
434
+ # Literal scalar block
435
+ lit = [ "\\/|\\/|\n/ | |_\n" ]
436
+ assert_to_yaml( lit, <<EOY )
437
+ - |
438
+ \\/|\\/|
439
+ / | |_
440
+ EOY
441
+ assert_bytecode( lit, "D\nQ\nS\\/|\\/|\nN\nC/ | |_\nN\nE\n" )
442
+ end
443
+
444
+ def test_spec_single_folded
445
+ # Folded scalar block
446
+ fold = [ "Mark McGwire's year was crippled by a knee injury.\n" ]
447
+ assert_to_yaml( fold, <<EOY )
448
+ - >
449
+ Mark McGwire's
450
+ year was crippled
451
+ by a knee injury.
452
+ EOY
453
+
454
+ # Force a few elaborate folded blocks
455
+ assert_to_yaml( [ <<STR1, <<STR2, <<STR3 ], <<EOY )
456
+ Here's what you're going to need:
457
+
458
+
459
+ * Ruby 1.8.0 or higher.
460
+
461
+ ** Linux/FreeBSD: "Get the latest, please.":http://ruby-lang.org/en/20020102.html
462
+
463
+ ** Windows: "Installer for Windows.":http://rubyinstaller.sourceforge.net/
464
+
465
+ ** Mac: "OSX disk image.":http://homepage.mac.com/discord/Ruby/
466
+
467
+ * Once Ruby is installed, open a command prompt and type:
468
+
469
+
470
+ <pre>
471
+ ruby -ropen-uri -e 'eval(open("http://go.hobix.com/").read)'
472
+ </pre>
473
+
474
+ STR1
475
+ Ok, so the idea here is that one whole weblahhg is contained
476
+ in a single directory. What is stored in the directory?
477
+
478
+
479
+ <pre>
480
+ hobix.yaml <- configuration
481
+
482
+ entries/ <- edit and organize
483
+ your news items,
484
+ articles and so on.
485
+
486
+ skel/ <- contains your
487
+ templates
488
+
489
+ htdocs/ <- html is created here,
490
+ store all your images here,
491
+ this is your viewable
492
+ websyht
493
+
494
+ lib/ <- extra hobix libraries
495
+ (plugins) go here
496
+ </pre>
497
+
498
+
499
+ One weblahhg can be shared with many authors. In the @hobix.yaml@
500
+ file, you can store information about each author, as well as
501
+ information about others who contribute to your websyht.
502
+
503
+
504
+ You also have a file of your own, a configuration file called
505
+ @.hobixrc@, which contains a list of the weblahhgs you belong
506
+ to.
507
+
508
+
509
+ h2. Pull One From the Sky
510
+
511
+
512
+ If you would like to create your own weblahhg from scratch:
513
+
514
+
515
+ <pre>
516
+ hobix create blahhg
517
+ </pre>
518
+
519
+
520
+ You will be prompted for a full path where the new weblahhg can
521
+ be created. Don't worry if the directory doesn't yet exist,
522
+ Hobix will take care of clearing a path for it.
523
+
524
+
525
+ Once you give it the path, Hobix will create all the necessary
526
+ directories, as well as the @hobix.yaml@. You should also have
527
+ a set of sample templates to get you started.
528
+
529
+
530
+ In fact, if you want to generate the default site:
531
+
532
+
533
+ <pre>
534
+ hobix regen blahhg
535
+ </pre>
536
+
537
+
538
+ h2. Joining Hands With Others
539
+
540
+
541
+ To join an existing weblahhg:
542
+
543
+
544
+ <pre>
545
+ hobix add other-blahhg /path/to/other-blahhg/hobix.yaml
546
+ </pre>
547
+
548
+
549
+ You don't need to be on a weblahhg's author list to join the weblahhg.
550
+ You just need permissions to edit the file.
551
+
552
+
553
+ h2. Leaving in a Cloud of Keystrokes
554
+
555
+
556
+ To remove a weblahhg from your configuration:
557
+
558
+
559
+ <pre>
560
+ hobix del other-blahhg
561
+ </pre>
562
+
563
+
564
+ Please don't be afraid to edit your configuration file yourself,
565
+ should the commandline not suit your style.
566
+
567
+
568
+ See, here's my @.hobixrc@:
569
+
570
+
571
+ <pre>
572
+ ---
573
+ weblogs:
574
+ hobix: /usr/local/www/hobix.com/www/hobix.yaml
575
+ why: /usr/local/www/whytheluckystiff.net/www/hobix.yaml
576
+ username: why
577
+ use editor: true
578
+ </pre>
579
+
580
+
581
+ That's a YAML file. Very simple to edit. You can manually edit
582
+ your information, safely add or edit your weblogs, and save back
583
+ to your @.hobixrc@.
584
+
585
+
586
+ Enough then. Time to trick out your new Hoblahhg.
587
+ You will be guided through an automatic installation (or upgrade) of
588
+ Hobix.
589
+ STR2
590
+ NOW BUNKING together: the ruby and yaml scripts up at http://go.hobix.com/. Hey ,, the life and unity we feel is tree-mending-US!!
591
+
592
+ Try:
593
+
594
+ <pre>
595
+ ruby -ropen-uri -e'eval open("http://go.hobix.com/").read'
596
+ </pre>
597
+
598
+ No longer are curtains dropping ON the actors' arms !! No longer are swift currents ON the actors' legs !! The actors have a bottomless cereal container, witness.
599
+ STR3
600
+ ---
601
+ - |+
602
+ Here's what you're going to need:
603
+
604
+
605
+ * Ruby 1.8.0 or higher.
606
+
607
+ ** Linux/FreeBSD: "Get the latest, please.":http://ruby-lang.org/en/20020102.html
608
+
609
+ ** Windows: "Installer for Windows.":http://rubyinstaller.sourceforge.net/
610
+
611
+ ** Mac: "OSX disk image.":http://homepage.mac.com/discord/Ruby/
612
+
613
+ * Once Ruby is installed, open a command prompt and type:
614
+
615
+
616
+ <pre>
617
+ ruby -ropen-uri -e 'eval(open("http://go.hobix.com/").read)'
618
+ </pre>
619
+
620
+ - |
621
+ Ok, so the idea here is that one whole weblahhg is contained
622
+ in a single directory. What is stored in the directory?
623
+
624
+
625
+ <pre>
626
+ hobix.yaml <- configuration
627
+
628
+ entries/ <- edit and organize
629
+ your news items,
630
+ articles and so on.
631
+
632
+ skel/ <- contains your
633
+ templates
634
+
635
+ htdocs/ <- html is created here,
636
+ store all your images here,
637
+ this is your viewable
638
+ websyht
639
+
640
+ lib/ <- extra hobix libraries
641
+ (plugins) go here
642
+ </pre>
643
+
644
+
645
+ One weblahhg can be shared with many authors. In the @hobix.yaml@
646
+ file, you can store information about each author, as well as
647
+ information about others who contribute to your websyht.
648
+
649
+
650
+ You also have a file of your own, a configuration file called
651
+ @.hobixrc@, which contains a list of the weblahhgs you belong
652
+ to.
653
+
654
+
655
+ h2. Pull One From the Sky
656
+
657
+
658
+ If you would like to create your own weblahhg from scratch:
659
+
660
+
661
+ <pre>
662
+ hobix create blahhg
663
+ </pre>
664
+
665
+
666
+ You will be prompted for a full path where the new weblahhg can
667
+ be created. Don't worry if the directory doesn't yet exist,
668
+ Hobix will take care of clearing a path for it.
669
+
670
+
671
+ Once you give it the path, Hobix will create all the necessary
672
+ directories, as well as the @hobix.yaml@. You should also have
673
+ a set of sample templates to get you started.
674
+
675
+
676
+ In fact, if you want to generate the default site:
677
+
678
+
679
+ <pre>
680
+ hobix regen blahhg
681
+ </pre>
682
+
683
+
684
+ h2. Joining Hands With Others
685
+
686
+
687
+ To join an existing weblahhg:
688
+
689
+
690
+ <pre>
691
+ hobix add other-blahhg /path/to/other-blahhg/hobix.yaml
692
+ </pre>
693
+
694
+
695
+ You don't need to be on a weblahhg's author list to join the weblahhg.
696
+ You just need permissions to edit the file.
697
+
698
+
699
+ h2. Leaving in a Cloud of Keystrokes
700
+
701
+
702
+ To remove a weblahhg from your configuration:
703
+
704
+
705
+ <pre>
706
+ hobix del other-blahhg
707
+ </pre>
708
+
709
+
710
+ Please don't be afraid to edit your configuration file yourself,
711
+ should the commandline not suit your style.
712
+
713
+
714
+ See, here's my @.hobixrc@:
715
+
716
+
717
+ <pre>
718
+ ---
719
+ weblogs:
720
+ hobix: /usr/local/www/hobix.com/www/hobix.yaml
721
+ why: /usr/local/www/whytheluckystiff.net/www/hobix.yaml
722
+ username: why
723
+ use editor: true
724
+ </pre>
725
+
726
+
727
+ That's a YAML file. Very simple to edit. You can manually edit
728
+ your information, safely add or edit your weblogs, and save back
729
+ to your @.hobixrc@.
730
+
731
+
732
+ Enough then. Time to trick out your new Hoblahhg.
733
+ You will be guided through an automatic installation (or upgrade) of
734
+ Hobix.
735
+
736
+
737
+ - |
738
+ NOW BUNKING together: the ruby and yaml scripts up at http://go.hobix.com/. Hey ,, the life and unity we feel is tree-mending-US!!
739
+
740
+ Try:
741
+
742
+ <pre>
743
+ ruby -ropen-uri -e'eval open("http://go.hobix.com/").read'
744
+ </pre>
745
+
746
+ No longer are curtains dropping ON the actors' arms !! No longer are swift currents ON the actors' legs !! The actors have a bottomless cereal container, witness.
747
+
748
+ EOY
749
+
750
+ assert_bytecode( fold, "D\nQ\nSMark McGwire's year was crippled by a knee injury.\nN\nE\n" )
751
+ end
752
+
753
+ def test_spec_preserve_indent
754
+ # Preserve indented spaces
755
+ fold = "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n"
756
+ assert_to_yaml( fold, <<EOY )
757
+ --- >
758
+ Sammy Sosa completed another
759
+ fine season with great stats.
760
+
761
+ 63 Home Runs
762
+ 0.288 Batting Average
763
+
764
+ What a year!
765
+ EOY
766
+
767
+ assert_bytecode( fold, "D\nSSammy Sosa completed another fine season with great stats.\nN\nN\nC 63 Home Runs\nN\nC 0.288 Batting Average\nN\nN\nCWhat a year!\nN\n" )
768
+ end
769
+
770
+ def test_spec_indentation_determines_scope
771
+ map = { 'name' => 'Mark McGwire', 'accomplishment' => "Mark set a major league home run record in 1998.\n",
772
+ 'stats' => "65 Home Runs\n0.278 Batting Average\n" }
773
+ assert_to_yaml( map, <<EOY )
774
+ name: Mark McGwire
775
+ accomplishment: >
776
+ Mark set a major league
777
+ home run record in 1998.
778
+ stats: |
779
+ 65 Home Runs
780
+ 0.278 Batting Average
781
+ EOY
782
+ assert_bytecode( map, "D\nM\nSname\nSMark McGwire\nSaccomplishment\nSMark set a major league home run record in 1998.\nN\nSstats\nS65 Home Runs\nN\nC0.278 Batting Average\nN\nE\n" )
783
+ end
784
+
785
+ # def test_spec_quoted_scalars
786
+ # assert_to_yaml(
787
+ # {"tie-fighter"=>"|\\-*-/|", "control"=>"\0101998\t1999\t2000\n", "unicode"=>"Sosa did fine." + ["263A".hex].pack('U*'), "quoted"=>" # not a 'comment'.", "single"=>"\"Howdy!\" he cried.", "hexesc"=>"\r\n is \r\n"}, <<EOY
788
+ #unicode: "Sosa did fine.\\u263A"
789
+ #control: "\\b1998\\t1999\\t2000\\n"
790
+ #hexesc: "\\x0D\\x0A is \\r\\n"
791
+ #
792
+ #single: '"Howdy!" he cried.'
793
+ #quoted: ' # not a ''comment''.'
794
+ #tie-fighter: '|\\-*-/|'
795
+ #EOY
796
+ # )
797
+ # end
798
+
799
+ def test_spec_multiline_scalars
800
+ # Multiline flow scalars
801
+ map = { 'plain' => 'This unquoted scalar spans many lines.',
802
+ 'quoted' => "So does this quoted scalar.\n" }
803
+ assert_to_yaml( map, <<EOY )
804
+ plain: This unquoted
805
+ scalar spans
806
+ many lines.
807
+ quoted: "\\
808
+ So does this quoted
809
+ scalar.\\n"
810
+ EOY
811
+ assert_bytecode( map, "D\nM\nSplain\nSThis unquoted scalar spans many lines.\nSquoted\nSSo does this quoted scalar.\nN\nE\n" )
812
+ end
813
+
814
+ def test_spec_type_int
815
+ map = { 'canonical' => 12345, 'decimal' => 12345, 'octal' => '014'.oct, 'hexadecimal' => '0xC'.hex }
816
+ assert_to_yaml( map, <<EOY )
817
+ canonical: 12345
818
+ decimal: +12,345
819
+ octal: 014
820
+ hexadecimal: 0xC
821
+ EOY
822
+ assert_bytecode( map, "D\nM\nScanonical\nS12345\nSdecimal\nS+12,345\nSoctal\nS014\nShexadecimal\nS0xC\nE\n" )
823
+
824
+ map = { 'canonical' => 685230, 'decimal' => 685230, 'octal' => '02472256'.oct, 'hexadecimal' => '0x0A74AE'.hex, 'sexagesimal' => 685230 }
825
+ assert_to_yaml( map, <<EOY )
826
+ canonical: 685230
827
+ decimal: +685,230
828
+ octal: 02472256
829
+ hexadecimal: 0x0A,74,AE
830
+ sexagesimal: 190:20:30
831
+ EOY
832
+ assert_bytecode( map, "D\nM\nScanonical\nS685230\nSdecimal\nS+685,230\nSoctal\nS02472256\nShexadecimal\nS0x0A,74,AE\nSsexagesimal\nS190:20:30\nE\n" )
833
+
834
+ end
835
+
836
+ def test_spec_type_float
837
+ map = { 'canonical' => 1230.15, 'exponential' => 1230.15, 'fixed' => 1230.15,
838
+ 'sexagecimal' => 1230.15, 'negative infinity' => -1.0/0.0 }
839
+ assert_to_yaml( map, <<EOY )
840
+ canonical: 1.23015e+3
841
+ exponential: 12.3015e+02
842
+ fixed: 1,230.15
843
+ sexagecimal: 20:30.15
844
+ negative infinity: -.inf
845
+ EOY
846
+ nan = YAML::load( <<EOY
847
+ not a number: .NaN
848
+ EOY
849
+ )
850
+ assert( nan['not a number'].nan? )
851
+
852
+ assert_bytecode( map, "D\nM\nScanonical\nS1.23015e+3\nSexponential\nS12.3015e+02\nSfixed\nS1,230.15\nSsexagecimal\nS20:30.15\nSnegative infinity\nS-.inf\nE\n" )
853
+ end
854
+
855
+ def test_spec_type_misc
856
+ map = { nil => nil, true => true, false => false, 'string' => '12345' }
857
+ assert_to_yaml( map, <<EOY )
858
+ null: ~
859
+ true: yes
860
+ false: no
861
+ string: '12345'
862
+ EOY
863
+ assert_bytecode( map, "D\nM\nSnull\nS~\nStrue\nSyes\nSfalse\nSno\nSstring\nTtag:yaml.org,2002:str\nS12345\nE\n" )
864
+ end
865
+
866
+ def test_spec_complex_invoice
867
+ # Complex invoice type
868
+ id001 = { 'given' => 'Chris', 'family' => 'Dumars', 'address' =>
869
+ { 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak',
870
+ 'state' => 'MI', 'postal' => 48046 } }
871
+ invoice = { 'invoice' => 34843, 'date' => Date.new( 2001, 1, 23 ),
872
+ 'bill-to' => id001, 'ship-to' => id001, 'product' =>
873
+ [ { 'sku' => 'BL394D', 'quantity' => 4,
874
+ 'description' => 'Basketball', 'price' => 450.00 },
875
+ { 'sku' => 'BL4438H', 'quantity' => 1,
876
+ 'description' => 'Super Hoop', 'price' => 2392.00 } ],
877
+ 'tax' => 251.42, 'total' => 4443.52,
878
+ 'comments' => "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n" }
879
+ assert_to_yaml( invoice, <<EOY )
880
+ invoice: 34843
881
+ date : 2001-01-23
882
+ bill-to: &id001
883
+ given : Chris
884
+ family : !str Dumars
885
+ address:
886
+ lines: |
887
+ 458 Walkman Dr.
888
+ Suite #292
889
+ city : Royal Oak
890
+ state : MI
891
+ postal : 48046
892
+ ship-to: *id001
893
+ product:
894
+ - !map
895
+ sku : BL394D
896
+ quantity : 4
897
+ description : Basketball
898
+ price : 450.00
899
+ - sku : BL4438H
900
+ quantity : 1
901
+ description : Super Hoop
902
+ price : 2392.00
903
+ tax : 251.42
904
+ total: 4443.52
905
+ comments: >
906
+ Late afternoon is best.
907
+ Backup contact is Nancy
908
+ Billsmer @ 338-4338.
909
+ EOY
910
+ assert_bytecode( invoice, "D\nM\nSinvoice\nS34843\nSdate\nS2001-01-23\nSbill-to\nAid001\n" +
911
+ "M\nSgiven\nSChris\nSfamily\nT!str\nSDumars\nSaddress\n" +
912
+ "M\nSlines\nS458 Walkman Dr.\nN\nCSuite #292\nN\nScity\nSRoyal Oak\nSstate\nSMI\nSpostal\nS48046\nE\nE\n" +
913
+ "Sship-to\nRid001\nSproduct\nQ\n" +
914
+ "T!map\nM\nSsku\nSBL394D\nSquantity\nS4\nSdescription\nSBasketball\nSprice\nS450.00\nE\n" +
915
+ "M\nSsku\nSBL4438H\nSquantity\nS1\nSdescription\nSSuper Hoop\nSprice\nS2392.00\nE\nE\n" +
916
+ "Stax\nS251.42\nStotal\nS4443.52\nScomments\n" +
917
+ "SLate afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\nN\n" +
918
+ "E\n" )
919
+ end
920
+
921
+ def test_spec_log_file
922
+ doc_ct = 0
923
+ doc1 = { 'Time' => mktime( 2001, 11, 23, 15, 01, 42, 00, "-05:00" ),
924
+ 'User' => 'ed', 'Warning' => "This is an error message for the log file\n" }
925
+ doc2 = { 'Time' => mktime( 2001, 11, 23, 15, 02, 31, 00, "-05:00" ),
926
+ 'User' => 'ed', 'Warning' => "A slightly different error message.\n" }
927
+ doc3 = { 'Date' => mktime( 2001, 11, 23, 15, 03, 17, 00, "-05:00" ),
928
+ 'User' => 'ed', 'Fatal' => "Unknown variable \"bar\"\n",
929
+ 'Stack' => [
930
+ { 'file' => 'TopClass.py', 'line' => 23, 'code' => "x = MoreObject(\"345\\n\")\n" },
931
+ { 'file' => 'MoreClass.py', 'line' => 58, 'code' => "foo = bar" } ] }
932
+ YAML::load_documents( <<EOY
933
+ ---
934
+ Time: 2001-11-23 15:01:42 -05:00
935
+ User: ed
936
+ Warning: >
937
+ This is an error message
938
+ for the log file
939
+ ---
940
+ Time: 2001-11-23 15:02:31 -05:00
941
+ User: ed
942
+ Warning: >
943
+ A slightly different error
944
+ message.
945
+ ---
946
+ Date: 2001-11-23 15:03:17 -05:00
947
+ User: ed
948
+ Fatal: >
949
+ Unknown variable "bar"
950
+ Stack:
951
+ - file: TopClass.py
952
+ line: 23
953
+ code: |
954
+ x = MoreObject("345\\n")
955
+ - file: MoreClass.py
956
+ line: 58
957
+ code: |-
958
+ foo = bar
959
+ EOY
960
+ ) { |doc|
961
+ case doc_ct
962
+ when 0
963
+ assert_equals( doc, doc1 )
964
+ when 1
965
+ assert_equals( doc, doc2 )
966
+ when 2
967
+ assert_equals( doc, doc3 )
968
+ end
969
+ doc_ct += 1
970
+ }
971
+ assert_equals( doc_ct, 3 )
972
+
973
+ doc_ct = 0
974
+ yp = YAML::Syck::Parser.new
975
+ yp.resolver = YAML.resolver
976
+ yp.input = :bytecode
977
+ yp.load_documents(
978
+ "D\nM\nSTime\nS2001-11-23 15:01:42 -05:00\nSUser\nSed\nSWarning\nSThis is an error message for the log file\nN\nE\n" +
979
+ "D\nM\nSTime\nS2001-11-23 15:02:31 -05:00\nSUser\nSed\nSWarning\nSA slightly different error message.\nN\nE\n" +
980
+ "D\nM\nSDate\nS2001-11-23 15:03:17 -05:00\nSUser\nSed\nSFatal\nSUnknown variable \"bar\"\nN\nSStack\n" +
981
+ "Q\nM\nSfile\nSTopClass.py\nSline\nS23\nScode\nSx = MoreObject(\"345\\n\")\nN\nE\n" +
982
+ "M\nSfile\nSMoreClass.py\nSline\nS58\nScode\nSfoo = bar\nE\nE\nE\n"
983
+ ) { |doc|
984
+ case doc_ct
985
+ when 0
986
+ assert_equals( doc, doc1 )
987
+ when 1
988
+ assert_equals( doc, doc2 )
989
+ when 2
990
+ assert_equals( doc, doc3 )
991
+ end
992
+ doc_ct += 1
993
+ }
994
+ assert_equals( doc_ct, 3 )
995
+
996
+ end
997
+
998
+ def test_spec_root_fold
999
+ y = YAML::load( <<EOY
1000
+ --- >
1001
+ This YAML stream contains a single text value.
1002
+ The next stream is a log file - a sequence of
1003
+ log entries. Adding an entry to the log is a
1004
+ simple matter of appending it at the end.
1005
+ EOY
1006
+ )
1007
+ assert_equals( y, "This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end.\n" )
1008
+ end
1009
+
1010
+ def test_spec_root_mapping
1011
+ y = YAML::load( <<EOY
1012
+ # This stream is an example of a top-level mapping.
1013
+ invoice : 34843
1014
+ date : 2001-01-23
1015
+ total : 4443.52
1016
+ EOY
1017
+ )
1018
+ assert_equals( y, { 'invoice' => 34843, 'date' => Date.new( 2001, 1, 23 ), 'total' => 4443.52 } )
1019
+ end
1020
+
1021
+ # def test_spec_oneline_docs
1022
+ # doc_ct = 0
1023
+ # YAML::load_documents( <<EOY
1024
+ ## The following is a sequence of three documents.
1025
+ ## The first contains an empty mapping, the second
1026
+ ## an empty sequence, and the last an empty string.
1027
+ #--- {}
1028
+ #--- [ ]
1029
+ #--- ''
1030
+ #EOY
1031
+ # ) { |doc|
1032
+ # case doc_ct
1033
+ # when 0
1034
+ # assert_equals( doc, {} )
1035
+ # when 1
1036
+ # assert_equals( doc, [] )
1037
+ # when 2
1038
+ # assert_equals( doc, '' )
1039
+ # end
1040
+ # doc_ct += 1
1041
+ # }
1042
+ # assert_equals( doc_ct, 3 )
1043
+ # end
1044
+
1045
+ def test_spec_domain_prefix
1046
+ customer_proc = proc { |type, val|
1047
+ if Hash === val
1048
+ scheme, domain, type = type.split( ':', 3 )
1049
+ val['type'] = "domain #{type}"
1050
+ val
1051
+ else
1052
+ raise ArgumentError, "Not a Hash in domain.tld,2002/invoice: " + val.inspect
1053
+ end
1054
+ }
1055
+ YAML.add_domain_type( "domain.tld,2002", 'invoice', &customer_proc )
1056
+ YAML.add_domain_type( "domain.tld,2002", 'customer', &customer_proc )
1057
+ map = { "invoice"=> { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } }
1058
+ assert_to_yaml( map, <<EOY )
1059
+ # 'http://domain.tld,2002/invoice' is some type family.
1060
+ invoice: !domain.tld,2002/^invoice
1061
+ # 'seq' is shorthand for 'http://yaml.org/seq'.
1062
+ # This does not effect '^customer' below
1063
+ # because it is does not specify a prefix.
1064
+ customers: !seq
1065
+ # '^customer' is shorthand for the full
1066
+ # notation 'http://domain.tld,2002/customer'.
1067
+ - !^customer
1068
+ given : Chris
1069
+ family : Dumars
1070
+ EOY
1071
+ assert_bytecode( map, "D\nc 'http://domain.tld,2002/invoice' is some type family.\n" +
1072
+ "M\nSinvoice\nT!domain.tld,2002/^invoice\nc 'seq' is shorthand for 'http://yaml.org/seq'.\n" +
1073
+ "c This does not effect '^customer' below\nc because it is does not specify a prefix.\n" +
1074
+ "M\nScustomers\nT!seq\nc '^customer' is shorthand for the full\nc notation 'http://domain.tld,2002/customer'.\n" +
1075
+ "Q\nT!^customer\nM\nSgiven\nSChris\nSfamily\nSDumars\nE\nE\nE\n" )
1076
+ end
1077
+
1078
+ def test_spec_throwaway
1079
+ map = {"this"=>"contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n"}
1080
+ assert_to_yaml( map, <<EOY )
1081
+ ### These are four throwaway comment ###
1082
+
1083
+ ### lines (the second line is empty). ###
1084
+ this: | # Comments may trail lines.
1085
+ contains three lines of text.
1086
+ The third one starts with a
1087
+ # character. This isn't a comment.
1088
+
1089
+ # These are three throwaway comment
1090
+ # lines (the first line is empty).
1091
+ EOY
1092
+ assert_bytecode( map, "D\nc These are four throwaway comment\nc\nc lines (the second line is empty).\n" +
1093
+ "M\nSthis\nc Comments may trail lines.\nScontains three lines of text.\nN\nCThe third one starts with a\nN\n" +
1094
+ "C# character. This isn't a comment.\nN\n" +
1095
+ "c These are three throwaway comment\nc lines (the first line is empty).\nE\n" )
1096
+ end
1097
+
1098
+ def test_spec_force_implicit
1099
+ # Force implicit
1100
+ map = { 'integer' => 12, 'also int' => 12, 'string' => '12' }
1101
+ assert_to_yaml( map, <<EOY )
1102
+ integer: 12
1103
+ also int: ! "12"
1104
+ string: !str 12
1105
+ EOY
1106
+ end
1107
+
1108
+ # def test_spec_private_types
1109
+ # doc_ct = 0
1110
+ # YAML::parse_documents( <<EOY
1111
+ ## Private types are per-document.
1112
+ #---
1113
+ #pool: !!ball
1114
+ # number: 8
1115
+ # color: black
1116
+ #---
1117
+ #bearing: !!ball
1118
+ # material: steel
1119
+ #EOY
1120
+ # ) { |doc|
1121
+ # case doc_ct
1122
+ # when 0
1123
+ # assert_equals( doc['pool'].type_id, 'x-private:ball' )
1124
+ # assert_equals( doc['pool'].transform.value, { 'number' => 8, 'color' => 'black' } )
1125
+ # when 1
1126
+ # assert_equals( doc['bearing'].type_id, 'x-private:ball' )
1127
+ # assert_equals( doc['bearing'].transform.value, { 'material' => 'steel' } )
1128
+ # end
1129
+ # doc_ct += 1
1130
+ # }
1131
+ # assert_equals( doc_ct, 2 )
1132
+ #
1133
+ # doc_ct = 0
1134
+ # YAML::Syck::Parser.new( :Input => :Bytecode, :Model => :Generic )::load_documents(
1135
+ # "D\nc Private types are per-document.\nM\nSpool\nT!!ball\n" +
1136
+ # "M\nSnumber\nS8\nScolor\nSblack\nE\nE\n" +
1137
+ # "D\nM\nSbearing\nT!!ball\nM\nSmaterial\nSsteel\nE\nE\n"
1138
+ # ) { |doc|
1139
+ # case doc_ct
1140
+ # when 0
1141
+ # assert_equals( doc['pool'].type_id, 'x-private:ball' )
1142
+ # assert_equals( doc['pool'].transform.value, { 'number' => 8, 'color' => 'black' } )
1143
+ # when 1
1144
+ # assert_equals( doc['bearing'].type_id, 'x-private:ball' )
1145
+ # assert_equals( doc['bearing'].transform.value, { 'material' => 'steel' } )
1146
+ # end
1147
+ # doc_ct += 1
1148
+ # }
1149
+ # assert_equals( doc_ct, 2 )
1150
+ # end
1151
+
1152
+ def test_spec_url_escaping
1153
+ YAML.add_domain_type( "domain.tld,2002", "type0" ) { |type, val|
1154
+ "ONE: #{val}"
1155
+ }
1156
+ YAML.add_domain_type( "domain.tld,2002", "type%30" ) { |type, val|
1157
+ "TWO: #{val}"
1158
+ }
1159
+ map = { 'same' => [ 'ONE: value', 'ONE: value' ], 'different' => [ 'TWO: value' ] }
1160
+ assert_to_yaml( map, <<EOY )
1161
+ same:
1162
+ - !domain.tld,2002/type\\x30 value
1163
+ - !domain.tld,2002/type0 value
1164
+ different: # As far as the YAML parser is concerned
1165
+ - !domain.tld,2002/type%30 value
1166
+ EOY
1167
+ assert_bytecode( map, "D\nM\nSsame\nQ\nT!domain.tld,2002/type\x30\nSvalue\nT!domain.tld,2002/type0\nSvalue\nE\n" +
1168
+ "Sdifferent\nc As far as the YAML parser is concerned\nQ\nT!domain.tld,2002/type%30\nSvalue\nE\nE\n" )
1169
+ end
1170
+
1171
+ def test_spec_override_anchor
1172
+ # Override anchor
1173
+ a001 = "The alias node below is a repeated use of this value.\n"
1174
+ anc = { 'anchor' => 'This scalar has an anchor.', 'override' => a001, 'alias' => a001 }
1175
+ assert_to_yaml( anc, <<EOY )
1176
+ anchor : &A001 This scalar has an anchor.
1177
+ override : &A001 >
1178
+ The alias node below is a
1179
+ repeated use of this value.
1180
+ alias : *A001
1181
+ EOY
1182
+ assert_bytecode( anc, "D\nM\nSanchor\nAA001\nSThis scalar has an anchor.\nSoverride\nAA001\n" +
1183
+ "SThe alias node below is a repeated use of this value.\nN\nSalias\nRA001\nE\n" )
1184
+ end
1185
+
1186
+ def test_spec_explicit_families
1187
+ YAML.add_domain_type( "somewhere.com,2002", 'type' ) { |type, val|
1188
+ "SOMEWHERE: #{val}"
1189
+ }
1190
+ map = { 'not-date' => '2002-04-28', 'picture' => "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236i^\020' \202\n\001\000;", 'hmm' => "SOMEWHERE: family above is short for\nhttp://somewhere.com/type\n" }
1191
+ assert_to_yaml( map, <<EOY )
1192
+ not-date: !str 2002-04-28
1193
+ picture: !binary |
1194
+ R0lGODlhDAAMAIQAAP//9/X
1195
+ 17unp5WZmZgAAAOfn515eXv
1196
+ Pz7Y6OjuDg4J+fn5OTk6enp
1197
+ 56enmleECcgggoBADs=
1198
+
1199
+ hmm: !somewhere.com,2002/type |
1200
+ family above is short for
1201
+ http://somewhere.com/type
1202
+ EOY
1203
+ assert_bytecode( map, "D\nM\nSnot-date\nT!str\nS2002-04-28\nSpicture\nT!binary\n" +
1204
+ "SR0lGODlhDAAMAIQAAP//9/X\nN\nC17unp5WZmZgAAAOfn515eXv\nN\nCPz7Y6OjuDg4J+fn5OTk6enp\nN\n" +
1205
+ "C56enmleECcgggoBADs=\nN\nShmm\nT!somewhere.com,2002/type\nSfamily above is short for\nN\n" +
1206
+ "Chttp://somewhere.com/type\nN\nE\n" )
1207
+ end
1208
+
1209
+ def test_spec_application_family
1210
+ # Testing the clarkevans.com graphs
1211
+ YAML.add_domain_type( "clarkevans.com,2002", 'graph/shape' ) { |type, val|
1212
+ if Array === val
1213
+ val << "Shape Container"
1214
+ val
1215
+ else
1216
+ raise ArgumentError, "Invalid graph of type #{val.class}: " + val.inspect
1217
+ end
1218
+ }
1219
+ one_shape_proc = Proc.new { |type, val|
1220
+ if Hash === val
1221
+ type = type.split( /:/ )
1222
+ val['TYPE'] = "Shape: #{type[2]}"
1223
+ val
1224
+ else
1225
+ raise ArgumentError, "Invalid graph of type #{val.class}: " + val.inspect
1226
+ end
1227
+ }
1228
+ YAML.add_domain_type( "clarkevans.com,2002", 'graph/circle', &one_shape_proc )
1229
+ YAML.add_domain_type( "clarkevans.com,2002", 'graph/line', &one_shape_proc )
1230
+ YAML.add_domain_type( "clarkevans.com,2002", 'graph/text', &one_shape_proc )
1231
+ seq = [[{"radius"=>7, "center"=>{"x"=>73, "y"=>129}, "TYPE"=>"Shape: graph/circle"}, {"finish"=>{"x"=>89, "y"=>102}, "TYPE"=>"Shape: graph/line", "start"=>{"x"=>73, "y"=>129}}, {"TYPE"=>"Shape: graph/text", "value"=>"Pretty vector drawing.", "start"=>{"x"=>73, "y"=>129}, "color"=>16772795}, "Shape Container"]]
1232
+ assert_to_yaml( seq, <<EOY )
1233
+ - !clarkevans.com,2002/graph/^shape
1234
+ - !^circle
1235
+ center: &ORIGIN {'x': 73, 'y': 129}
1236
+ radius: 7
1237
+ - !^line # !clarkevans.com,2002/graph/line
1238
+ start: *ORIGIN
1239
+ finish: { 'x': 89, 'y': 102 }
1240
+ - !^text
1241
+ start: *ORIGIN
1242
+ color: 0xFFEEBB
1243
+ value: Pretty vector drawing.
1244
+ EOY
1245
+ assert_bytecode( seq, "D\nQ\nT!clarkevans.com,2002/graph/^shape\nQ\n" +
1246
+ "T!^circle\nM\nScenter\nAORIGIN\nM\nSx\nS73\nTstr\nSy\nS129\nE\nSradius\nS7\nE\n" +
1247
+ "T!^line\nc !clarkevans.com,2002/graph/line\nM\nSstart\nRORIGIN\nSfinish\nM\nSx\nS89\nTstr\nSy\nS102\nE\nE\n" +
1248
+ "T!^text\nM\nSstart\nRORIGIN\nScolor\nS0xFFEEBB\nSvalue\nSPretty vector drawing.\nE\nE\nE\n" )
1249
+ end
1250
+
1251
+ def test_spec_float_explicit
1252
+ seq = [ 10.0, 10.0, 10.0, 10.0 ]
1253
+ assert_to_yaml( seq, <<EOY )
1254
+ # All entries in the sequence
1255
+ # have the same type and value.
1256
+ - 10.0
1257
+ - !float 10
1258
+ - !yaml.org,2002/^float '10'
1259
+ - !yaml.org,2002/float "\\
1260
+ 1\\
1261
+ 0"
1262
+ EOY
1263
+ assert_bytecode( seq, "D\nc All entries in the sequence\nc have the same type and value\n" +
1264
+ "Q\nS10.0\nT!float\nS10\nT!yaml.org,2002/^float\nS10\nT!yaml.org,2002/float\nS10\nE\n" )
1265
+ end
1266
+
1267
+ def test_spec_builtin_seq
1268
+ # Assortment of sequences
1269
+ assert_to_yaml(
1270
+ { 'empty' => [], 'in-line' => [ 'one', 'two', 'three', 'four', 'five' ],
1271
+ 'nested' => [ 'First item in top sequence', [ 'Subordinate sequence entry' ],
1272
+ "A multi-line sequence entry\n", 'Sixth item in top sequence' ] }, <<EOY
1273
+ empty: []
1274
+ in-line: [ one, two, three # May span lines,
1275
+ , four, # indentation is
1276
+ five ] # mostly ignored.
1277
+ nested:
1278
+ - First item in top sequence
1279
+ -
1280
+ - Subordinate sequence entry
1281
+ - >
1282
+ A multi-line
1283
+ sequence entry
1284
+ - Sixth item in top sequence
1285
+ EOY
1286
+ )
1287
+ end
1288
+
1289
+ def test_spec_builtin_map
1290
+ # Assortment of mappings
1291
+ assert_to_yaml(
1292
+ { 'empty' => {}, 'in-line' => { 'one' => 1, 'two' => 2 },
1293
+ 'spanning' => { 'one' => 1, 'two' => 2 },
1294
+ 'nested' => { 'first' => 'First entry', 'second' =>
1295
+ { 'key' => 'Subordinate mapping' }, 'third' =>
1296
+ [ 'Subordinate sequence', {}, 'Previous mapping is empty.',
1297
+ { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' },
1298
+ 'The previous entry is equal to the following one.',
1299
+ { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' } ],
1300
+ 12.0 => 'This key is a float.', "?\n" => 'This key had to be protected.',
1301
+ "\a" => 'This key had to be escaped.',
1302
+ "This is a multi-line folded key\n" => "Whose value is also multi-line.\n",
1303
+ [ 'This key', 'is a sequence' ] => [ 'With a sequence value.' ] } }, <<EOY
1304
+
1305
+ empty: {}
1306
+ in-line: { one: 1, two: 2 }
1307
+ spanning: { one: 1,
1308
+ two: 2 }
1309
+ nested:
1310
+ first : First entry
1311
+ second:
1312
+ key: Subordinate mapping
1313
+ third:
1314
+ - Subordinate sequence
1315
+ - { }
1316
+ - Previous mapping is empty.
1317
+ - A key: value pair in a sequence.
1318
+ A second: key:value pair.
1319
+ - The previous entry is equal to the following one.
1320
+ -
1321
+ A key: value pair in a sequence.
1322
+ A second: key:value pair.
1323
+ !float 12 : This key is a float.
1324
+ ? >
1325
+ ?
1326
+ : This key had to be protected.
1327
+ "\\a" : This key had to be escaped.
1328
+ ? >
1329
+ This is a
1330
+ multi-line
1331
+ folded key
1332
+ : >
1333
+ Whose value is
1334
+ also multi-line.
1335
+ ?
1336
+ - This key
1337
+ - is a sequence
1338
+ :
1339
+ - With a sequence value.
1340
+ # The following parses correctly,
1341
+ # but Ruby 1.6.* fails the comparison!
1342
+ # ?
1343
+ # This: key
1344
+ # is a: mapping
1345
+ # :
1346
+ # with a: mapping value.
1347
+ EOY
1348
+ )
1349
+ end
1350
+
1351
+ def test_spec_builtin_literal_blocks
1352
+ # Assortment of literal scalar blocks
1353
+ assert_to_yaml(
1354
+ {"both are equal to"=>" This has no newline.", "is equal to"=>"The \\ ' \" characters may be\nfreely used. Leading white\n space is significant.\n\nLine breaks are significant.\nThus this value contains one\nempty line and ends with a\nsingle line break, but does\nnot start with one.\n", "also written as"=>" This has no newline.", "indented and chomped"=>" This has no newline.", "empty"=>"", "literal"=>"The \\ ' \" characters may be\nfreely used. Leading white\n space is significant.\n\nLine breaks are significant.\nThus this value contains one\nempty line and ends with a\nsingle line break, but does\nnot start with one.\n"}, <<EOY
1355
+ empty: |
1356
+
1357
+ literal: |
1358
+ The \\ ' " characters may be
1359
+ freely used. Leading white
1360
+ space is significant.
1361
+
1362
+ Line breaks are significant.
1363
+ Thus this value contains one
1364
+ empty line and ends with a
1365
+ single line break, but does
1366
+ not start with one.
1367
+
1368
+ is equal to: "The \\ \' \\" characters may \\
1369
+ be\\nfreely used. Leading white\\n space \\
1370
+ is significant.\\n\\nLine breaks are \\
1371
+ significant.\\nThus this value contains \\
1372
+ one\\nempty line and ends with a\\nsingle \\
1373
+ line break, but does\\nnot start with one.\\n"
1374
+
1375
+ # Comments may follow a nested
1376
+ # scalar value. They must be
1377
+ # less indented.
1378
+
1379
+ # Modifiers may be combined in any order.
1380
+ indented and chomped: |2-
1381
+ This has no newline.
1382
+
1383
+ also written as: |-2
1384
+ This has no newline.
1385
+
1386
+ both are equal to: " This has no newline."
1387
+ EOY
1388
+ )
1389
+
1390
+ str1 = "This has one newline.\n"
1391
+ str2 = "This has no newline."
1392
+ str3 = "This has two newlines.\n\n"
1393
+ assert_to_yaml(
1394
+ { 'clipped' => str1, 'same as "clipped" above' => str1,
1395
+ 'stripped' => str2, 'same as "stripped" above' => str2,
1396
+ 'kept' => str3, 'same as "kept" above' => str3 }, <<EOY
1397
+ clipped: |
1398
+ This has one newline.
1399
+
1400
+ same as "clipped" above: "This has one newline.\\n"
1401
+
1402
+ stripped: |-
1403
+ This has no newline.
1404
+
1405
+ same as "stripped" above: "This has no newline."
1406
+
1407
+ kept: |+
1408
+ This has two newlines.
1409
+
1410
+ same as "kept" above: "This has two newlines.\\n\\n"
1411
+
1412
+ EOY
1413
+ )
1414
+ end
1415
+
1416
+ def test_spec_span_single_quote
1417
+ assert_to_yaml( {"third"=>"a single quote ' must be escaped.", "second"=>"! : \\ etc. can be used freely.", "is same as"=>"this contains six spaces\nand one line break", "empty"=>"", "span"=>"this contains six spaces\nand one line break"}, <<EOY
1418
+ empty: ''
1419
+ second: '! : \\ etc. can be used freely.'
1420
+ third: 'a single quote '' must be escaped.'
1421
+ span: 'this contains
1422
+ six spaces
1423
+
1424
+ and one
1425
+ line break'
1426
+ is same as: "this contains six spaces\\nand one line break"
1427
+ EOY
1428
+ )
1429
+ end
1430
+
1431
+ def test_spec_span_double_quote
1432
+ assert_to_yaml( {"is equal to"=>"this contains four spaces", "third"=>"a \" or a \\ must be escaped.", "second"=>"! : etc. can be used freely.", "empty"=>"", "fourth"=>"this value ends with an LF.\n", "span"=>"this contains four spaces"}, <<EOY
1433
+ empty: ""
1434
+ second: "! : etc. can be used freely."
1435
+ third: "a \\\" or a \\\\ must be escaped."
1436
+ fourth: "this value ends with an LF.\\n"
1437
+ span: "this contains
1438
+ four \\
1439
+ spaces"
1440
+ is equal to: "this contains four spaces"
1441
+ EOY
1442
+ )
1443
+ end
1444
+
1445
+ def test_spec_builtin_time
1446
+ # Time
1447
+ assert_to_yaml(
1448
+ { "space separated" => mktime( 2001, 12, 14, 21, 59, 43, ".10", "-05:00" ),
1449
+ "canonical" => mktime( 2001, 12, 15, 2, 59, 43, ".10" ),
1450
+ "date (noon UTC)" => Date.new( 2002, 12, 14),
1451
+ "valid iso8601" => mktime( 2001, 12, 14, 21, 59, 43, ".10", "-05:00" ) }, <<EOY
1452
+ canonical: 2001-12-15T02:59:43.1Z
1453
+ valid iso8601: 2001-12-14t21:59:43.10-05:00
1454
+ space separated: 2001-12-14 21:59:43.10 -05:00
1455
+ date (noon UTC): 2002-12-14
1456
+ EOY
1457
+ )
1458
+ end
1459
+
1460
+ def test_spec_builtin_binary
1461
+ arrow_gif = "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236iiiccc\243\243\243\204\204\204\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371!\376\016Made with GIMP\000,\000\000\000\000\f\000\f\000\000\005, \216\2010\236\343@\024\350i\020\304\321\212\010\034\317\200M$z\357\3770\205p\270\2601f\r\e\316\001\303\001\036\020' \202\n\001\000;"
1462
+ assert_to_yaml(
1463
+ { 'canonical' => arrow_gif, 'base64' => arrow_gif,
1464
+ 'description' => "The binary value above is a tiny arrow encoded as a gif image.\n" }, <<EOY
1465
+ canonical: !binary "\\
1466
+ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOf\\
1467
+ n515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaW\\
1468
+ NjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++\\
1469
+ f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUg\\
1470
+ d2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuN\\
1471
+ AFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84Bww\\
1472
+ EeECcgggoBADs="
1473
+ base64: !binary |
1474
+ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOf
1475
+ n515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaW
1476
+ NjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++
1477
+ f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUg
1478
+ d2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuN
1479
+ AFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84Bww
1480
+ EeECcgggoBADs=
1481
+ description: >
1482
+ The binary value above is a tiny arrow
1483
+ encoded as a gif image.
1484
+ EOY
1485
+ )
1486
+ end
1487
+ def test_ruby_regexp
1488
+ # Test Ruby regular expressions
1489
+ assert_to_yaml(
1490
+ { 'simple' => /a.b/, 'complex' => /\A"((?:[^"]|\")+)"/,
1491
+ 'case-insensitive' => /George McFly/i }, <<EOY
1492
+ case-insensitive: !ruby/regexp "/George McFly/i"
1493
+ complex: !ruby/regexp "/\\\\A\\"((?:[^\\"]|\\\\\\")+)\\"/"
1494
+ simple: !ruby/regexp "/a.b/"
1495
+ EOY
1496
+ )
1497
+ end
1498
+
1499
+ def test_ruby_struct
1500
+ # Ruby structures
1501
+ book_struct = Struct::new( "BookStruct", :author, :title, :year, :isbn )
1502
+ assert_to_yaml(
1503
+ [ book_struct.new( "Yukihiro Matsumoto", "Ruby in a Nutshell", 2002, "0-596-00214-9" ),
1504
+ book_struct.new( [ 'Dave Thomas', 'Andy Hunt' ], "The Pickaxe", 2002,
1505
+ book_struct.new( "This should be the ISBN", "but I have another struct here", 2002, "None" )
1506
+ ) ], <<EOY
1507
+ - !ruby/struct:BookStruct
1508
+ author: Yukihiro Matsumoto
1509
+ title: Ruby in a Nutshell
1510
+ year: 2002
1511
+ isbn: 0-596-00214-9
1512
+ - !ruby/struct:BookStruct
1513
+ author:
1514
+ - Dave Thomas
1515
+ - Andy Hunt
1516
+ title: The Pickaxe
1517
+ year: 2002
1518
+ isbn: !ruby/struct:BookStruct
1519
+ author: This should be the ISBN
1520
+ title: but I have another struct here
1521
+ year: 2002
1522
+ isbn: None
1523
+ EOY
1524
+ )
1525
+
1526
+ assert_to_yaml( YAML_Tests::StructTest.new( 123 ), <<EOY )
1527
+ --- !ruby/struct:YAML_Tests::StructTest
1528
+ c: 123
1529
+ EOY
1530
+
1531
+ end
1532
+
1533
+ def test_emitting_indicators
1534
+ assert_to_yaml( "Hi, from Object 1. You passed: please, pretty please", <<EOY
1535
+ --- "Hi, from Object 1. You passed: please, pretty please"
1536
+ EOY
1537
+ )
1538
+ end
1539
+
1540
+ #
1541
+ # Test the YAML::Stream class -- INACTIVE at the moment
1542
+ #
1543
+ def test_document
1544
+ y = YAML::Stream.new( :Indent => 2, :UseVersion => 0 )
1545
+ y.add(
1546
+ { 'hi' => 'hello', 'map' =>
1547
+ { 'good' => 'two' },
1548
+ 'time' => Time.now,
1549
+ 'try' => /^po(.*)$/,
1550
+ 'bye' => 'goodbye'
1551
+ }
1552
+ )
1553
+ y.add( { 'po' => 'nil', 'oper' => 90 } )
1554
+ y.add( { 'hi' => 'wow!', 'bye' => 'wow!' } )
1555
+ y.add( { [ 'Red Socks', 'Boston' ] => [ 'One', 'Two', 'Three' ] } )
1556
+ y.add( [ true, false, false ] )
1557
+ end
1558
+
1559
+ #
1560
+ # Test YPath choices parsing
1561
+ #
1562
+ def test_ypath_parsing
1563
+ assert_path_segments( "/*/((one|three)/name|place)|//place",
1564
+ [ ["*", "one", "name"],
1565
+ ["*", "three", "name"],
1566
+ ["*", "place"],
1567
+ ["/", "place"] ]
1568
+ )
1569
+ end
1570
+
1571
+ #
1572
+ # Test of Ranges
1573
+ #
1574
+ def test_ranges
1575
+
1576
+ # Simple numeric
1577
+ assert_to_yaml( 1..3, <<EOY )
1578
+ --- !ruby/range 1..3
1579
+ EOY
1580
+
1581
+ # Simple alphabetic
1582
+ assert_to_yaml( 'a'..'z', <<EOY )
1583
+ --- !ruby/range a..z
1584
+ EOY
1585
+
1586
+ # Float
1587
+ assert_to_yaml( 10.5...30.3, <<EOY )
1588
+ --- !ruby/range 10.5...30.3
1589
+ EOY
1590
+
1591
+ end
1592
+
1593
+ #
1594
+ # Tests from Tanaka Akira on [ruby-core]
1595
+ #
1596
+ def test_akira
1597
+
1598
+ # Commas in plain scalars [ruby-core:1066]
1599
+ assert_to_yaml(
1600
+ {"A"=>"A,","B"=>"B"}, <<EOY
1601
+ A: "A,"
1602
+ B: B
1603
+ EOY
1604
+ )
1605
+
1606
+ # Double-quoted keys [ruby-core:1069]
1607
+ assert_to_yaml(
1608
+ {"1"=>2, "2"=>3}, <<EOY
1609
+ '1': 2
1610
+ "2": 3
1611
+ EOY
1612
+ )
1613
+
1614
+ # Anchored mapping [ruby-core:1071]
1615
+ assert_to_yaml(
1616
+ [{"a"=>"b"}] * 2, <<EOY
1617
+ - &id001
1618
+ a: b
1619
+ - *id001
1620
+ EOY
1621
+ )
1622
+
1623
+ # Stress test [ruby-core:1071]
1624
+ # a = []; 1000.times { a << {"a"=>"b", "c"=>"d"} }
1625
+ # YAML::load( a.to_yaml )
1626
+
1627
+ end
1628
+
1629
+ #
1630
+ # Test Time.now cycle
1631
+ #
1632
+ def test_time_now_cycle
1633
+ #
1634
+ # From Minero Aoki [ruby-core:2305]
1635
+ #
1636
+ require 'yaml'
1637
+ t = Time.now
1638
+ 5.times do
1639
+ assert_equals( t, YAML.load( YAML.dump( t ) ) )
1640
+ end
1641
+ end
1642
+
1643
+ # #
1644
+ # # Circular references
1645
+ # #
1646
+ # def test_circular_references
1647
+ # a = []; a[0] = a; a[1] = a
1648
+ # inspect_str = "[[...], [...]]"
1649
+ # assert_equals( inspect_str, YAML::load( a.to_yaml ).inspect )
1650
+ # end
1651
+ end
1652
+
1653
+ RUNIT::CUI::TestRunner.run( YAML_Unit_Tests.suite )