<commit_before>local marshall_v2 = require "cassandra.marshallers.marshall_v2"
local unsmarshall_v2 = require "cassandra.marshallers.unmarshall_v2"

describe("Marshallers v2", function()

  local fixtures = {
    -- custom
    ascii = {"ascii"},
    bigint = {0, 42, -42, 42000000000, -42000000000},
    blob = {"\005\042", string.rep("blob", 10000)},
    boolean = {true, false},
    --counter
    -- decimal
    double = {0, 1.0000000000000004, -1.0000000000000004},
    float = {0, 3.14151, -3.14151},
    int = {0, 4200, -42},
    text = {"some text"},
    timestamp = {1405356926},
    uuid = {"1144bada-852c-11e3-89fb-e0b9a54a6d11"},
    varchar = {"string"},
    varint = {0, 4200, -42},
    timeuuid = {"1144bada-852c-11e3-89fb-e0b9a54a6d11"},
    inet = {["127.0.0.1"] = "127.0.0.1",
            ["2001:0db8:85a3:0042:1000:8a2e:0370:7334"] = "2001:0db8:85a3:0042:1000:8a2e:0370:7334",
            ["2001:0db8:0000:0000:0000:0000:0000:0001"] = "2001:db8::1",
            ["2001:0db8:85a3:0000:0000:0000:0000:0010"] = "2001:db8:85a3::10",
            ["2001:0db8:85a3:0000:0000:0000:0000:0100"] = "2001:db8:85a3::100",
            ["0000:0000:0000:0000:0000:0000:0000:0001"] = "::1",
            ["0000:0000:0000:0000:0000:0000:0000:0000"] = "::"}
  }

  for fix_type, fix_values in pairs(fixtures) do
    it("should encode and decode a ["..fix_type.."]", function()
      for expected, fix_value in ipairs(fix_values) do
        local encoded = marshall_v2.value_representation(fix_value, marshall_v2.TYPES[fix_type])
        local buffer = unsmarshall_v2.create_buffer(encoded)
        local decoded = unsmarshall_v2.read_value(buffer, { id = marshall_v2.TYPES[fix_type] })

        if fix_type == "float" then
          local delta = 0.0000001
          assert.True(math.abs(decoded - fix_value) < delta)
        elseif fix_type == "inet" then
          assert.equal(expected, decoded)
        else
          assert.equal(fix_value, decoded)
        end
      end
    end)
  end

  it("should encode and decode a [list]", function()
    local list_fixtures = {
      { value_type = "text", value = {"abc", "def"} },
      { value_type = "int", value = {0, 1, 2, 42, -42} },
    }

    for _, fixture in ipairs(list_fixtures) do
      local encoded = marshall_v2.value_representation(fixture.value, marshall_v2.TYPES.list)
      local buffer = unsmarshall_v2.create_buffer(encoded)<commit_msg>Fix so we actually test inet<commit_after>local marshall_v2 = require "cassandra.marshallers.marshall_v2"
local unsmarshall_v2 = require "cassandra.marshallers.unmarshall_v2"

describe("Marshallers v2", function()

  local fixtures = {
    -- custom
    ascii = {"ascii"},
    bigint = {0, 42, -42, 42000000000, -42000000000},
    blob = {"\005\042", string.rep("blob", 10000)},
    boolean = {true, false},
    --counter
    -- decimal
    double = {0, 1.0000000000000004, -1.0000000000000004},
    float = {0, 3.14151, -3.14151},
    int = {0, 4200, -42},
    text = {"some text"},
    timestamp = {1405356926},
    uuid = {"1144bada-852c-11e3-89fb-e0b9a54a6d11"},
    varchar = {"string"},
    varint = {0, 4200, -42},
    timeuuid = {"1144bada-852c-11e3-89fb-e0b9a54a6d11"},
    inet = {["127.0.0.1"] = "127.0.0.1",
            ["2001:0db8:85a3:0042:1000:8a2e:0370:7334"] = "2001:0db8:85a3:0042:1000:8a2e:0370:7334",
            ["2001:0db8:0000:0000:0000:0000:0000:0001"] = "2001:db8::1",
            ["2001:0db8:85a3:0000:0000:0000:0000:0010"] = "2001:db8:85a3::10",
            ["2001:0db8:85a3:0000:0000:0000:0000:0100"] = "2001:db8:85a3::100",
            ["0000:0000:0000:0000:0000:0000:0000:0001"] = "::1",
            ["0000:0000:0000:0000:0000:0000:0000:0000"] = "::"}
  }

  for fix_type, fix_values in pairs(fixtures) do
    it("should encode and decode a ["..fix_type.."]", function()
      for expected, fix_value in pairs(fix_values) do
        local encoded = marshall_v2.value_representation(fix_value, marshall_v2.TYPES[fix_type])
        local buffer = unsmarshall_v2.create_buffer(encoded)
        local decoded = unsmarshall_v2.read_value(buffer, { id = marshall_v2.TYPES[fix_type] })

        if fix_type == "float" then
          local delta = 0.0000001
          assert.True(math.abs(decoded - fix_value) < delta)
        elseif fix_type == "inet" then
          assert.equal(expected, decoded)
        else
          assert.equal(fix_value, decoded)
        end
      end
    end)
  end

  it("should encode and decode a [list]", function()
    local list_fixtures = {
      { value_type = "text", value = {"abc", "def"} },
      { value_type = "int", value = {0, 1, 2, 42, -42} },
    }

    for _, fixture in ipairs(list_fixtures) do
      local encoded = marshall_v2.value_representation(fixture.value, marshall_v2.TYPES.list)
      local buffer = unsmarshall_v2.create_buffer(encoded)
{'fraction_non_alphanumeric': 0.16023246160232463, 'fraction_numerical': 0.1751764217517642, 'mean_word_length': 3.1400343642611683, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 8, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2872649', 'n_tokens_mistral': 2338, 'n_tokens_neox': 1796, 'n_words': 324}