-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: validate go templates with go #30
base: master
Are you sure you want to change the base?
test: validate go templates with go #30
Conversation
qvalentin
commented
Jan 14, 2025
•
edited
Loading
edited
- Some testnames are still ugly
- corpus_test.go:29: template: template:2: missing value for block clause -> it is working, I found a bug ;)
- ci
8db8730
to
5727350
Compare
this ensures all testcases obey the gotemplate grammar and we are compatible with the official implementation
39e190b
to
e54ee93
Compare
test/corpus_test.go
Outdated
partsWithEmptyParts := TESTCASE_SEPERATOR.Split(content, -1) | ||
parts := []string{} | ||
|
||
// remove empty parts | ||
for i := 0; i < len(partsWithEmptyParts); i++ { | ||
if partsWithEmptyParts[i] != "" { | ||
parts = append(parts, partsWithEmptyParts[i]) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
partsWithEmptyParts := TESTCASE_SEPERATOR.Split(content, -1) | |
parts := []string{} | |
// remove empty parts | |
for i := 0; i < len(partsWithEmptyParts); i++ { | |
if partsWithEmptyParts[i] != "" { | |
parts = append(parts, partsWithEmptyParts[i]) | |
} | |
} | |
parts := TESTCASE_SEPERATOR.Split(content, -1) | |
// remove empty parts | |
index := 0 | |
for _, str := range parts { | |
if str != "" { | |
parts[index] = str | |
index++ | |
} | |
} | |
parts = parts[:index] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk, sometimes the simplest loop is the best loop.
0c14f5f
to
9ec3efb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice addition to the project!
|
||
var ( | ||
TESTCASE_SEPERATOR = regexp.MustCompile("(?m)^(=+)$") | ||
INPUT_OUTPUT_SEPERATOR = regexp.MustCompile("\n(---)\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
INPUT_OUTPUT_SEPERATOR = regexp.MustCompile("\n(---)\n") | |
INPUT_OUTPUT_SEPERATOR = regexp.MustCompile("\n(-+)\n") |
So a test doesn't fail to parse if it includes more than 3 dashes.
fmt.Printf("Error parsing %s: Testcase has invalid format %s\n", filename, testName) | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should just set testParts to something like this:
fmt.Printf("Error parsing %s: Testcase has invalid format %s\n", filename, testName) | |
continue | |
testParts = []string{"", ""} |
and check in the testTemplate
against input
so we get a test failure from a bad formatted test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change, I can see a test failure easily:
--- FAIL: TestCorpus/corpus/actions.txt:_invalid_comments (0.00s)
(although this stops failing once the regex change suggested above is applied).
TESTCASE_SEPERATOR = regexp.MustCompile("(?m)^(=+)$") | ||
INPUT_OUTPUT_SEPERATOR = regexp.MustCompile("\n(---)\n") | ||
TRIM_TESTCASE_SEPERATOR = regexp.MustCompile("^(=+)\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TESTCASE_SEPERATOR = regexp.MustCompile("(?m)^(=+)$") | |
INPUT_OUTPUT_SEPERATOR = regexp.MustCompile("\n(---)\n") | |
TRIM_TESTCASE_SEPERATOR = regexp.MustCompile("^(=+)\n") | |
TESTCASE_SEPARATOR = regexp.MustCompile("(?m)^(=+)$") | |
INPUT_OUTPUT_SEPARATOR = regexp.MustCompile("\n(---)\n") | |
TRIM_TESTCASE_SEPARATOR = regexp.MustCompile("^(=+)\n") |
typo