Merge branch 'master' of github.com:Araq/Nimrod
This commit is contained in:
commit
d1d20e5760
3 changed files with 25 additions and 5 deletions
|
|
@ -65,8 +65,13 @@ proc writeCommandLineUsage() =
|
||||||
MsgWriteln(getCommandLineDesc())
|
MsgWriteln(getCommandLineDesc())
|
||||||
helpWritten = true
|
helpWritten = true
|
||||||
|
|
||||||
|
proc addPrefix(switch: string): string =
|
||||||
|
if len(switch) == 1: result = "-" & switch
|
||||||
|
else: result = "--" & switch
|
||||||
|
|
||||||
proc InvalidCmdLineOption(pass: TCmdLinePass, switch: string, info: TLineInfo) =
|
proc InvalidCmdLineOption(pass: TCmdLinePass, switch: string, info: TLineInfo) =
|
||||||
LocalError(info, errInvalidCmdLineOption, switch)
|
if switch == " ": LocalError(info, errInvalidCmdLineOption, "-")
|
||||||
|
else: LocalError(info, errInvalidCmdLineOption, addPrefix(switch))
|
||||||
|
|
||||||
proc splitSwitch(switch: string, cmd, arg: var string, pass: TCmdLinePass,
|
proc splitSwitch(switch: string, cmd, arg: var string, pass: TCmdLinePass,
|
||||||
info: TLineInfo) =
|
info: TLineInfo) =
|
||||||
|
|
@ -98,10 +103,10 @@ proc ProcessOnOffSwitchG(op: TGlobalOptions, arg: string, pass: TCmdlinePass,
|
||||||
else: LocalError(info, errOnOrOffExpectedButXFound, arg)
|
else: LocalError(info, errOnOrOffExpectedButXFound, arg)
|
||||||
|
|
||||||
proc ExpectArg(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
|
proc ExpectArg(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
|
||||||
if arg == "": LocalError(info, errCmdLineArgExpected, switch)
|
if arg == "": LocalError(info, errCmdLineArgExpected, addPrefix(switch))
|
||||||
|
|
||||||
proc ExpectNoArg(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
|
proc ExpectNoArg(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
|
||||||
if arg != "": LocalError(info, errCmdLineNoArgExpected, switch)
|
if arg != "": LocalError(info, errCmdLineNoArgExpected, addPrefix(switch))
|
||||||
|
|
||||||
proc ProcessSpecificNote(arg: string, state: TSpecialWord, pass: TCmdlinePass,
|
proc ProcessSpecificNote(arg: string, state: TSpecialWord, pass: TCmdlinePass,
|
||||||
info: TLineInfo) =
|
info: TLineInfo) =
|
||||||
|
|
|
||||||
|
|
@ -1532,7 +1532,7 @@ iterator fieldPairs*[S: tuple|object, T: tuple|object](x: S, y: T): tuple[
|
||||||
## The current implementation also has a bug that affects symbol binding
|
## The current implementation also has a bug that affects symbol binding
|
||||||
## in the loop body.
|
## in the loop body.
|
||||||
|
|
||||||
proc `==`*[T: tuple](x, y: T): bool =
|
proc `==`*[T: tuple|object](x, y: T): bool =
|
||||||
## generic ``==`` operator for tuples that is lifted from the components
|
## generic ``==`` operator for tuples that is lifted from the components
|
||||||
## of `x` and `y`.
|
## of `x` and `y`.
|
||||||
for a, b in fields(x, y):
|
for a, b in fields(x, y):
|
||||||
|
|
@ -1557,7 +1557,7 @@ proc `<`*[T: tuple](x, y: T): bool =
|
||||||
if c > 0: return false
|
if c > 0: return false
|
||||||
return false
|
return false
|
||||||
|
|
||||||
proc `$`*[T: tuple](x: T): string =
|
proc `$`*[T: tuple|object](x: T): string =
|
||||||
## generic ``$`` operator for tuples that is lifted from the components
|
## generic ``$`` operator for tuples that is lifted from the components
|
||||||
## of `x`. Example:
|
## of `x`. Example:
|
||||||
##
|
##
|
||||||
|
|
|
||||||
15
tests/run/tobject.nim
Normal file
15
tests/run/tobject.nim
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
type Obj = object
|
||||||
|
foo: int
|
||||||
|
|
||||||
|
proc makeObj(x: int): Obj =
|
||||||
|
result.foo = x
|
||||||
|
|
||||||
|
suite "object basic methods":
|
||||||
|
test "it should convert an object to a string":
|
||||||
|
var obj = makeObj(1)
|
||||||
|
# Should be "obj: (foo: 1)" or similar.
|
||||||
|
check($obj == "(foo: 1)")
|
||||||
|
test "it should test equality based on fields":
|
||||||
|
check(makeObj(1) == makeObj(1))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue