Errors no longer directly depends on testcommon

This commit is contained in:
Sasha Koshka 2024-04-20 23:07:16 -04:00
parent 334a45e06f
commit 293662e474
3 changed files with 56 additions and 53 deletions

View File

@ -1,55 +1,6 @@
package errors
import "testing"
import "strings"
func TestError (test *testing.T) {
testError (test,
`example.fspl:11:7: some error
11 | lorem ipsum dolor
^^^^^`,
Errorf (
Position {
File: "example.fspl",
Line: "lorem ipsum dolor",
Row: 10,
Start: 6,
End: 11,
},
"some error"))
}
func TestErrorTab (test *testing.T) {
testError (test,
`example.fspl:11:8: some error
11 | lorem ipsum dolor
^^^^^`,
Errorf (
Position {
File: "example.fspl",
Line: "\tlorem\tipsum\tdolor",
Row: 10,
Start: 7,
End: 12,
},
"some error"))
}
func TestErrorTabInBetween (test *testing.T) {
testError (test,
`example.fspl:11:8: some error
11 | lorem ipsum dolor
^^^^^^^^^`,
Errorf (
Position {
File: "example.fspl",
Line: "\tlorem\tipsum\tdolor",
Row: 10,
Start: 7,
End: 14,
},
"some error"))
}
func TestGetXInTabbedString (test *testing.T) {
getXCase := func (line string, column, correct int) {
@ -69,7 +20,6 @@ func TestGetXInTabbedString (test *testing.T) {
getXCase("x\tyyyy\tzy", 7, 16)
}
func TestFormatTabs (test *testing.T) {
fmtCase := func (line string, correct string) {
got := formatTabs(line)

View File

@ -1,6 +1,7 @@
package errors
package errorstest
import "testing"
import "git.tebibyte.media/fspl/fspl/errors"
import "git.tebibyte.media/fspl/fspl/testcommon"
func testString (test *testing.T, correct string, got string) {
@ -11,6 +12,6 @@ func testString (test *testing.T, correct string, got string) {
testcommon.Compare(test, correct, got)
}
func testError (test *testing.T, correct string, err Error) {
testString(test, correct, Format(err))
func testError (test *testing.T, correct string, err errors.Error) {
testString(test, correct, errors.Format(err))
}

View File

@ -0,0 +1,52 @@
package errorstest
import "testing"
import "git.tebibyte.media/fspl/fspl/errors"
func TestError (test *testing.T) {
testError (test,
`example.fspl:11:7: some error
11 | lorem ipsum dolor
^^^^^`,
errors.Errorf (
errors.Position {
File: "example.fspl",
Line: "lorem ipsum dolor",
Row: 10,
Start: 6,
End: 11,
},
"some error"))
}
func TestErrorTab (test *testing.T) {
testError (test,
`example.fspl:11:8: some error
11 | lorem ipsum dolor
^^^^^`,
errors.Errorf (
errors.Position {
File: "example.fspl",
Line: "\tlorem\tipsum\tdolor",
Row: 10,
Start: 7,
End: 12,
},
"some error"))
}
func TestErrorTabInBetween (test *testing.T) {
testError (test,
`example.fspl:11:8: some error
11 | lorem ipsum dolor
^^^^^^^^^`,
errors.Errorf (
errors.Position {
File: "example.fspl",
Line: "\tlorem\tipsum\tdolor",
Row: 10,
Start: 7,
End: 14,
},
"some error"))
}