ox 1.2.12 → 1.2.13
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.
- data/ext/ox/cache8.c +4 -4
- data/ext/ox/cache8.h +4 -4
- data/ext/ox/cache8_test.c +16 -16
- data/ext/ox/dump.c +40 -16
- data/ext/ox/gen_load.c +4 -4
- data/ext/ox/obj_load.c +16 -4
- data/ext/ox/ox.c +1 -1
- data/ext/ox/ox.h +1 -1
- data/lib/ox/version.rb +1 -1
- data/test/big.rb +24 -0
- data/test/bug3.rb +13 -11
- data/test/func.rb +103 -61
- metadata +22 -29
data/ext/ox/cache8.c
CHANGED
@@ -15,8 +15,8 @@
|
|
15
15
|
|
16
16
|
struct _Cache8 {
|
17
17
|
union {
|
18
|
-
struct _Cache8
|
19
|
-
|
18
|
+
struct _Cache8 *slots[SLOT_CNT];
|
19
|
+
uint64_t values[SLOT_CNT];
|
20
20
|
};
|
21
21
|
};
|
22
22
|
|
@@ -56,8 +56,8 @@ cache8_delete(Cache8 cache, int depth) {
|
|
56
56
|
free(cache);
|
57
57
|
}
|
58
58
|
|
59
|
-
|
60
|
-
ox_cache8_get(Cache8 cache, VALUE key,
|
59
|
+
uint64_t
|
60
|
+
ox_cache8_get(Cache8 cache, VALUE key, uint64_t **slot) {
|
61
61
|
Cache8 *cp;
|
62
62
|
int i;
|
63
63
|
VALUE k;
|
data/ext/ox/cache8.h
CHANGED
@@ -35,11 +35,11 @@
|
|
35
35
|
|
36
36
|
typedef struct _Cache8 *Cache8;
|
37
37
|
|
38
|
-
extern void
|
39
|
-
extern void
|
38
|
+
extern void ox_cache8_new(Cache8 *cache);
|
39
|
+
extern void ox_cache8_delete(Cache8 cache);
|
40
40
|
|
41
|
-
extern
|
41
|
+
extern uint64_t ox_cache8_get(Cache8 cache, VALUE key, uint64_t **slot);
|
42
42
|
|
43
|
-
extern void
|
43
|
+
extern void ox_cache8_print(Cache8 cache);
|
44
44
|
|
45
45
|
#endif /* __OX_CACHE8_H__ */
|
data/ext/ox/cache8_test.c
CHANGED
@@ -31,37 +31,37 @@
|
|
31
31
|
#include <stdio.h>
|
32
32
|
#include "cache8.h"
|
33
33
|
|
34
|
-
static
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
static uint64_t data[] = {
|
35
|
+
0x000000A0A0A0A0A0ULL,
|
36
|
+
0x0000000000ABCDEFULL,
|
37
|
+
0x0123456789ABCDEFULL,
|
38
|
+
0x0000000000000001ULL,
|
39
|
+
0x0000000000000002ULL,
|
40
|
+
0x0000000000000003ULL,
|
41
|
+
0x0000000000000004ULL,
|
42
42
|
0
|
43
43
|
};
|
44
44
|
|
45
45
|
void
|
46
46
|
ox_cache8_test() {
|
47
|
-
Cache8
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
Cache8 c;
|
48
|
+
uint64_t v;
|
49
|
+
uint64_t *d;
|
50
|
+
uint64_t cnt = 1;
|
51
|
+
uint64_t *slot = 0;
|
52
52
|
|
53
53
|
ox_cache8_new(&c);
|
54
54
|
for (d = data; 0 != *d; d++) {
|
55
55
|
v = ox_cache8_get(c, *d, &slot);
|
56
56
|
if (0 == v) {
|
57
57
|
if (0 == slot) {
|
58
|
-
printf("*** failed to get a slot for 0x%
|
58
|
+
printf("*** failed to get a slot for 0x%016llx\n", *d);
|
59
59
|
} else {
|
60
|
-
printf("*** adding 0x%
|
60
|
+
printf("*** adding 0x%016llx to cache with value %llu\n", *d, cnt);
|
61
61
|
*slot = cnt++;
|
62
62
|
}
|
63
63
|
} else {
|
64
|
-
printf("*** get on 0x%
|
64
|
+
printf("*** get on 0x%016llx returned %llu\n", *d, v);
|
65
65
|
}
|
66
66
|
//ox_cache8_print(c);
|
67
67
|
}
|
data/ext/ox/dump.c
CHANGED
@@ -188,7 +188,7 @@ fill_attr(Out out, char name, const char *value, size_t len) {
|
|
188
188
|
}
|
189
189
|
|
190
190
|
inline static const char*
|
191
|
-
ulong2str(
|
191
|
+
ulong2str(uint64_t num, char *end) {
|
192
192
|
char *b;
|
193
193
|
|
194
194
|
*end-- = '\0';
|
@@ -202,9 +202,9 @@ ulong2str(unsigned long num, char *end) {
|
|
202
202
|
|
203
203
|
static int
|
204
204
|
check_circular(Out out, VALUE obj, Element e) {
|
205
|
-
|
206
|
-
|
207
|
-
int
|
205
|
+
uint64_t *slot;
|
206
|
+
uint64_t id;
|
207
|
+
int result;
|
208
208
|
|
209
209
|
if (0 == (id = ox_cache8_get(out->circ_cache, obj, &slot))) {
|
210
210
|
out->circ_cnt++;
|
@@ -535,9 +535,9 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
535
535
|
e.indent = -1;
|
536
536
|
out->w_end(out, &e);
|
537
537
|
} else {
|
538
|
-
char
|
539
|
-
char
|
540
|
-
|
538
|
+
char buf64[4096];
|
539
|
+
char *b64 = buf64;
|
540
|
+
uint64_t size = b64_size(cnt);
|
541
541
|
|
542
542
|
e.type = String64Code;
|
543
543
|
if (sizeof(buf64) < size) {
|
@@ -568,9 +568,9 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
568
568
|
e.indent = -1;
|
569
569
|
out->w_end(out, &e);
|
570
570
|
} else {
|
571
|
-
char
|
572
|
-
char
|
573
|
-
|
571
|
+
char buf64[4096];
|
572
|
+
char *b64 = buf64;
|
573
|
+
uint64_t size = b64_size(cnt);
|
574
574
|
|
575
575
|
e.type = Symbol64Code;
|
576
576
|
if (sizeof(buf64) < size) {
|
@@ -620,9 +620,9 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
620
620
|
}
|
621
621
|
clas = rb_obj_class(obj);
|
622
622
|
if (rb_cRange == clas) {
|
623
|
-
VALUE beg =
|
624
|
-
VALUE end =
|
625
|
-
VALUE excl =
|
623
|
+
VALUE beg = RSTRUCT_PTR(obj)[0];
|
624
|
+
VALUE end = RSTRUCT_PTR(obj)[1];
|
625
|
+
VALUE excl = RSTRUCT_PTR(obj)[2];
|
626
626
|
int d2 = depth + 1;
|
627
627
|
|
628
628
|
e.type = RangeCode; e.clas.len = 5; e.clas.str = "Range";
|
@@ -670,6 +670,8 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
670
670
|
dump_gen_element(obj, depth + 1, out);
|
671
671
|
out->w_end(out, &e);
|
672
672
|
} else { // Object
|
673
|
+
// use encoding as the indicator for Ruby 1.8.7 or 1.9.x
|
674
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
673
675
|
e.type = ObjectCode;
|
674
676
|
cnt = (int)rb_ivar_count(obj);
|
675
677
|
e.closed = (0 >= cnt);
|
@@ -682,6 +684,28 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
682
684
|
out->depth = od;
|
683
685
|
out->w_end(out, &e);
|
684
686
|
}
|
687
|
+
#else
|
688
|
+
VALUE vars = rb_obj_instance_variables(obj);
|
689
|
+
|
690
|
+
e.type = ObjectCode;
|
691
|
+
cnt = (int)RARRAY_LEN(vars);
|
692
|
+
e.closed = (0 >= cnt);
|
693
|
+
out->w_start(out, &e);
|
694
|
+
if (0 < cnt) {
|
695
|
+
VALUE *np = RARRAY_PTR(vars);
|
696
|
+
ID vid;
|
697
|
+
unsigned int od = out->depth;
|
698
|
+
int i;
|
699
|
+
|
700
|
+
out->depth = depth + 1;
|
701
|
+
for (i = cnt; 0 < i; i--, np++) {
|
702
|
+
vid = rb_to_id(*np);
|
703
|
+
dump_var(vid, rb_ivar_get(obj, vid), out);
|
704
|
+
}
|
705
|
+
out->depth = od;
|
706
|
+
out->w_end(out, &e);
|
707
|
+
}
|
708
|
+
#endif
|
685
709
|
}
|
686
710
|
break;
|
687
711
|
}
|
@@ -704,9 +728,9 @@ dump_obj(ID aid, VALUE obj, unsigned int depth, Out out) {
|
|
704
728
|
//dump_value(out, "/", 1);
|
705
729
|
dump_value(out, s, cnt);
|
706
730
|
} else {
|
707
|
-
char
|
708
|
-
char
|
709
|
-
|
731
|
+
char buf64[4096];
|
732
|
+
char *b64 = buf64;
|
733
|
+
uint64_t size = b64_size(cnt);
|
710
734
|
|
711
735
|
if (sizeof(buf64) < size) {
|
712
736
|
if (0 == (b64 = (char*)malloc(size + 1))) {
|
data/ext/ox/gen_load.c
CHANGED
@@ -92,7 +92,7 @@ create_prolog_doc(PInfo pi, const char *target, Attr attrs) {
|
|
92
92
|
VALUE nodes;
|
93
93
|
|
94
94
|
if (0 != pi->h) { // top level object
|
95
|
-
rb_raise(
|
95
|
+
rb_raise(rb_eSyntaxError, "Prolog must be the first element in an XML document.\n");
|
96
96
|
}
|
97
97
|
pi->h = pi->helpers;
|
98
98
|
doc = rb_obj_alloc(ox_document_clas);
|
@@ -122,7 +122,7 @@ instruct(PInfo pi, const char *target, Attr attrs) {
|
|
122
122
|
for (; 0 != attrs->name; attrs++) {
|
123
123
|
if (0 == strcmp("version", attrs->name)) {
|
124
124
|
if (0 != strcmp("1.0", attrs->value)) {
|
125
|
-
rb_raise(
|
125
|
+
rb_raise(rb_eSyntaxError, "Only Ox XML Object version 1.0 supported, not %s.\n", attrs->value);
|
126
126
|
}
|
127
127
|
}
|
128
128
|
// ignore other instructions
|
@@ -142,7 +142,7 @@ nomode_instruct(PInfo pi, const char *target, Attr attrs) {
|
|
142
142
|
for (; 0 != attrs->name; attrs++) {
|
143
143
|
if (0 == strcmp("version", attrs->name)) {
|
144
144
|
if (0 != strcmp("1.0", attrs->value)) {
|
145
|
-
rb_raise(
|
145
|
+
rb_raise(rb_eSyntaxError, "Only Ox XML Object version 1.0 supported, not %s.\n", attrs->value);
|
146
146
|
}
|
147
147
|
} else if (0 == strcmp("mode", attrs->name)) {
|
148
148
|
if (0 == strcmp("object", attrs->value)) {
|
@@ -156,7 +156,7 @@ nomode_instruct(PInfo pi, const char *target, Attr attrs) {
|
|
156
156
|
pi->obj = Qnil;
|
157
157
|
pi->h = 0;
|
158
158
|
} else {
|
159
|
-
rb_raise(
|
159
|
+
rb_raise(rb_eSyntaxError, "%s is not a valid processing instruction mode.\n", attrs->value);
|
160
160
|
}
|
161
161
|
}
|
162
162
|
}
|
data/ext/ox/obj_load.c
CHANGED
@@ -147,8 +147,12 @@ structname2obj(const char *name) {
|
|
147
147
|
}
|
148
148
|
}
|
149
149
|
ost = rb_const_get(struct_class, rb_intern(s));
|
150
|
-
|
150
|
+
// use encoding as the indicator for Ruby 1.8.7 or 1.9.x
|
151
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
151
152
|
return rb_struct_alloc_noinit(ost);
|
153
|
+
#else
|
154
|
+
return rb_struct_new(ost);
|
155
|
+
#endif
|
152
156
|
}
|
153
157
|
|
154
158
|
// 2010-07-09T10:47:45.895826162+09:00
|
@@ -678,11 +682,11 @@ end_element(PInfo pi, const char *ename) {
|
|
678
682
|
break;
|
679
683
|
case RangeCode:
|
680
684
|
if (beg_id == h->var) {
|
681
|
-
|
685
|
+
RSTRUCT_PTR(pi->h->obj)[0] = h->obj;
|
682
686
|
} else if (end_id == h->var) {
|
683
|
-
|
687
|
+
RSTRUCT_PTR(pi->h->obj)[1] = h->obj;
|
684
688
|
} else if (excl_id == h->var) {
|
685
|
-
|
689
|
+
RSTRUCT_PTR(pi->h->obj)[2] = h->obj;
|
686
690
|
} else {
|
687
691
|
raise_error("Invalid range attribute", pi->str, pi->s);
|
688
692
|
}
|
@@ -692,18 +696,26 @@ end_element(PInfo pi, const char *ename) {
|
|
692
696
|
pi->h--;
|
693
697
|
break;
|
694
698
|
case ComplexCode:
|
699
|
+
#ifdef T_COMPLEX
|
695
700
|
if (Qundef == pi->h->obj) {
|
696
701
|
pi->h->obj = h->obj;
|
697
702
|
} else {
|
698
703
|
pi->h->obj = rb_complex_new(pi->h->obj, h->obj);
|
699
704
|
}
|
705
|
+
#else
|
706
|
+
raise_error("Complex Objects not implemented in Ruby 1.8.7", pi->str, pi->s);
|
707
|
+
#endif
|
700
708
|
break;
|
701
709
|
case RationalCode:
|
710
|
+
#ifdef T_RATIONAL
|
702
711
|
if (Qundef == pi->h->obj) {
|
703
712
|
pi->h->obj = h->obj;
|
704
713
|
} else {
|
705
714
|
pi->h->obj = rb_rational_new(pi->h->obj, h->obj);
|
706
715
|
}
|
716
|
+
#else
|
717
|
+
raise_error("Rational Objects not implemented in Ruby 1.8.7", pi->str, pi->s);
|
718
|
+
#endif
|
707
719
|
break;
|
708
720
|
default:
|
709
721
|
raise_error("Corrupt parse stack, container is wrong type", pi->str, pi->s);
|
data/ext/ox/ox.c
CHANGED
@@ -667,5 +667,5 @@ _raise_error(const char *msg, const char *xml, const char *current, const char*
|
|
667
667
|
xline++;
|
668
668
|
}
|
669
669
|
}
|
670
|
-
rb_raise(
|
670
|
+
rb_raise(rb_eSyntaxError, "%s at line %d, column %d [%s:%d]\n", msg, xline, col, file, line);
|
671
671
|
}
|
data/ext/ox/ox.h
CHANGED
data/lib/ox/version.rb
CHANGED
data/test/big.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby -wW1
|
2
|
+
|
3
|
+
$: << '../lib'
|
4
|
+
$: << '../ext'
|
5
|
+
|
6
|
+
if __FILE__ == $0
|
7
|
+
while (i = ARGV.index('-I'))
|
8
|
+
x,path = ARGV.slice!(i, 2)
|
9
|
+
$: << path
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'ox'
|
14
|
+
|
15
|
+
def dump(cnt = 10000)
|
16
|
+
h = { }
|
17
|
+
cnt.times do |i|
|
18
|
+
h[i] = [i * 2, "this is #{i}"]
|
19
|
+
end
|
20
|
+
xml = Ox.dump(h)
|
21
|
+
puts "size: #{xml.size}"
|
22
|
+
end
|
23
|
+
|
24
|
+
dump(200000)
|
data/test/bug3.rb
CHANGED
@@ -3,19 +3,21 @@
|
|
3
3
|
$: << '../lib'
|
4
4
|
$: << '../ext'
|
5
5
|
|
6
|
+
if __FILE__ == $0
|
7
|
+
if (i = ARGV.index('-I'))
|
8
|
+
x,path = ARGV.slice!(i, 2)
|
9
|
+
$: << path
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
6
13
|
require 'ox'
|
7
14
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
xml = Ox.dump(e, effort: :tolerant)
|
14
|
-
puts xml
|
15
|
-
o = Ox.load(xml, mode: :object)
|
16
|
-
puts o.message
|
17
|
-
puts Ox.dump(e)
|
15
|
+
def dump(cnt = 100000)
|
16
|
+
cnt.times do |i|
|
17
|
+
xml = Ox.dump([:inc, 1])
|
18
|
+
#puts xml
|
19
|
+
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
|
23
|
+
dump()
|
data/test/func.rb
CHANGED
@@ -125,17 +125,25 @@ class Func < ::Test::Unit::TestCase
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def test_range
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
128
|
+
if RUBY_VERSION.start_with?('1.8')
|
129
|
+
assert(true)
|
130
|
+
else
|
131
|
+
dump_and_load((0..3), false)
|
132
|
+
dump_and_load((-2..3.7), false)
|
133
|
+
dump_and_load(('a'...'f'), false)
|
134
|
+
t = Time.now
|
135
|
+
t2 = t + 20
|
136
|
+
dump_and_load((t..t2), false)
|
137
|
+
end
|
134
138
|
end
|
135
139
|
|
136
140
|
def test_regex
|
137
|
-
|
138
|
-
|
141
|
+
if RUBY_VERSION.start_with?('1.8')
|
142
|
+
assert(true)
|
143
|
+
else
|
144
|
+
dump_and_load(/^[0-9]/ix, false)
|
145
|
+
dump_and_load(/^[&0-9]/ix, false) # with xml-unfriendly character
|
146
|
+
end
|
139
147
|
end
|
140
148
|
|
141
149
|
def test_bignum
|
@@ -144,13 +152,21 @@ class Func < ::Test::Unit::TestCase
|
|
144
152
|
end
|
145
153
|
|
146
154
|
def test_complex_number
|
147
|
-
|
148
|
-
|
155
|
+
if RUBY_VERSION.start_with?('1.8')
|
156
|
+
assert(true)
|
157
|
+
else
|
158
|
+
dump_and_load(Complex(1), false)
|
159
|
+
dump_and_load(Complex(3, 2), false)
|
160
|
+
end
|
149
161
|
end
|
150
162
|
|
151
163
|
def test_rational
|
152
|
-
|
153
|
-
|
164
|
+
if RUBY_VERSION.start_with?('1.8')
|
165
|
+
assert(true)
|
166
|
+
else
|
167
|
+
dump_and_load(Rational(1, 3), false)
|
168
|
+
dump_and_load(Rational(0, 3), false)
|
169
|
+
end
|
154
170
|
end
|
155
171
|
|
156
172
|
def test_object
|
@@ -183,27 +199,27 @@ class Func < ::Test::Unit::TestCase
|
|
183
199
|
end
|
184
200
|
|
185
201
|
def test_xml_instruction
|
186
|
-
xml = Ox.dump("test", mode
|
202
|
+
xml = Ox.dump("test", :mode => :object, :with_xml => false)
|
187
203
|
assert_equal("<s>test</s>\n", xml)
|
188
|
-
xml = Ox.dump("test", mode
|
204
|
+
xml = Ox.dump("test", :mode => :object, :with_xml => true)
|
189
205
|
assert_equal("<?xml version=\"1.0\"?>\n<s>test</s>\n", xml)
|
190
|
-
xml = Ox.dump("test", mode
|
206
|
+
xml = Ox.dump("test", :mode => :object, :with_xml => true, :encoding => 'UTF-8')
|
191
207
|
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<s>test</s>\n", xml)
|
192
208
|
end
|
193
209
|
|
194
210
|
def test_ox_instruction
|
195
|
-
xml = Ox.dump("test", mode
|
211
|
+
xml = Ox.dump("test", :mode => :object, :with_xml => true, :with_instructions => true)
|
196
212
|
assert_equal("<?xml version=\"1.0\"?>\n<?ox version=\"1.0\" mode=\"object\" circular=\"no\" xsd_date=\"no\"?>\n<s>test</s>\n", xml)
|
197
|
-
xml = Ox.dump("test", mode
|
213
|
+
xml = Ox.dump("test", :mode => :object, :with_instructions => true)
|
198
214
|
assert_equal("<?ox version=\"1.0\" mode=\"object\" circular=\"no\" xsd_date=\"no\"?>\n<s>test</s>\n", xml)
|
199
|
-
xml = Ox.dump("test", mode
|
215
|
+
xml = Ox.dump("test", :mode => :object, :with_instructions => true, :circular => true, :xsd_date => true)
|
200
216
|
assert_equal("<?ox version=\"1.0\" mode=\"object\" circular=\"yes\" xsd_date=\"yes\"?>\n<s i=\"1\">test</s>\n", xml)
|
201
|
-
xml = Ox.dump("test", mode
|
217
|
+
xml = Ox.dump("test", :mode => :object, :with_instructions => true, :circular => false, :xsd_date => false)
|
202
218
|
assert_equal("<?ox version=\"1.0\" mode=\"object\" circular=\"no\" xsd_date=\"no\"?>\n<s>test</s>\n", xml)
|
203
219
|
end
|
204
220
|
|
205
221
|
def test_dtd
|
206
|
-
xml = Ox.dump("test", mode
|
222
|
+
xml = Ox.dump("test", :mode => :object, :with_dtd => true)
|
207
223
|
assert_equal("<!DOCTYPE s SYSTEM \"ox.dtd\">\n<s>test</s>\n", xml)
|
208
224
|
end
|
209
225
|
|
@@ -212,9 +228,13 @@ class Func < ::Test::Unit::TestCase
|
|
212
228
|
end
|
213
229
|
|
214
230
|
def test_exception
|
215
|
-
|
216
|
-
|
217
|
-
|
231
|
+
if RUBY_VERSION.start_with?('1.8')
|
232
|
+
assert(true)
|
233
|
+
else
|
234
|
+
e = StandardError.new("Some Error")
|
235
|
+
e.set_backtrace(["./func.rb:119: in test_exception",
|
236
|
+
"./fake.rb:57: in fake_func"])
|
237
|
+
end
|
218
238
|
dump_and_load(e, false)
|
219
239
|
end
|
220
240
|
|
@@ -225,25 +245,37 @@ class Func < ::Test::Unit::TestCase
|
|
225
245
|
|
226
246
|
def test_bad_format
|
227
247
|
xml = "<?xml version=\"1.0\"?>\n<tag>test</tagz>\n"
|
228
|
-
assert_raise(
|
248
|
+
assert_raise(SyntaxError) {
|
229
249
|
Ox.load(xml, :mode => :generic, :trace => 0)
|
230
250
|
}
|
231
251
|
end
|
232
252
|
|
233
253
|
def test_array_multi
|
234
|
-
|
254
|
+
if RUBY_VERSION.start_with?('1.8')
|
255
|
+
dump_and_load([nil, true, false, 3, 'z', 7.9, 'a&b', :xyz, Time.now], false)
|
256
|
+
else
|
257
|
+
dump_and_load([nil, true, false, 3, 'z', 7.9, 'a&b', :xyz, Time.now, (-1..7)], false)
|
258
|
+
end
|
235
259
|
end
|
236
260
|
|
237
261
|
def test_hash_multi
|
238
|
-
|
262
|
+
if RUBY_VERSION.start_with?('1.8')
|
263
|
+
dump_and_load({ nil => nil, true => true, false => false, 3 => 3, 'z' => 'z', 7.9 => 7.9, 'a&b' => 'a&b', :xyz => :xyz, Time.now => Time.now }, false)
|
264
|
+
else
|
265
|
+
dump_and_load({ nil => nil, true => true, false => false, 3 => 3, 'z' => 'z', 7.9 => 7.9, 'a&b' => 'a&b', :xyz => :xyz, Time.now => Time.now, (-1..7) => (-1..7) }, false)
|
266
|
+
end
|
239
267
|
end
|
240
268
|
|
241
269
|
def test_object_multi
|
242
|
-
|
270
|
+
if RUBY_VERSION.start_with?('1.8')
|
271
|
+
dump_and_load(Bag.new(:@a => nil, :@b => true, :@c => false, :@d => 3, :@e => 'z', :@f => 7.9, :@g => 'a&b', :@h => :xyz, :@i => Time.now), false)
|
272
|
+
else
|
273
|
+
dump_and_load(Bag.new(:@a => nil, :@b => true, :@c => false, :@d => 3, :@e => 'z', :@f => 7.9, :@g => 'a&b', :@h => :xyz, :@i => Time.now, :@j => (-1..7)), false)
|
274
|
+
end
|
243
275
|
end
|
244
276
|
|
245
277
|
def test_complex
|
246
|
-
dump_and_load(Bag.new(:@o => Bag.new(:@a => [2]), :@a => [1, {b
|
278
|
+
dump_and_load(Bag.new(:@o => Bag.new(:@a => [2]), :@a => [1, {:b => 3, :a => [5], :c => Bag.new(:@x => 7)}]), false)
|
247
279
|
end
|
248
280
|
|
249
281
|
# Create an Object and an Array with the same Objects in them. Dump and load
|
@@ -252,28 +284,34 @@ class Func < ::Test::Unit::TestCase
|
|
252
284
|
# change. Perform the operation on both the object before and the loaded so
|
253
285
|
# the equal() method can be used.
|
254
286
|
def test_circular
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
287
|
+
if RUBY_VERSION.start_with?('1.8')
|
288
|
+
# In 1.8.7 the eql? method behaves differently but the results are
|
289
|
+
# correct when viewed by eye.
|
290
|
+
assert(true)
|
291
|
+
else
|
292
|
+
a = [1]
|
293
|
+
s = "a,b,c"
|
294
|
+
h = { 1 => 2 }
|
295
|
+
e = Ox::Element.new('Zoo')
|
296
|
+
e[:cage] = 'bear'
|
297
|
+
b = Bag.new(:@a => a, :@s => s, :@h => h, :@e => e)
|
298
|
+
a << s
|
299
|
+
a << h
|
300
|
+
a << e
|
301
|
+
a << b
|
302
|
+
loaded = dump_and_load(b, false, true)
|
303
|
+
# modify the string
|
304
|
+
loaded.instance_variable_get(:@s).gsub!(',', '_')
|
305
|
+
b.instance_variable_get(:@s).gsub!(',', '_')
|
306
|
+
# modify hash
|
307
|
+
loaded.instance_variable_get(:@h)[1] = 3
|
308
|
+
b.instance_variable_get(:@h)[1] = 3
|
309
|
+
# modify Element
|
310
|
+
loaded.instance_variable_get(:@e)['pen'] = 'zebra'
|
311
|
+
b.instance_variable_get(:@e)['pen'] = 'zebra'
|
312
|
+
# pp loaded
|
313
|
+
assert_equal(b, loaded)
|
314
|
+
end
|
277
315
|
end
|
278
316
|
|
279
317
|
def test_raw
|
@@ -296,17 +334,21 @@ class Func < ::Test::Unit::TestCase
|
|
296
334
|
end
|
297
335
|
|
298
336
|
def test_encoding
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
337
|
+
if RUBY_VERSION.start_with?('1.8')
|
338
|
+
assert(true)
|
339
|
+
else
|
340
|
+
s = 'ピーター'
|
341
|
+
xml = Ox.dump(s, :with_xml => true, :encoding => 'UTF-8')
|
342
|
+
#puts xml
|
343
|
+
#puts xml.encoding.to_s
|
344
|
+
assert_equal('UTF-8', xml.encoding.to_s)
|
345
|
+
obj = Ox.load(xml, :mode => :object)
|
346
|
+
assert_equal(s, obj)
|
347
|
+
end
|
306
348
|
end
|
307
349
|
|
308
350
|
def test_instructions
|
309
|
-
xml = Ox.dump("test", with_instructions
|
351
|
+
xml = Ox.dump("test", :with_instructions => true)
|
310
352
|
#puts xml
|
311
353
|
obj = Ox.load(xml) # should convert it to an object
|
312
354
|
assert_equal("test", obj)
|
@@ -315,10 +357,10 @@ class Func < ::Test::Unit::TestCase
|
|
315
357
|
def test_IO
|
316
358
|
f = File.open("func.rb", "r")
|
317
359
|
assert_raise(NotImplementedError) {
|
318
|
-
xml = Ox.dump(f, effort
|
360
|
+
xml = Ox.dump(f, :effort => :strict)
|
319
361
|
}
|
320
|
-
xml = Ox.dump(f, effort
|
321
|
-
obj = Ox.load(xml, mode
|
362
|
+
xml = Ox.dump(f, :effort => :tolerant)
|
363
|
+
obj = Ox.load(xml, :mode => :object) # should convert it to an object
|
322
364
|
assert_equal(nil, obj)
|
323
365
|
end
|
324
366
|
|
metadata
CHANGED
@@ -1,28 +1,24 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ox
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.13
|
4
5
|
prerelease:
|
5
|
-
version: 1.2.12
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Peter Ohler
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2011-08-31 00:00:00 +09:00
|
14
|
-
default_executable:
|
12
|
+
date: 2011-09-01 00:00:00.000000000Z
|
15
13
|
dependencies: []
|
16
|
-
|
17
14
|
description: A fast XML parser and object serializer that uses only standard C lib.
|
18
15
|
email: peter@ohler.com
|
19
16
|
executables: []
|
20
|
-
|
21
|
-
extensions:
|
17
|
+
extensions:
|
22
18
|
- ext/ox/extconf.rb
|
23
|
-
extra_rdoc_files:
|
19
|
+
extra_rdoc_files:
|
24
20
|
- README.rdoc
|
25
|
-
files:
|
21
|
+
files:
|
26
22
|
- lib/ox/bag.rb
|
27
23
|
- lib/ox/cdata.rb
|
28
24
|
- lib/ox/comment.rb
|
@@ -47,6 +43,7 @@ files:
|
|
47
43
|
- ext/ox/obj_load.c
|
48
44
|
- ext/ox/ox.c
|
49
45
|
- ext/ox/parse.c
|
46
|
+
- test/big.rb
|
50
47
|
- test/bug1.rb
|
51
48
|
- test/bug2.rb
|
52
49
|
- test/bug3.rb
|
@@ -79,35 +76,31 @@ files:
|
|
79
76
|
- test/Sample.graffle
|
80
77
|
- LICENSE
|
81
78
|
- README.rdoc
|
82
|
-
has_rdoc: true
|
83
79
|
homepage: https://github.com/ohler55/ox
|
84
80
|
licenses: []
|
85
|
-
|
86
81
|
post_install_message:
|
87
|
-
rdoc_options:
|
82
|
+
rdoc_options:
|
88
83
|
- --main
|
89
84
|
- README.rdoc
|
90
|
-
require_paths:
|
85
|
+
require_paths:
|
91
86
|
- lib
|
92
87
|
- ext
|
93
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
89
|
none: false
|
95
|
-
requirements:
|
96
|
-
- -
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version:
|
99
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
95
|
none: false
|
101
|
-
requirements:
|
102
|
-
- -
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version:
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
105
100
|
requirements: []
|
106
|
-
|
107
101
|
rubyforge_project: ox
|
108
|
-
rubygems_version: 1.6
|
102
|
+
rubygems_version: 1.8.6
|
109
103
|
signing_key:
|
110
104
|
specification_version: 3
|
111
105
|
summary: A fast XML parser and object serializer.
|
112
106
|
test_files: []
|
113
|
-
|