-
-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #672 from leenipper/bracket-push-create-test-case-…
…generator bracket-push: create test case generator
- Loading branch information
Showing
4 changed files
with
146 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
"text/template" | ||
|
||
"../../../gen" | ||
) | ||
|
||
func main() { | ||
t, err := template.New("").Parse(tmpl) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
var j js | ||
if err := gen.Gen("bracket-push", &j, t); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
// The JSON structure we expect to be able to unmarshal into | ||
type js struct { | ||
Cases []struct { | ||
Description string | ||
Input string | ||
Expected bool | ||
} | ||
} | ||
|
||
// template applied to above data structure generates the Go test cases | ||
var tmpl = `package brackets | ||
{{.Header}} | ||
type bracketTest struct { | ||
input string | ||
expected bool | ||
} | ||
var testCases = []bracketTest { | ||
{{range .J.Cases}}{ | ||
// {{.Description}} | ||
{{printf "%q" .Input}}, | ||
{{.Expected}}, | ||
}, | ||
{{end}}} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package brackets | ||
|
||
// Source: exercism/x-common | ||
// Commit: 855c591 bracket-push: add test case (#747) | ||
// x-common version: 1.1.0 | ||
|
||
type bracketTest struct { | ||
input string | ||
expected bool | ||
} | ||
|
||
var testCases = []bracketTest{ | ||
{ | ||
// paired square brackets | ||
"[]", | ||
true, | ||
}, | ||
{ | ||
// empty string | ||
"", | ||
true, | ||
}, | ||
{ | ||
// unpaired brackets | ||
"[[", | ||
false, | ||
}, | ||
{ | ||
// wrong ordered brackets | ||
"}{", | ||
false, | ||
}, | ||
{ | ||
// wrong closing bracket | ||
"{]", | ||
false, | ||
}, | ||
{ | ||
// paired with whitespace | ||
"{ }", | ||
true, | ||
}, | ||
{ | ||
// simple nested brackets | ||
"{[]}", | ||
true, | ||
}, | ||
{ | ||
// several paired brackets | ||
"{}[]", | ||
true, | ||
}, | ||
{ | ||
// paired and nested brackets | ||
"([{}({}[])])", | ||
true, | ||
}, | ||
{ | ||
// unopened closing brackets | ||
"{[)][]}", | ||
false, | ||
}, | ||
{ | ||
// unpaired and nested brackets | ||
"([{])", | ||
false, | ||
}, | ||
{ | ||
// paired and wrong nested brackets | ||
"[({]})", | ||
false, | ||
}, | ||
{ | ||
// math expression | ||
"(((185 + 223.85) * 15) - 543)/2", | ||
true, | ||
}, | ||
{ | ||
// complex latex expression | ||
"\\left(\\begin{array}{cc} \\frac{1}{3} & x\\\\ \\mathrm{e}^{x} &... x^2 \\end{array}\\right)", | ||
true, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters