Files
Johan Fylling 7bb6dbe36b Preparing for v1 API
Moving (most) source to v1 root package to prepare for v0/v1 API separation.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-12-12 15:09:03 +01:00

42 lines
999 B
Go

// Copyright 2016 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
package ast
import "testing"
func TestErrorsString(t *testing.T) {
err := Errors{
NewError(ParseErr, nil, "blah"),
NewError(ParseErr, NewLocation(nil, "", 100, 2), "bleh"),
NewError(ParseErr, NewLocation(nil, "foo.rego", 100, 2), "blarg"),
}
expected := `3 errors occurred:
rego_parse_error: blah
100:2: rego_parse_error: bleh
foo.rego:100: rego_parse_error: blarg`
result := err.Error()
if result != expected {
t.Errorf("Expected %v but got: %v", expected, result)
}
err = Errors{NewError(ParseErr, nil, "blah")}
expected = `1 error occurred: rego_parse_error: blah`
result = err.Error()
if result != expected {
t.Errorf("Expected %v but got: %v", expected, result)
}
expected = `no error(s)`
result = Errors{}.Error()
if result != expected {
t.Errorf("Expected %v but got: %v", expected, result)
}
}