The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
{
    "description": "Javascript Code with Scope",
    "bson_type": "0x0F",
    "test_key": "a",
    "valid": [
        {
            "description": "Empty code string, empty scope",
            "bson": "160000000F61000E0000000100000000050000000000",
            "extjson": "{\"a\" : {\"$code\" : \"\", \"$scope\" : {}}}"
        },
        {
            "description": "Non-empty code string, empty scope",
            "bson": "1A0000000F610012000000050000006162636400050000000000",
            "extjson": "{\"a\" : {\"$code\" : \"abcd\", \"$scope\" : {}}}"
        },
        {
            "description": "Empty code string, non-empty scope",
            "bson": "1D0000000F61001500000001000000000C000000107800010000000000",
            "extjson": "{\"a\" : {\"$code\" : \"\", \"$scope\" : {\"x\" : 1}}}"
        },
        {
            "description": "Non-empty code string and non-empty scope",
            "bson": "210000000f6100190000000500000061626364000c000000107800010000000000",
            "extjson": "{\"a\" : {\"$code\" : \"abcd\", \"$scope\" : {\"x\" : 1}}}"
        },
        {
            "description": "Unicode and embedded null in code string, empty scope",
            "bson": "1A0000000F61001200000005000000C3A9006400050000000000",
            "extjson": "{\"a\" : {\"$code\" : \"\\u00e9\\u0000d\", \"$scope\" : {}}}"
        }
    ],
    "decodeErrors": [
        {
            "description": "field length zero",
            "bson": "280000000F6100000000000500000061626364001300000010780001000000107900010000000000"
        },
        {
            "description": "field length negative",
            "bson": "280000000F6100FFFFFFFF0500000061626364001300000010780001000000107900010000000000"
        },
        {
            "description": "field length too short (less than minimum size)",
            "bson": "160000000F61000D0000000100000000050000000000"
        },
        {
            "description": "field length too short (truncates scope)",
            "bson": "280000000F61001F0000000500000061626364001300000010780001000000107900010000000000"
        },
        {
            "description": "field length too long (clips outer doc)",
            "bson": "280000000F6100210000000500000061626364001300000010780001000000107900010000000000"
        },
        {
            "description": "field length too long (longer than outer doc)",
            "bson": "280000000F6100FF0000000500000061626364001300000010780001000000107900010000000000"
        },
        {
            "description": "bad code string: length too short",
            "bson": "280000000F6100200000000400000061626364001300000010780001000000107900010000000000"
        },
        {
            "description": "bad code string: length too long (clips scope)",
            "bson": "280000000F6100200000000600000061626364001300000010780001000000107900010000000000"
        },
        {
            "description": "bad code string: negative length",
            "bson": "280000000F610020000000FFFFFFFF61626364001300000010780001000000107900010000000000"
        },
        {
            "description": "bad code string: length longer than field",
            "bson": "280000000F610020000000FF00000061626364001300000010780001000000107900010000000000"
        },
        {
            "description": "bad scope doc (field has bad string length)",
            "bson": "1C0000000F001500000001000000000C000000020000000000000000"
        }
    ]
}