tests themselves contain the expected result

This commit is contained in:
Araq
2011-02-20 20:12:22 +01:00
parent cbee9c4e1a
commit 2cdfe35e73
144 changed files with 957 additions and 200 deletions

View File

@@ -74,15 +74,18 @@ const
proc rawGetTok(c: var TCfgParser, tok: var TToken)
proc open*(c: var TCfgParser, input: PStream, filename: string) {.
proc open*(c: var TCfgParser, input: PStream, filename: string,
lineOffset = 0) {.
rtl, extern: "npc$1".} =
## initializes the parser with an input stream. `Filename` is only used
## for nice error messages.
## for nice error messages. `lineOffset` can be used to influence the line
## number information in the generated error messages.
lexbase.open(c, input)
c.filename = filename
c.state = startState
c.tok.kind = tkInvalid
c.tok.literal = ""
inc(c.linenumber, lineOffset)
rawGetTok(c, c.tok)
proc close*(c: var TCfgParser) {.rtl, extern: "npc$1".} =
@@ -291,6 +294,23 @@ proc errorStr*(c: TCfgParser, msg: string): string {.rtl, extern: "npc$1".} =
## column information.
result = `%`("$1($2, $3) Error: $4",
[c.filename, $getLine(c), $getColumn(c), msg])
proc warningStr*(c: TCfgParser, msg: string): string {.rtl, extern: "npc$1".} =
## returns a properly formated warning message containing current line and
## column information.
result = `%`("$1($2, $3) Warning: $4",
[c.filename, $getLine(c), $getColumn(c), msg])
proc ignoreMsg*(c: TCfgParser, e: TCfgEvent): string {.rtl, extern: "npc$1".} =
## returns a properly formated warning message containing that
## an entry is ignored.
case e.kind
of cfgSectionStart: result = c.warningStr("section ignored: " & e.section)
of cfgKeyValuePair: result = c.warningStr("key ignored: " & e.key)
of cfgOption:
result = c.warningStr("command ignored: " & e.key & ": " & e.value)
of cfgError: result = e.msg
of cfgEof: result = ""
proc getKeyValPair(c: var TCfgParser, kind: TCfgEventKind): TCfgEvent =
if c.tok.kind == tkSymbol:

View File

@@ -271,7 +271,6 @@ when false:
j = j * 10 + ord(frmt[i]) - ord('0')
inc(i)
if frmt[i] notin {'0'..'9'}: break
num = j
add(s, compiledArg(j))
of '{':
inc(i)
@@ -281,7 +280,6 @@ when false:
inc(i)
if frmt[i] == '}': inc(i)
else: raise newException(EInvalidValue, "invalid format string")
num = j
add(s, compiledArg(j))
else: raise newException(EInvalidValue, "invalid format string")
var start = i
@@ -316,7 +314,6 @@ proc `%`*(frmt: string, args: openarray[PRope]): PRope {.
j = j * 10 + ord(frmt[i]) - ord('0')
inc(i)
if frmt[i] notin {'0'..'9'}: break
num = j
add(result, args[j-1])
of '{':
inc(i)
@@ -326,7 +323,6 @@ proc `%`*(frmt: string, args: openarray[PRope]): PRope {.
inc(i)
if frmt[i] == '}': inc(i)
else: raise newException(EInvalidValue, "invalid format string")
num = j
add(result, args[j-1])
else: raise newException(EInvalidValue, "invalid format string")
var start = i

View File

@@ -139,7 +139,7 @@ proc findNormalized(x: string, inArray: openarray[string]): int =
var i = 0
while i < high(inArray):
if cmpIgnoreStyle(x, inArray[i]) == 0: return i
inc(i, 2) # incrementing by 1 would probably result in a
inc(i, 2) # incrementing by 1 would probably lead to a
# security hole...
return -1
@@ -166,7 +166,6 @@ proc addf*(s: var string, formatstr: string, a: openarray[string]) {.
while formatstr[i] in Digits:
j = j * 10 + ord(formatstr[i]) - ord('0')
inc(i)
num = j
add s, a[j - 1]
of '{':
var j = i+1
@@ -1003,5 +1002,6 @@ when isMainModule:
it goes""", 10, false)
assert formatBiggestFloat(0.00000000001, ffDecimal, 11) == "0.00000000001"
assert formatBiggestFloat(0.00000000001, ffScientific, 1) == "1.0e-11"
assert "$# $3 $# $#" % ["a", "b", "c"] == "a c b c"