bson 4.1.1-java → 4.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +18 -3
  5. data/lib/bson-ruby.jar +0 -0
  6. data/lib/bson.rb +6 -4
  7. data/lib/bson/array.rb +1 -1
  8. data/lib/bson/binary.rb +4 -2
  9. data/lib/bson/code.rb +1 -1
  10. data/lib/bson/code_with_scope.rb +1 -1
  11. data/lib/bson/config.rb +1 -1
  12. data/lib/bson/date.rb +1 -1
  13. data/lib/bson/date_time.rb +1 -1
  14. data/lib/bson/decimal128.rb +318 -0
  15. data/lib/bson/decimal128/builder.rb +448 -0
  16. data/lib/bson/document.rb +2 -2
  17. data/lib/bson/environment.rb +13 -1
  18. data/lib/bson/false_class.rb +1 -1
  19. data/lib/bson/float.rb +1 -1
  20. data/lib/bson/hash.rb +1 -1
  21. data/lib/bson/int32.rb +46 -0
  22. data/lib/bson/int64.rb +46 -0
  23. data/lib/bson/integer.rb +1 -1
  24. data/lib/bson/max_key.rb +1 -1
  25. data/lib/bson/min_key.rb +1 -1
  26. data/lib/bson/object_id.rb +3 -2
  27. data/lib/bson/open_struct.rb +57 -0
  28. data/lib/bson/regexp.rb +87 -19
  29. data/lib/bson/registry.rb +1 -1
  30. data/lib/bson/specialized.rb +1 -1
  31. data/lib/bson/string.rb +1 -1
  32. data/lib/bson/symbol.rb +1 -1
  33. data/lib/bson/time.rb +1 -1
  34. data/lib/bson/timestamp.rb +2 -2
  35. data/lib/bson/true_class.rb +1 -1
  36. data/lib/bson/version.rb +2 -2
  37. data/spec/bson/array_spec.rb +1 -1
  38. data/spec/bson/binary_spec.rb +2 -1
  39. data/spec/bson/corpus_spec.rb +68 -0
  40. data/spec/bson/decimal128_spec.rb +1583 -0
  41. data/spec/bson/document_spec.rb +1 -1
  42. data/spec/bson/driver_bson_spec.rb +77 -0
  43. data/spec/bson/int32_spec.rb +58 -0
  44. data/spec/bson/int64_spec.rb +58 -0
  45. data/spec/bson/open_struct_spec.rb +144 -0
  46. data/spec/bson/raw_spec.rb +540 -0
  47. data/spec/bson/regexp_spec.rb +7 -7
  48. data/spec/bson/timestamp_spec.rb +1 -1
  49. data/spec/spec_helper.rb +5 -0
  50. data/spec/support/common_driver.rb +347 -0
  51. data/spec/support/corpus-tests/array.json +43 -0
  52. data/spec/support/corpus-tests/boolean.json +27 -0
  53. data/spec/support/corpus-tests/code.json +67 -0
  54. data/spec/support/corpus-tests/code_w_scope.json +78 -0
  55. data/spec/support/corpus-tests/document.json +36 -0
  56. data/spec/support/corpus-tests/double.json +69 -0
  57. data/spec/support/corpus-tests/failures/binary.json +69 -0
  58. data/spec/support/corpus-tests/failures/datetime.json +31 -0
  59. data/spec/support/corpus-tests/failures/dbpointer.json +42 -0
  60. data/spec/support/corpus-tests/failures/int64.json +38 -0
  61. data/spec/support/corpus-tests/failures/symbol.json +62 -0
  62. data/spec/support/corpus-tests/failures/undefined.json +13 -0
  63. data/spec/support/corpus-tests/int32.json +38 -0
  64. data/spec/support/corpus-tests/maxkey.json +12 -0
  65. data/spec/support/corpus-tests/minkey.json +12 -0
  66. data/spec/support/corpus-tests/null.json +12 -0
  67. data/spec/support/corpus-tests/oid.json +28 -0
  68. data/spec/support/corpus-tests/regex.json +37 -0
  69. data/spec/support/corpus-tests/string.json +67 -0
  70. data/spec/support/corpus-tests/timestamp.json +18 -0
  71. data/spec/support/corpus-tests/top.json +62 -0
  72. data/spec/support/corpus.rb +265 -0
  73. data/spec/support/driver-spec-tests/decimal128/decimal128-1.json +363 -0
  74. data/spec/support/driver-spec-tests/decimal128/decimal128-2.json +793 -0
  75. data/spec/support/driver-spec-tests/decimal128/decimal128-3.json +1771 -0
  76. data/spec/support/driver-spec-tests/decimal128/decimal128-4.json +165 -0
  77. data/spec/support/driver-spec-tests/decimal128/decimal128-5.json +402 -0
  78. data/spec/support/driver-spec-tests/decimal128/decimal128-6.json +131 -0
  79. data/spec/support/driver-spec-tests/decimal128/decimal128-7.json +327 -0
  80. data/spec/support/shared_examples.rb +1 -1
  81. metadata +77 -4
  82. metadata.gz.sig +0 -0
