Skip to content

thorntonmc/trail

Repository files navigation

trail

Inspired by rust's std::path

Components

Break a path into components:

import (
    "testing"

    "github.com/stretchr/testify/assert"
)

func TestComponentRead(t *testing.T) {
    var c *Components
    // with root
    c, _ = testTrail.Components()
    assert.Equal(t, string(rootDir), string(c.Next()))
    assert.Equal(t, "Users", string(c.Next()))
    assert.Equal(t, "name", string(c.Next()))
    assert.Equal(t, "personal", string(c.Next()))
    assert.Equal(t, "trail", string(c.Next()))
    assert.Equal(t, "", string(c.Next()))
}

Ancestry

Break a path into its ancestors

func TestAncestor(t *testing.T) {
    trail := testTrail
    a := trail.Ancestors()

    assert.Equal(t, "/Users/name/personal/trail", a.Next().Inner)
    assert.Equal(t, "/Users/name/personal", a.Next().Inner)
    assert.Equal(t, "/Users/name", a.Next().Inner)
    assert.Equal(t, "/Users", a.Next().Inner)
    assert.Nil(t, a.Next())
    assert.Nil(t, a.Next())
}

About

path extensions for go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages