Sha256: 071d19116219570b995a8ebb664fe73a422f7194445b6abe9cec22efa14d4bdf

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

require File.expand_path "../test_helper", __FILE__

context "Rugged::Tree tests" do
  setup do
    path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
    @repo = Rugged::Repository.new(path)
    @oid = "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"
    @tree = @repo.lookup(@oid)
  end

  test "can read the tree data" do
    assert_equal @oid, @tree.oid
	  assert_equal "tree", @tree.type
	  assert_equal 3, @tree.count
	  assert_equal "1385f264afb75a56a5bec74243be9b367ba4ca08", @tree[0][:oid]
	  assert_equal "fa49b077972391ad58037050f2a75f74e3671e92", @tree[1][:oid]
  end

  test "can read the tree entry data" do
    bent = @tree[0]
    tent = @tree[2]

    assert_equal "README", bent[:name]
    # assert_equal 33188, bent.attributes

    assert_equal "subdir", tent[:name]
    assert_equal "619f9935957e010c419cb9d15621916ddfcc0b96", tent[:oid]
    assert_equal "tree", @repo.lookup(tent[:oid]).type
  end

  test "can iterate over the tree" do
    enum_test = @tree.sort { |a, b| a[:oid] <=> b[:oid] }.map { |e| e[:name] }.join(':')
    assert_equal "README:subdir:new.txt", enum_test

    enum = @tree.each
    assert enum.kind_of? Enumerable
  end

  test "can walk the tree, yielding only trees" do
    @tree.walk_trees {|root, entry| assert_equal :tree, entry[:type]}
  end

  test "can walk the tree, yielding only blobs" do
    @tree.walk_blobs {|root, entry| assert_equal :blob, entry[:type]}
  end

  test "can iterate over the subtrees a tree" do
    @tree.each_tree {|tree| assert_equal :tree, tree[:type]}
  end

  test "can iterate over the subtrees a tree" do
    @tree.each_blob {|tree| assert_equal :blob, tree[:type]}
  end

  xtest "can write the tree data" do
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rugged-0.16.0 test/tree_test.rb
rugged-0.16.0b1 test/tree_test.rb