bson 4.2.0.rc1-java → 4.2.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/bson-ruby.jar +0 -0
  5. data/lib/bson/array.rb +1 -1
  6. data/lib/bson/binary.rb +4 -2
  7. data/lib/bson/code.rb +1 -1
  8. data/lib/bson/code_with_scope.rb +1 -1
  9. data/lib/bson/date.rb +1 -1
  10. data/lib/bson/date_time.rb +1 -1
  11. data/lib/bson/decimal128.rb +2 -2
  12. data/lib/bson/false_class.rb +1 -1
  13. data/lib/bson/float.rb +1 -1
  14. data/lib/bson/hash.rb +1 -1
  15. data/lib/bson/integer.rb +1 -1
  16. data/lib/bson/object_id.rb +1 -1
  17. data/lib/bson/open_struct.rb +1 -1
  18. data/lib/bson/regexp.rb +87 -19
  19. data/lib/bson/specialized.rb +1 -1
  20. data/lib/bson/string.rb +1 -1
  21. data/lib/bson/symbol.rb +1 -1
  22. data/lib/bson/time.rb +1 -1
  23. data/lib/bson/timestamp.rb +1 -1
  24. data/lib/bson/true_class.rb +1 -1
  25. data/lib/bson/version.rb +1 -1
  26. data/spec/bson/array_spec.rb +1 -1
  27. data/spec/bson/binary_spec.rb +2 -1
  28. data/spec/bson/corpus_spec.rb +68 -0
  29. data/spec/bson/decimal128_spec.rb +5 -1
  30. data/spec/bson/int64_spec.rb +47 -0
  31. data/spec/bson/raw_spec.rb +562 -0
  32. data/spec/bson/regexp_spec.rb +7 -7
  33. data/spec/spec_helper.rb +1 -0
  34. data/spec/support/corpus-tests/array.json +43 -0
  35. data/spec/support/corpus-tests/boolean.json +27 -0
  36. data/spec/support/corpus-tests/code.json +67 -0
  37. data/spec/support/corpus-tests/code_w_scope.json +78 -0
  38. data/spec/support/corpus-tests/document.json +36 -0
  39. data/spec/support/corpus-tests/double.json +69 -0
  40. data/spec/support/corpus-tests/failures/binary.json +69 -0
  41. data/spec/support/corpus-tests/failures/datetime.json +31 -0
  42. data/spec/support/corpus-tests/failures/dbpointer.json +42 -0
  43. data/spec/support/corpus-tests/failures/int64.json +38 -0
  44. data/spec/support/corpus-tests/failures/symbol.json +62 -0
  45. data/spec/support/corpus-tests/failures/undefined.json +13 -0
  46. data/spec/support/corpus-tests/int32.json +38 -0
  47. data/spec/support/corpus-tests/maxkey.json +12 -0
  48. data/spec/support/corpus-tests/minkey.json +12 -0
  49. data/spec/support/corpus-tests/null.json +12 -0
  50. data/spec/support/corpus-tests/oid.json +28 -0
  51. data/spec/support/corpus-tests/regex.json +37 -0
  52. data/spec/support/corpus-tests/string.json +67 -0
  53. data/spec/support/corpus-tests/timestamp.json +18 -0
  54. data/spec/support/corpus-tests/top.json +62 -0
  55. data/spec/support/corpus.rb +265 -0
  56. data/spec/support/shared_examples.rb +1 -1
  57. metadata +51 -3
  58. metadata.gz.sig +0 -0
@@ -24,7 +24,7 @@ describe Regexp do
24
24
 
25
25
  it "returns the binary data plus type" do
26
26
  expect(object.as_json).to eq(
27
- { "$regex" => "\\W+", "$options" => "i" }
27
+ { "$regex" => "\\W+", "$options" => "im" }
28
28
  )
29
29
  end
30
30
 
@@ -55,9 +55,7 @@ describe Regexp do
55
55
  /\d+/
56
56
  end
57
57
 
58
- let :bson do
59
- [obj.source, BSON::NULL_BYTE, BSON::NULL_BYTE].join ''
60
- end
58
+ let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}m#{BSON::NULL_BYTE}" }
61
59
 
62
60
  it_behaves_like "a serializable bson element"
63
61
 
@@ -69,7 +67,9 @@ describe Regexp do
69
67
  context "when the regexp has no options" do
70
68
 
71
69
  let(:obj) { /\d+/ }
