Exemplo n.º 1
0
func (t endpointTree) checkForCycles(node *endpointNode, trace gotility.StringSlice) error {
	for _, child := range node.children {
		if trace.Contains(child.Name) {
			trace.Add(child.Name)
			trace.Reverse()
			return fmt.Errorf("Detected inheritance cycle: %s", strings.Join(trace, " -> "))
		}

		trace.Add(child.Name)
		if err := t.checkForCycles(child, trace); err != nil {
			return err
		}
		trace.DeleteByValue(child.Name)
	}

	return nil
}
Exemplo n.º 2
0
		s := gotility.StringSlice{}
		Expect(s.DeleteByValue("foo")).To(BeFalse())

		s = gotility.StringSlice{"foo", "bar", "baz"}
		Expect(s).To(ConsistOf([]string{"foo", "bar", "baz"}))
		Expect(s.DeleteByValue("bar")).To(BeTrue())
		Expect(s).To(ConsistOf([]string{"foo", "baz"}))
		Expect(s.DeleteByValue("foo")).To(BeTrue())
		Expect(s).To(ConsistOf([]string{"baz"}))
		Expect(s.DeleteByValue("baz")).To(BeTrue())
		Expect(s).To(ConsistOf([]string{}))
	})

	It("should know if it contains a string", func() {
		s := gotility.StringSlice{}
		Expect(s.Contains("foo")).To(BeFalse())

		s = gotility.StringSlice{"foo", "bar"}
		Expect(s.Contains("foo")).To(BeTrue())
		Expect(s.Contains("bar")).To(BeTrue())
		Expect(s.Contains("baz")).To(BeFalse())
	})

	It("should be able to reverse its elements", func() {
		s := gotility.StringSlice{}
		s.Reverse()
		Expect(s).To(BeEmpty())

		s = gotility.StringSlice{"foo", "bar", "baz", "1", "2"}
		s.Reverse()
		Expect(s).To(Equal(gotility.StringSlice{"2", "1", "baz", "bar", "foo"}))