@@ -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
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "description": "DateTime",
3
+ "bson_type": "0x09",
4
+ "test_key": "a",
5
+ "valid": [
6
+ {
7
+ "description": "epoch",
8
+ "bson": "10000000096100000000000000000000",
9
+ "extjson": "{\"a\" : {\"$date\" : \"1970-01-01T00:00:00.000Z\"}}",
10
+ "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"0\"}}}"
11
+ },
12
+ {
13
+ "description": "positive ms",
14
+ "bson": "10000000096100C4D8D6CC3B01000000",
15
+ "extjson": "{\"a\" : {\"$date\" : \"2012-12-24T12:15:30.500Z\"}}",
16
+ "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"1356351330500\"}}}"
17
+ },
18
+ {
19
+ "description": "negative",
20
+ "bson": "10000000096100C43CE7B9BDFFFFFF00",
21
+ "extjson": "{\"a\" : {\"$date\" : \"1960-12-24T12:15:30.500Z\"}}",
22
+ "canonical_extjson": "{\"a\" : {\"$date\" : {\"$numberLong\" : \"-284643869500\"}}}"
23
+ }
24
+ ],
25
+ "decodeErrors": [
26
+ {
27
+ "description": "datetime field truncated",
28
+ "bson": "0C0000000961001234567800"
29
+ }
30
+ ]
31
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "description": "DBPointer type (deprecated)",
3
+ "bson_type": "0x0C",
4
+ "deprecated": true,
5
+ "test_key": "a",
6
+ "valid": [
7
+ {
8
+ "description": "DBpointer",
9
+ "bson": "1A0000000C610002000000620056E1FC72E0C917E9C471416100"
10
+ },
11
+ {
12
+ "description": "With two-byte UTF-8",
13
+ "bson": "1B0000000C610003000000C3A90056E1FC72E0C917E9C471416100"
14
+ }
15
+ ],
16
+ "decodeErrors": [
17
+ {
18
+ "description": "String with negative length",
19
+ "bson": "1A0000000C6100FFFFFFFF620056E1FC72E0C917E9C471416100"
20
+ },
21
+ {
22
+ "description": "String with zero length",
23
+ "bson": "1A0000000C610000000000620056E1FC72E0C917E9C471416100"
24
+ },
25
+ {
26
+ "description": "String not null terminated",
27
+ "bson": "1A0000000C610002000000626256E1FC72E0C917E9C471416100"
28
+ },
29
+ {
30
+ "description": "short OID (less than minimum length for field)",
31
+ "bson": "160000000C61000300000061620056E1FC72E0C91700"
32
+ },
33
+ {
34
+ "description": "short OID (greater than minimum, but truncated)",
35
+ "bson": "1A0000000C61000300000061620056E1FC72E0C917E9C4716100"
36
+ },
37
+ {
38
+ "description": "String with bad UTF-8",
39
+ "bson": "1A0000000C610002000000E90056E1FC72E0C917E9C471416100"
40
+ }
41
+ ]
42
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "description": "Int64 type",
3
+ "bson_type": "0x12",
4
+ "test_key": "a",
5
+ "valid": [
6
+ {
7
+ "description": "MinValue",
8
+ "bson": "10000000126100000000000000008000",
9
+ "extjson": "{\"a\" : {\"$numberLong\" : \"-9223372036854775808\"}}"
10
+ },
11
+ {
12
+ "description": "MaxValue",
13
+ "bson": "10000000126100FFFFFFFFFFFFFF7F00",
14
+ "extjson": "{\"a\" : {\"$numberLong\" : \"9223372036854775807\"}}"
15
+ },
16
+ {
17
+ "description": "-1",
18
+ "bson": "10000000126100FFFFFFFFFFFFFFFF00",
19
+ "extjson": "{\"a\" : {\"$numberLong\" : \"-1\"}}"
20
+ },
21
+ {
22
+ "description": "0",
23
+ "bson": "10000000126100000000000000000000",
24
+ "extjson": "{\"a\" : {\"$numberLong\" : \"0\"}}"
25
+ },
26
+ {
27
+ "description": "1",
28
+ "bson": "10000000126100010000000000000000",
29
+ "extjson": "{\"a\" : {\"$numberLong\" : \"1\"}}"
30
+ }
31
+ ],
32
+ "decodeErrors": [
33
+ {
34
+ "description": "int64 field truncated",
35
+ "bson": "0C0000001261001234567800"
36
+ }
37
+ ]
38
+ }