72
- let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}#{BSON::NULL_BYTE}" }
70
+ # Ruby always has a BSON regex's equivalent of multiline on
71
+ # http://www.regular-expressions.info/modifiers.html
72
+ let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}m#{BSON::NULL_BYTE}" }
73
73
 
74
74
  it_behaves_like "a serializable bson element"
75
75
 
@@ -83,7 +83,7 @@ describe Regexp do
83
83
  context "when ignoring case" do
84
84
 
85
85
  let(:obj) { /\W+/i }
86
- let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}i#{BSON::NULL_BYTE}" }
86
+ let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}im#{BSON::NULL_BYTE}" }
87
87
 
88
88
  it_behaves_like "a serializable bson element"
89
89
 
@@ -107,7 +107,7 @@ describe Regexp do
107
107
  context "when matching extended" do
108
108
 
109
109
  let(:obj) { /\W+/x }
110
- let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}x#{BSON::NULL_BYTE}" }
110
+ let(:bson) { "#{obj.source}#{BSON::NULL_BYTE}mx#{BSON::NULL_BYTE}" }
111
111
 
112
112
  it_behaves_like "a serializable bson element"
113
113
 
@@ -14,6 +14,7 @@
14
14
 
15
15
  CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
16
16
  DRIVER_COMMON_BSON_TESTS = Dir.glob("#{CURRENT_PATH}/support/driver-spec-tests/**/*.json")
17
+ BSON_CORPUS_TESTS = Dir.glob("#{CURRENT_PATH}/support/corpus-tests/*.json")
17
18
 
18
19
  $LOAD_PATH.unshift(File.dirname(__FILE__))
