Example #1
0
func scan(css string) ([]*scanner.Token, error) {
	s := scanner.New(css)
	tks := []*scanner.Token{}
	for {
		tk := s.Next()
		switch tk.Type {
		case scanner.TokenEOF:
			return tks, nil
		case scanner.TokenError:
			return nil, errors.Input(tk.Value)
		default:
			tks = append(tks, tk)
		}
	}
}
Example #2
0
			assertError(errors.Bug("foo"), "foo", errors.ByBug)
			assertError(errors.Bugf("foo %s", "bar"), "foo bar", errors.ByBug)
		})

		It("Runtime", func() {
			assertError(errors.Runtime("foo"), "foo", errors.ByRuntime)
			assertError(errors.Runtimef("foo %s", "bar"), "foo bar", errors.ByRuntime)
		})

		It("External", func() {
			assertError(errors.External("foo"), "foo", errors.ByExternal)
			assertError(errors.Externalf("foo %s", "bar"), "foo bar", errors.ByExternal)
		})

		It("Input", func() {
			assertError(errors.Input("foo"), "foo", errors.ByInput)
			assertError(errors.Inputf("foo %s", "bar"), "foo bar", errors.ByInput)
		})

	})

	Context("GetCausedBy", func() {

		It("Default to ByBug", func() {
			Ω(errors.GetCausedBy(syserr.New("foo"))).Should(Equal(errors.ByBug))
		})

		It("Error object", func() {
			Ω(errors.GetCausedBy(errors.External("foo"))).Should(Equal(errors.ByExternal))
		})