ox 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ox might be problematic. Click here for more details.

Files changed (4) hide show
  1. data/ext/ox/ox.c +3 -0
  2. data/lib/ox/version.rb +1 -1
  3. data/test/func.rb +20 -10
  4. metadata +2 -2
@@ -495,6 +495,9 @@ dump(int argc, VALUE *argv, VALUE self) {
495
495
  rb_raise(rb_eNoMemError, "Not enough memory.\n");
496
496
  }
497
497
  rstr = rb_str_new2(xml);
498
+ if ('\0' != *copts.encoding) {
499
+ rb_enc_associate(rstr, rb_enc_find(copts.encoding));
500
+ }
498
501
  free(xml);
499
502
 
500
503
  return rstr;
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Ox
3
3
  # Current version of the module.
4
- VERSION = '1.2.2'
4
+ VERSION = '1.2.3'
5
5
  end
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby -wW1
2
+ # encoding: UTF-8
2
3
 
3
4
  $: << '../lib'
4
5
  $: << '../ext'
@@ -180,27 +181,27 @@ class Func < ::Test::Unit::TestCase
180
181
 
181
182
  def test_xml_instruction
182
183
  xml = Ox.dump("test", mode: :object, with_xml: false)
183
- assert_equal(xml, "<s>test</s>\n")
184
+ assert_equal("<s>test</s>\n", xml)
184
185
  xml = Ox.dump("test", mode: :object, with_xml: true)
185
- assert_equal(xml, "<?xml version=\"1.0\"?>\n<s>test</s>\n")
186
+ assert_equal("<?xml version=\"1.0\"?>\n<s>test</s>\n", xml)
186
187
  xml = Ox.dump("test", mode: :object, with_xml: true, encoding: 'UTF-8')
187
- assert_equal(xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<s>test</s>\n")
188
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<s>test</s>\n", xml)
188
189
  end
189
190
 
190
191
  def test_ox_instruction
191
192
  xml = Ox.dump("test", mode: :object, with_xml: true, with_instructions: true)
192
- assert_equal(xml, "<?xml version=\"1.0\"?>\n<?ox version=\"1.0\" mode=\"object\"?>\n<s>test</s>\n")
193
+ assert_equal("<?xml version=\"1.0\"?>\n<?ox version=\"1.0\" mode=\"object\" circular=\"no\" xsd_date=\"no\"?>\n<s>test</s>\n", xml)
193
194
  xml = Ox.dump("test", mode: :object, with_instructions: true)
194
- assert_equal(xml, "<?ox version=\"1.0\" mode=\"object\"?>\n<s>test</s>\n")
195
+ assert_equal("<?ox version=\"1.0\" mode=\"object\" circular=\"no\" xsd_date=\"no\"?>\n<s>test</s>\n", xml)
195
196
  xml = Ox.dump("test", mode: :object, with_instructions: true, circular: true, xsd_date: true)
196
- assert_equal(xml, "<?ox version=\"1.0\" mode=\"object\" circular=\"yes\" xsd_date=\"yes\"?>\n<s i=\"1\">test</s>\n")
197
+ assert_equal("<?ox version=\"1.0\" mode=\"object\" circular=\"yes\" xsd_date=\"yes\"?>\n<s i=\"1\">test</s>\n", xml)
197
198
  xml = Ox.dump("test", mode: :object, with_instructions: true, circular: false, xsd_date: false)
198
- assert_equal(xml, "<?ox version=\"1.0\" mode=\"object\" circular=\"no\" xsd_date=\"no\"?>\n<s>test</s>\n")
199
+ assert_equal("<?ox version=\"1.0\" mode=\"object\" circular=\"no\" xsd_date=\"no\"?>\n<s>test</s>\n", xml)
199
200
  end
200
201
 
201
202
  def test_dtd
202
203
  xml = Ox.dump("test", mode: :object, with_dtd: true)
203
- assert_equal(xml, "<!DOCTYPE s SYSTEM \"ox.dtd\">\n<s>test</s>\n")
204
+ assert_equal("<!DOCTYPE s SYSTEM \"ox.dtd\">\n<s>test</s>\n", xml)
204
205
  end
205
206
 
206
207
  def test_class
@@ -284,14 +285,23 @@ class Func < ::Test::Unit::TestCase
284
285
  loaded
285
286
  end
286
287
 
288
+ def test_encoding
289
+ s = 'ピーター'
290
+ xml = Ox.dump(s, with_xml: true, encoding: 'UTF-8')
291
+ #puts xml
292
+ #puts xml.encoding.to_s
293
+ assert_equal('UTF-8', xml.encoding.to_s)
294
+ obj = Ox.load(xml, mode: :object)
295
+ assert_equal(s, obj)
296
+ end
297
+
287
298
  def test_instructions
288
299
  xml = Ox.dump("test", with_instructions: true)
289
- puts xml
300
+ #puts xml
290
301
  obj = Ox.load(xml) # should convert it to an object
291
302
  assert_equal("test", obj)
292
303
  end
293
304
 
294
-
295
305
  end
296
306
 
297
307
  class Bag
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ox
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.2
5
+ version: 1.2.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Peter Ohler
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-14 00:00:00 Z
13
+ date: 2011-07-27 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: A fast XML parser and object serializer that uses only standard C lib.