19
20
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
@@ -0,0 +1,43 @@
1
+ {
2
+ "description": "Array",
3
+ "bson_type": "0x04",
4
+ "test_key": "a",
5
+ "valid": [
6
+ {
7
+ "description": "Empty",
8
+ "bson": "0D000000046100050000000000",
9
+ "extjson": "{\"a\" : []}"
10
+ },
11
+ {
12
+ "description": "Single Element Array",
13
+ "bson": "140000000461000C0000001030000A0000000000",
14
+ "extjson": "{\"a\" : [10]}"
15
+ },
16
+ {
17
+ "description": "Single Element Array with index set incorrectly",
18
+ "bson": "130000000461000B00000010000A0000000000",
19
+ "canonical_bson": "140000000461000C0000001030000A0000000000",
20
+ "extjson": "{\"a\" : [10]}"
21
+ },
22
+ {
23
+ "description": "Single Element Array with index set incorrectly",
24
+ "bson": "150000000461000D000000106162000A0000000000",
25
+ "canonical_bson": "140000000461000C0000001030000A0000000000",
26
+ "extjson": "{\"a\" : [10]}"
27
+ }
28
+ ],
29
+ "decodeErrors": [
30
+ {
31
+ "description": "Array length too long: eats outer terminator",
32
+ "bson": "140000000461000D0000001030000A0000000000"
33
+ },
34
+ {
35
+ "description": "Array length too short: leaks terminator",
36
+ "bson": "140000000461000B0000001030000A0000000000"
37
+ },
38
+ {
39
+ "description": "Invalid Array: bad string length in field",
40
+ "bson": "1A00000004666F6F00100000000230000500000062617A000000"
41
+ }
42
+ ]
43
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "description": "Boolean",
3
+ "bson_type": "0x08",
4
+ "test_key": "b",
5
+ "valid": [
6
+ {
7
+ "description": "True",
8
+ "bson": "090000000862000100",
9
+ "extjson": "{\"b\" : true}"
10
+ },
11
+ {
12
+ "description": "False",
13
+ "bson": "090000000862000000",
14
+ "extjson": "{\"b\" : false}"
15
+ }
16
+ ],
17
+ "decodeErrors": [
18
+ {
19
+ "description": "Invalid boolean value of 2",
20
+ "bson": "090000000862000200"
21
+ },
22
+ {
23
+ "description": "Invalid boolean value of -1",
24
+ "bson": "09000000086200FF00"
25
+ }
26
+ ]
27
+ }
@@ -0,0 +1,67 @@
1
+ {
2
+ "description": "Javascript Code",
3
+ "bson_type": "0x0D",
4
+ "test_key": "a",
5
+ "valid": [
6
+ {
7
+ "description": "Empty string",
8
+ "bson": "0D0000000D6100010000000000",
9
+ "extjson": "{\"a\" : {\"$code\" : \"\"}}"
10
+ },
11
+ {
12
+ "description": "Single character",
13
+ "bson": "0E0000000D610002000000620000",
14
+ "extjson": "{\"a\" : {\"$code\" : \"b\"}}"
15
+ },
16
+ {
17
+ "description": "Multi-character",
18
+ "bson": "190000000D61000D0000006162616261626162616261620000",
19
+ "extjson": "{\"a\" : {\"$code\" : \"abababababab\"}}"
20
+ },
21
+ {
22
+ "description": "two-byte UTF-8 (\u00e9)",
23
+ "bson": "190000000261000D000000C3A9C3A9C3A9C3A9C3A9C3A90000",
24
+ "extjson": "{\"a\" : \"\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\"}"
25
+ },
26
+ {
27
+ "description": "three-byte UTF-8 (\u2606)",
28
+ "bson": "190000000261000D000000E29886E29886E29886E298860000",
29
+ "extjson": "{\"a\" : \"\\u2606\\u2606\\u2606\\u2606\"}"
30
+ },
31
+ {
32
+ "description": "Embedded nulls",
33
+ "bson": "190000000261000D0000006162006261620062616261620000",
34
+ "extjson": "{\"a\" : \"ab\\u0000bab\\u0000babab\"}"
35
+ }
36
+ ],
37
+ "decodeErrors": [
38
+ {
39
+ "description": "bad code string length: 0 (but no 0x00 either)",
40
+ "bson": "0C0000000261000000000000"
41
+ },
42
+ {
43
+ "description": "bad code string length: -1",
44
+ "bson": "0C000000026100FFFFFFFF00"
45
+ },
46
+ {
47
+ "description": "bad code string length: eats terminator",
48
+ "bson": "10000000026100050000006200620000"
49
+ },
50
+ {
51
+ "description": "bad code string length: longer than rest of document",
52
+ "bson": "120000000200FFFFFF00666F6F6261720000"
53
+ },
54
+ {
55
+ "description": "code string is not null-terminated",
56
+ "bson": "1000000002610004000000616263FF00"
57
+ },
58
+ {
59
+ "description": "empty code string, but extra null",
60
+ "bson": "0E00000002610001000000000000"
61
+ },
62
+ {
63
+ "description": "invalid UTF-8",
64
+ "bson": "0E00000002610002000000E90000"
65
+ }
66
+ ]
67
+ }
@@ -0,0 +1,78 @@
1
+ {
2
+ "description": "Javascript Code with Scope",
3
+ "bson_type": "0x0F",
4
+ "test_key": "a",
5
+ "valid": [
6
+ {
7
+ "description": "Empty code string, empty scope",
8
+ "bson": "160000000F61000E0000000100000000050000000000",
9
+ "extjson": "{\"a\" : {\"$code\" : \"\", \"$scope\" : {}}}"
10
+ },
11
+ {
12
+ "description": "Non-empty code string, empty scope",
13
+ "bson": "1A0000000F610012000000050000006162636400050000000000",
14
+ "extjson": "{\"a\" : {\"$code\" : \"abcd\", \"$scope\" : {}}}"
15
+ },
16
+ {
17
+ "description": "Empty code string, non-empty scope",
18
+ "bson": "1D0000000F61001500000001000000000C000000107800010000000000",
19
+ "extjson": "{\"a\" : {\"$code\" : \"\", \"$scope\" : {\"x\" : 1}}}"
20
+ },
21
+ {
22
+ "description": "Non-empty code string and non-empty scope",
23
+ "bson": "210000000F6100190000000500000061626364000C000000107800010000000000",
24
+ "extjson": "{\"a\" : {\"$code\" : \"abcd\", \"$scope\" : {\"x\" : 1}}}"
25
+ },
26
+ {
27
+ "description": "Unicode and embedded null in code string, empty scope",
28
+ "bson": "1A0000000F61001200000005000000C3A9006400050000000000",
29
+ "extjson": "{\"a\" : {\"$code\" : \"\\u00e9\\u0000d\", \"$scope\" : {}}}"
30
+ }
31
+ ],
32
+ "decodeErrors": [
33
+ {
34
+ "description": "field length zero",
35
+ "bson": "280000000F6100000000000500000061626364001300000010780001000000107900010000000000"
36
+ },
37
+ {
38
+ "description": "field length negative",
39
+ "bson": "280000000F6100FFFFFFFF0500000061626364001300000010780001000000107900010000000000"
40
+ },
41
+ {
42
+ "description": "field length too short (less than minimum size)",
43
+ "bson": "160000000F61000D0000000100000000050000000000"
44
+ },
45
+ {
46
+ "description": "field length too short (truncates scope)",
47
+ "bson": "280000000F61001F0000000500000061626364001300000010780001000000107900010000000000"
48
+ },
49
+ {
50
+ "description": "field length too long (clips outer doc)",
51
+ "bson": "280000000F6100210000000500000061626364001300000010780001000000107900010000000000"
52
+ },
53
+ {
54
+ "description": "field length too long (longer than outer doc)",
55
+ "bson": "280000000F6100FF0000000500000061626364001300000010780001000000107900010000000000"
56
+ },
57
+ {
58
+ "description": "bad code string: length too short",
59
+ "bson": "280000000F6100200000000400000061626364001300000010780001000000107900010000000000"
60
+ },
61
+ {
62
+ "description": "bad code string: length too long (clips scope)",
63
+ "bson": "280000000F6100200000000600000061626364001300000010780001000000107900010000000000"
64
+ },
65
+ {
66
+ "description": "bad code string: negative length",
67
+ "bson": "280000000F610020000000FFFFFFFF61626364001300000010780001000000107900010000000000"
68
+ },
69
+ {
70
+ "description": "bad code string: length longer than field",
71
+ "bson": "280000000F610020000000FF00000061626364001300000010780001000000107900010000000000"
72
+ },
73
+ {
74
+ "description": "bad scope doc (field has bad string length)",
75
+ "bson": "1C0000000F001500000001000000000C000000020000000000000000"
76
+ }
77
+ ]
78
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "description": "Document type (sub-documents)",
3
+ "bson_type": "0x03",
4
+ "test_key": "x",
5
+ "valid": [
6
+ {
7
+ "description": "Empty subdoc",
8
+ "bson": "0D000000037800050000000000",
9
+ "extjson": "{\"x\" : {}}"
10
+ },
11
+ {
12
+ "description": "Empty-string key subdoc",
13
+ "bson": "150000000378000D00000002000200000062000000",
14
+ "extjson": "{\"x\" : {\"\" : \"b\"}}"
15
+ },
16
+ {
17
+ "description": "Single-character key subdoc",
18
+ "bson": "160000000378000E0000000261000200000062000000",
19
+ "extjson": "{\"x\" : {\"a\" : \"b\"}}"
20
+ }
21
+ ],
22
+ "decodeErrors": [
23
+ {
24
+ "description": "Subdocument length too long: eats outer terminator",
25
+ "bson": "1800000003666F6F000F0000001062617200FFFFFF7F0000"
26
+ },
27
+ {
28
+ "description": "Subdocument length too short: leaks terminator",
29
+ "bson": "1500000003666F6F000A0000000862617200010000"
30
+ },
31
+ {
32
+ "description": "Invalid subdocument: bad string length in field",
33
+ "bson": "1C00000003666F6F001200000002626172000500000062617A000000"
34
+ }
35
+ ]
36
+ }
@@ -0,0 +1,69 @@
1
+ {
2
+ "description": "Double type",
3
+ "bson_type": "0x01",
4
+ "test_key": "d",
5
+ "valid": [
6
+ {
7
+ "description": "+1.0",
8
+ "bson": "10000000016400000000000000F03F00",
9
+ "extjson": "{\"d\" : 1.0}"
10
+ },
11
+ {
12
+ "description": "-1.0",
13
+ "bson": "10000000016400000000000000F0BF00",
14
+ "extjson": "{\"d\" : -1.0}"
15
+ },
16
+ {
17
+ "description": "+1.0001220703125",
18
+ "bson": "10000000016400000000008000F03F00",
19
+ "extjson": "{\"d\" : 1.0001220703125}"
20
+ },
21
+ {
22
+ "description": "-1.0001220703125",
23
+ "bson": "10000000016400000000008000F0BF00",
24
+ "extjson": "{\"d\" : -1.0001220703125}"
25
+ },
26
+ {
27
+ "description": "+2.0001220703125e10",
28
+ "bson": "1000000001640000807ca1a9a0124200",
29
+ "extjson": "{\"d\" : 2.0001220703125e10}"
30
+ },
31
+ {
32
+ "description": "-2.0001220703125e10",
33
+ "bson": "1000000001640000807ca1a9a012c200",
34
+ "extjson": "{\"d\" : -2.0001220703125e10}"
35
+ },
36
+ {
37
+ "description": "0.0",
38
+ "bson": "10000000016400000000000000000000",
39
+ "extjson": "{\"d\" : 0.0}"
40
+ },
41
+ {
42
+ "description": "-0.0",
43
+ "bson": "10000000016400000000000000008000",
44
+ "extjson": "{\"d\" : -0.0}"
45
+ },
46
+ {
47
+ "description": "NaN",
48
+ "bson": "10000000016400000000000000F87F00"
49
+ },
50
+ {
51
+ "description": "NaN with payload",
52
+ "bson": "10000000016400120000000000F87F00"
53
+ },
54
+ {
55
+ "description": "Inf",
56
+ "bson": "10000000016400000000000000F07F00"
57
+ },
58
+ {
59
+ "description": "-Inf",
60
+ "bson": "10000000016400000000000000F0FF00"
61
+ }
62
+ ],
63
+ "decodeErrors": [
64
+ {
65
+ "description": "double truncated",
66
+ "bson": "0B0000000164000000F03F00"
67
+ }
68
+ ]
69
+ }
@@ -0,0 +1,69 @@
1
+ {
2
+ "description": "Binary type",
3
+ "bson_type": "0x05",
4
+ "test_key": "x",
5
+ "valid": [
6
+ {
7
+ "description": "subtype 0x00 (Zero-length)",
8
+ "bson": "0D000000057800000000000000",
9
+ "extjson": "{\"x\" : {\"$binary\" : \"\", \"$type\" : \"00\"}}"
10
+ },
11
+ {
12
+ "description": "subtype 0x00",
13
+ "bson": "0F0000000578000200000000FFFF00",
14
+ "extjson": "{\"x\" : {\"$binary\" : \"//8=\", \"$type\" : \"00\"}}"
15
+ },
16
+ {
17
+ "description": "subtype 0x01",
18
+ "bson": "0F0000000578000200000001FFFF00",
19
+ "extjson": "{\"x\" : {\"$binary\" : \"//8=\", \"$type\" : \"01\"}}"
20
+ },
21
+ {
22
+ "description": "subtype 0x02",
23
+ "bson": "13000000057800060000000202000000ffff00",
24
+ "extjson": "{\"x\" : {\"$binary\" : \"//8=\", \"$type\" : \"02\"}}"
25
+ },
26
+ {
27
+ "description": "subtype 0x03",
28
+ "bson": "1D000000057800100000000373FFD26444B34C6990E8E7D1DFC035D400",
29
+ "extjson": "{\"x\" : {\"$binary\" : \"c//SZESzTGmQ6OfR38A11A==\", \"$type\" : \"03\"}}"
30
+ },
31
+ {
32
+ "description": "subtype 0x04",
33
+ "bson": "1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400",
34
+ "extjson": "{\"x\" : {\"$binary\" : \"c//SZESzTGmQ6OfR38A11A==\", \"$type\" : \"04\"}}"
35
+ },
36
+ {
37
+ "description": "subtype 0x05",
38
+ "bson": "1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400",
39
+ "extjson": "{\"x\" : {\"$binary\" : \"c//SZESzTGmQ6OfR38A11A==\", \"$type\" : \"05\"}}"
40
+ },
41
+ {
42
+ "description": "subtype 0x80",
43
+ "bson": "0F0000000578000200000080FFFF00",
44
+ "extjson": "{\"x\" : {\"$binary\" : \"//8=\", \"$type\" : \"80\"}}"
45
+ }
46
+ ],
47
+ "decodeErrors": [
48
+ {
49
+ "description": "Length longer than document",
50
+ "bson": "1D000000057800FF0000000573FFD26444B34C6990E8E7D1DFC035D400"
51
+ },
52
+ {
53
+ "description": "Negative length",
54
+ "bson": "0D000000057800FFFFFFFF0000"
55
+ },
56
+ {
57
+ "description": "subtype 0x02 length too long ",
58
+ "bson": "13000000057800060000000203000000FFFF00"
59
+ },
60
+ {
61
+ "description": "subtype 0x02 length too short",
62
+ "bson": "13000000057800060000000201000000FFFF00"
63
+ },
64
+ {
65
+ "description": "subtype 0x02 length negative one",
66
+ "bson": "130000000578000600000002FFFFFFFFFFFF00"
67
+ }
68
+ ]
69
+ }