Nim/tests/compiler/tunittest_light.nim
Jacek Sieka 7d6cbf290a
Error -> Defect for defects (#13908)
* Error -> Defect for defects

The distinction between Error and Defect is subjective,
context-dependent and somewhat arbitrary, so when looking at an
exception, it's hard to guess what it is - this happens often when
looking at a `raises` list _without_ opening the corresponding
definition and digging through layers of inheritance.

With the help of a little consistency in naming, it's at least possible
to start disentangling the two error types and the standard lib can set
a good example here.
2020-04-28 19:56:01 +02:00

55 lines
1.2 KiB
Nim

import compiler/unittest_light
proc testAssertEquals() =
assertEquals("foo", "foo")
doAssertRaises(AssertionDefect):
assertEquals("foo", "foo ")
proc testMismatch() =
assertEquals(1+1, 2*1)
let a = """
some test with space at the end of lines
can be hard to spot differences when diffing in a terminal
without this helper function
"""
let b = """
some test with space at the end of lines
can be hard to spot differences when diffing in a terminal
without this helper function
"""
let output = mismatch(a, b)
let expected = """
lhs:{ some test with space at the end of lines \n
\n
can be hard to spot differences when diffing in a terminal \n
without this helper function\n
\n
}
rhs:{ some test with space at the end of lines \n
\n
can be hard to spot differences when diffing in a terminal \n
without this helper function\n
\n
}
lhs.len: 144 rhs.len: 143
first mismatch index: 110
lhs[i]: {" "}
rhs[i]: {"\n"}
lhs[0..<i]:{ some test with space at the end of lines \n
\n
can be hard to spot differences when diffing in a terminal }"""
if output != expected:
echo output
doAssert false
testMismatch()
testAssertEquals()