Esempio 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
}
Esempio n. 2
0
		Expect(s.DeleteByIndex(-1)).To(BeFalse())
		Expect(s.DeleteByIndex(42)).To(BeFalse())

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

	It("should search and delete elements", func() {
		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())