<commit_before>require 'ffi-xattr'

describe Xattr do
  let(:path)  { "test.txt" }
  let(:xattr) { Xattr.new(path) }

  before { File.open(path, "w") { |io| io << "some content" } }
  after  { File.delete(path) }

  it "has an inital empty list of xattrs" do
    xattr.list.should be_kind_of(Array)
    xattr.list.should be_empty
  end

  it "can set and get attributes" do
    xattr.set "user.foo", "bar"
    xattr.set "user.bar", "boo"

    xattr.list.sort.should == ["user.bar", "user.foo"]

    xattr.get("user.foo").should == "bar"
    xattr.get("user.bar").should == "boo"
  end

  it "can get and set with #[] and #[]=" do
    xattr['user.foo'] = 'baz'
    xattr['user.foo'].should == 'baz'
  end

  it "can remove attributes" do
    xattr.set "user.foo", "bar"
    xattr.list.should == ["user.foo"]

    xattr.remove "user.foo"
    xattr.list.should == []
  end

  it "returns nil if the attribute is not set" do
    xattr.get("hello").should be_nil
  end

  it "can iterate over all attributes" do
    xattr.set("user.hello", "world")

    called = false
    xattr.each do |key, value|
      called = true

      key.should == "user.hello"
      value.should == "world"
    end

    called.should be_true<commit_msg>should raise error trying to remove inexistent attribute (mainly test Error.check)<commit_after>require 'ffi-xattr'

describe Xattr do
  let(:path)  { "test.txt" }
  let(:xattr) { Xattr.new(path) }

  before { File.open(path, "w") { |io| io << "some content" } }
  after  { File.delete(path) }

  it "has an inital empty list of xattrs" do
    xattr.list.should be_kind_of(Array)
    xattr.list.should be_empty
  end

  it "can set and get attributes" do
    xattr.set "user.foo", "bar"
    xattr.set "user.bar", "boo"

    xattr.list.sort.should == ["user.bar", "user.foo"]

    xattr.get("user.foo").should == "bar"
    xattr.get("user.bar").should == "boo"
  end

  it "can get and set with #[] and #[]=" do
    xattr['user.foo'] = 'baz'
    xattr['user.foo'].should == 'baz'
  end

  it "can remove attributes" do
    xattr.set "user.foo", "bar"
    xattr.list.should == ["user.foo"]

    xattr.remove "user.foo"
    xattr.list.should == []
  end

  it "raises error when tries to remove inexistent attribute" do
    lambda { xattr.remove("inexisting") }.should raise_error
  end

  it "returns nil if the attribute is not set" do
    xattr.get("hello").should be_nil
  end

  it "can iterate over all attributes" do
    xattr.set("user.hello", "world")

    called = false
    xattr.each do |key, value|
      called = true

      key.should == "user.hello"
      value.should == "world"
    end

    called.should be_true
{'fraction_non_alphanumeric': 0.15196078431372548, 'fraction_numerical': 0.0, 'mean_word_length': 2.8393632416787264, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '4509508', 'n_tokens_mistral': 984, 'n_tokens_neox': 945, 'n_words': 258}