from clarabot_nano.utility.serialize import msgpack_loads, msgpack_loads_strict_map_key, bigger_int_from_js_msgpack


def test_msgpack_ext_hook():
    ext_18 = b"\xc7\x06\x12\x01\x02\x03\x04\x05\x06"
    ext_26 = b"\xc7\x06\x1a\x01\x02\x03\x04\x05\x06"
    for loads in [msgpack_loads, msgpack_loads_strict_map_key]:
        assert loads(ext_18) == b"\x01\x02\x03\x04\x05\x06"
        assert loads(ext_26) == b"\x01\x02\x03\x04\x05\x06"


def test_bigger_int_from_js_msgpack():
    assert bigger_int_from_js_msgpack(1619720759111.0) == 1619720759111
    assert bigger_int_from_js_msgpack(1619720759111) == 1619720759111
    assert bigger_int_from_js_msgpack(1619720759111.001) == 1619720759111.001
    assert bigger_int_from_js_msgpack(None) is None
    assert bigger_int_from_js_msgpack("asd") == "asd"
