-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c5ae00
commit 4870d95
Showing
2 changed files
with
87 additions
and
0 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,3 @@ | ||
This directory can be used for adding a test case to a github issue, eg: | ||
issue `#7976` would have test case named `t7976.nim` | ||
It makes it easier to find which issue corresponds to a test caes, or vice versa, and removes the guesswork of trying to figure out an appropriate directory/filename by being more systematic. |
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,84 @@ | ||
when defined(case1): | ||
import strformat, typetraits | ||
type Person = tuple[name: string, age: int] | ||
let | ||
person1: Person = ("Peter", 30) | ||
person2 = (name: "Peter", age: 30) | ||
echo fmt"Tuple person1 of type {$person1.type} = {person1}" | ||
echo fmt"Tuple person2 of type {$person2.type} = {person2}" | ||
|
||
when defined(case2): | ||
import strformat, typetraits | ||
type Person = tuple[name: string, age: int] | ||
let | ||
person1 = (name: "Peter", age: 30) | ||
person2: Person = ("Peter", 30) | ||
echo fmt"Tuple person1 of type {$person1.type} = {person1}" | ||
echo fmt"Tuple person2 of type {$person2.type} = {person2}" | ||
|
||
when defined(case3): | ||
import strformat, typetraits | ||
type Person = tuple[name: string, age: int] | ||
let | ||
person1: Person = ("Peter", 30) | ||
person2 = (name: "Peter", age: 30) | ||
echo fmt"Tuple person1 of type {$person1.type} = {person1}" | ||
echo fmt"Tuple person2 of type {$person2.type} = {person2}" | ||
|
||
when defined(case4): | ||
import strformat, typetraits | ||
type Person = tuple[name: string, age: int] | ||
let | ||
person1: Person = ("Peter", 30) | ||
person2 = (name: "Peter", age: 30) | ||
echo fmt"Tuple person1 of type {$person2.type} = {person2}" # simply moved up | ||
echo fmt"Tuple person2 of type {$person1.type} = {person1}" | ||
|
||
when defined(case5): | ||
import strformat, typetraits | ||
type Person = tuple[name: string, age: int] | ||
let | ||
person1: Person = ("Peter", 30) | ||
person2 = (name: "Peter", age: 30) | ||
echo fmt"Tuple person1 of type {name(person1.type)} = {person1}" | ||
echo fmt"Tuple person2 of type {name(person2.type)} = {person2}" | ||
|
||
when not defined(case_any_testcase): # main driver | ||
# import os, strutils, osproc, nre, strformat | ||
import os, strutils, osproc, strformat | ||
proc assertEquals[T](lhs: T, rhs: T) = | ||
if lhs!=rhs: | ||
echo "lhs:{\n", lhs, "}\nrhs:{", rhs, "}" | ||
echo "lhs:\n", lhs, "\nrhs:", rhs | ||
doAssert false | ||
|
||
var output = "" | ||
proc main() = | ||
const nim = getCurrentCompilerExe() | ||
const self = currentSourcePath | ||
let cases = "case1 case2 case3 case4 case5".split | ||
for opt in cases: | ||
let cmd = fmt"{nim} c -r --colors:off --hints:off -d:case_any_testcase -d:{opt} {self}" | ||
output.add "test case: " & opt & "\n" | ||
let ret = execCmdEx(cmd, {poStdErrToStdOut, poEvalCommand}) | ||
doAssert ret.exitCode == 0 | ||
output.add ret.output | ||
let expected = """ | ||
test case: case1 | ||
Tuple person1 of type Person = (name: "Peter", age: 30) | ||
Tuple person2 of type tuple[name: string, age: int] = (name: "Peter", age: 30) | ||
test case: case2 | ||
Tuple person1 of type tuple[name: string, age: int] = (name: "Peter", age: 30) | ||
Tuple person2 of type Person = (name: "Peter", age: 30) | ||
test case: case3 | ||
Tuple person1 of type Person = (name: "Peter", age: 30) | ||
Tuple person2 of type tuple[name: string, age: int] = (name: "Peter", age: 30) | ||
test case: case4 | ||
Tuple person1 of type tuple[name: string, age: int] = (name: "Peter", age: 30) | ||
Tuple person2 of type Person = (name: "Peter", age: 30) | ||
test case: case5 | ||
Tuple person1 of type Person = (name: "Peter", age: 30) | ||
Tuple person2 of type tuple[name: string, age: int] = (name: "Peter", age: 30) | ||
""" | ||
assertEquals(output, expected) | ||
main() |