Commit e0c200c9 by Paul John King

add preliminary test data for keep-as filter

parent 1d292636
......@@ -306,6 +306,25 @@ new
line
`},
},
}
)
type (
FilterKeepAsDatum struct {
Description string
InputKeep string
InputAs string
ExpectedSuccess bool
}
FilterKeepAsData []FilterKeepAsDatum
)
var (
filterKeepAsData FilterKeepAsData = FilterKeepAsData{
{
`^alpha/»ALPHA`,
`^alpha/`, `ALPHA`,
true,
},
}
)
......@@ -36,9 +36,125 @@
package mangle_tar
import (
"fmt"
"testing"
)
func TestNewKeepAsFilter(t *testing.T) {
func Test_Filter_NewKeepAsFilter(t *testing.T) {
var (
err error
filter *Filter
report string
passed bool
success bool
inputKeep string
inputAs string
expectedStdout string
expectedStderr string
expectedSuccess bool
)
err = nil
filter = new(Filter)
report = ``
passed = true
success = true
inputKeep = `^alpha/`
inputAs = `ALPHA`
expectedStdout = ``
expectedStderr = fmt.Sprintf(
`initialising keep '%s' as '%s'`,
inputKeep, inputAs,
)
expectedSuccess = true
filter, _report, _passed, _success, err := createKeepAsFilter(
inputKeep,
inputAs,
expectedStdout,
expectedStderr,
expectedSuccess,
)
if err != nil {
t.Fatalf(`error: %s`, err.Error())
}
report = report + _report
passed = passed && _passed
success = success && _success
if !passed {
t.Fatal(report)
}
t.Log(report)
if success {
t.Logf("apply %s", filter.Apply)
}
return
}
func createKeepAsFilter(
inputKeep string,
inputAs string,
expectedStdout string,
expectedStderr string,
expectedSuccess bool,
) (
filter *Filter,
report string,
passed bool,
success bool,
err error,
) {
var (
receivedStdout string
receivedStderr string
receivedError error
receivedSuccess bool
)
receivedStdout, receivedStderr, err = CaptureStdoutStderr(
func() {
filter, receivedError = NewKeepAsFilter(inputKeep, inputAs)
},
)
if err != nil {
return
}
receivedSuccess = receivedError == nil
report = fmt.Sprintf(`
┍━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
│ execute │ NewKeepAsFilter('%s', '%s')
┝━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
│ stdout │
│ expected │ '%s'
│ received │ '%s'
│ match │ %t
├────────────────┼────────────────────────────────────────────────
│ stderr │
│ expected │ '%s'
│ received │ '%s'
│ match │ %t
├────────────────┼────────────────────────────────────────────────
│ success │
│ expected │ %t
│ received │ %t
│ match │ %t
┕━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`,
inputKeep, inputAs,
expectedStdout, receivedStdout, expectedStdout == receivedStdout,
expectedStderr, receivedStderr, expectedStderr == receivedStderr,
expectedSuccess, receivedSuccess, expectedSuccess == receivedSuccess,
)
passed = expectedStdout == receivedStdout &&
expectedStderr == receivedStderr &&
expectedSuccess == receivedSuccess
success = expectedSuccess && receivedSuccess
return
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment