Skip to content

Commit

Permalink
add unit tests for runtime/core - scope (MontFerret#94)
Browse files Browse the repository at this point in the history
* add unit tests for runtime/core - scope

* add unit tests for runtime/core - scope

* add unit tests for runtime/core - scope
  • Loading branch information
esell authored and ziflex committed Oct 11, 2018
1 parent 54c9857 commit ad21fa6
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions pkg/runtime/core/scope_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package core_test

import (
"testing"

"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
. "github.com/smartystreets/goconvey/convey"
)

func TestScope(t *testing.T) {
Convey("Should match", t, func() {
rs, cf := core.NewRootScope()

So(cf, ShouldNotBeNil)

s := core.NewScope(rs)

So(s.HasVariable("a"), ShouldBeFalse)

s.SetVariable("a", values.NewString("test"))

So(s.HasVariable("a"), ShouldBeTrue)

v, err := s.GetVariable("a")

So(err, ShouldBeNil)
So(v, ShouldEqual, "test")

c := s.Fork()

So(c.HasVariable("a"), ShouldBeTrue)

cv, err := c.GetVariable("a")

So(err, ShouldBeNil)
So(cv, ShouldEqual, "test")
})
}

func TestScopeTraversing(t *testing.T) {
Convey("Should match", t, func() {
rs, cf := core.NewRootScope()
So(cf, ShouldNotBeNil)

s := core.NewScope(rs)

rs.SetVariable("a", values.NewString("test"))
v, err := s.GetVariable("a")

// root traversal should work
So(err, ShouldBeNil)
So(v, ShouldEqual, "test")

s.SetVariable("b", values.NewString("test2"))
s2 := core.NewScope(rs)
_, err = s2.GetVariable("b")

// child traversal should fail
So(err, ShouldNotBeNil)

v2, err := s2.GetVariable("a")

// root traversal should work
So(err, ShouldBeNil)
So(v2, ShouldEqual, "test")

})
}

0 comments on commit ad21fa6

Please sign in to comment.