mercurial/HGCommandParserTests.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 27 Nov 2012 21:42:13 +0000
changeset 106 99be3b5a40da
parent 105 25e8ff9d2a31
child 115 b1ed2d29054b
permissions -rw-r--r--
Added support for heads (both repository and per-branch)

"{ Package: 'stx:libscm/mercurial' }"

TestCase subclass:#HGCommandParserTests
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'SCM-Mercurial-Tests'
!


!HGCommandParserTests methodsFor:'tests - commands'!

test_cmd_branches_01

    | branches |

    branches := (HGCommandParser on: 'default                        5:f22945219f9be25a1fe436d81afece07b89330be
branch1                        4:5bd21fb5eea8a7cb4adf45bccfea76cda11df84a (inactive)
branch2                        3:32d32dee719fb422a69cfa6f7f8c1d8e299de2df (closed)
') parseCommandBranches.

    self assert: branches size == 3.

    self assert: branches first name = 'default'.
    self assert: branches first isActive.
    self assert: branches first isClosed not.

    self assert: branches second name = 'branch1'.
    self assert: branches second isActive not.
    self assert: branches second isClosed not.

    self assert: branches third name = 'branch2'.
    self assert: branches third isActive.
    self assert: branches third isClosed.

    "Created: / 27-11-2012 / 19:00:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_heads_01

    | heads |

    heads := (HGCommandParser on: '6:4e0568ffbf1a53f2d8980ba9844d2af6f0bac455
5:f22945219f9be25a1fe436d81afece07b89330be
4:5bd21fb5eea8a7cb4adf45bccfea76cda11df84a
') parseCommandHeads.

    self assert: heads size == 3.

    self assert: heads first  asString = '6:4e0568ffbf1a53f2d8980ba9844d2af6f0bac455'.
    self assert: heads second asString = '5:f22945219f9be25a1fe436d81afece07b89330be'.
    self assert: heads third  asString = '4:5bd21fb5eea8a7cb4adf45bccfea76cda11df84a'.

    "Created: / 27-11-2012 / 21:22:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_status_01

    | statuses |

    statuses := (HGCommandParser on: 'M HGRevisionInfo.st
? something.txt
') parseCommandStatus.

    self assert: statuses size == 2.
    self assert: statuses first first isModified.
    self assert: statuses first second = 'HGRevisionInfo.st'.

    self assert: statuses second first isUntracked.
    self assert: statuses second second = 'something.txt'.

    "Created: / 21-11-2012 / 00:53:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_status_02

    | statuses |

    statuses := (HGCommandParser on: 'A HGRevisionInfo.st
  HGVersionInfo.st
') parseCommandStatus.

    self assert: statuses size == 1.
    self assert: statuses first first isCopied.
    self assert: statuses first first source = 'HGVersionInfo.st'.
    self assert: statuses first second = 'HGRevisionInfo.st'.

    "Created: / 21-11-2012 / 01:08:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_cmd_status_03

    | statuses |

    statuses := (HGCommandParser on: 'A HGRevisionInfo.st
  HGVersionInfo.st
? something.txt
') parseCommandStatus.

    self assert: statuses size == 2.
    self assert: statuses first first isCopied.
    self assert: statuses first first source = 'HGVersionInfo.st'.
    self assert: statuses first second = 'HGRevisionInfo.st'.

    self assert: statuses second first isUntracked.
    self assert: statuses second second = 'something.txt'.

    "Created: / 21-11-2012 / 01:09:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGCommandParserTests methodsFor:'tests - misc'!

test_misc_01

    | id |

    id := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7') parseNodeId.
    self assert: ( id revno == 4 ).
    self assert: ( id hexPrintString = '6F88E1F44D9EB86E0B56CA15E30E5D786ACD83C7' ).

    id := (HGCommandParser on: '4:6f88e1f44d9e') parseNodeId.
    self assert: ( id revno == 4 ).
    self assert: ( id hexPrintString = '6F88E1F44D9E' ).

    id := (HGCommandParser on: '-1:0000000000000000000000000000000000000000') parseNodeId.
    self assert: id == HGChangesetId null.

    id := (HGCommandParser on: '-1:000000000000') parseNodeId.
    self assert: id == HGChangesetId null.


    "/ Too short id
    self 
        should:[id := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83') parseNodeId.]
        raise: Error.
    self 
        should:[id := (HGCommandParser on: '4:6f88e1f44d9') parseNodeId.]
        raise: Error.


    "/ Invalid char
    self 
        should:[id := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd8X') parseNodeId.]
        raise: Error.

        self 
        should:[id := (HGCommandParser on: '4:6f88e1f44d9X') parseNodeId.]
        raise: Error.

    "Created: / 13-11-2012 / 16:34:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_misc_03

    | rev |

    rev := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7
default
3:912a64597e4f133ffbc1fdabdda99167a2d69ce2 -1:0000000000000000000000000000000000000000 
Jan Vrany <jan.vrany@fit.cvut.cz>
2012-10-17 13:20 +0200
Commit 4
**EOE**
') parseLogEntry.

    self assert: rev id revno = 4.
    self assert: rev author = 'Jan Vrany <jan.vrany@fit.cvut.cz>'.
    self assert: rev timestamp hour = 13.
    self assert: rev message = 'Commit 4'

    "Created: / 13-11-2012 / 17:16:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 21-11-2012 / 18:07:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_misc_03b

    | rev |

    rev := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7
default
3:912a64597e4f133ffbc1fdabdda99167a2d69ce2 -1:0000000000000000000000000000000000000000 
Jan Vrany <jan.vrany@fit.cvut.cz>
2012-10-17 13:20 +0200
Commit 4
Two lones
**EOE**
') parseLogEntry.

    self assert: rev message = 'Commit 4
Two lones'

    "Created: / 21-11-2012 / 18:09:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_misc_04

    | revs |

    revs := (HGCommandParser on: '4:6f88e1f44d9eb86e0b56ca15e30e5d786acd83c7
default
3:912a64597e4f133ffbc1fdabdda99167a2d69ce2 -1:0000000000000000000000000000000000000000 
Jan Vrany <jan.vrany@fit.cvut.cz>
2012-10-17 13:20 +0200
Commit 4
**EOE**
3:912a64597e4f133ffbc1fdabdda99167a2d69ce2
default
2:db43a5baa9acaf2536d8b12c070b4f5e0363d45c -1:0000000000000000000000000000000000000000 
Jan Vrany <jan.vrany@fit.cvut.cz>
2012-10-17 13:20 +0200
Commit 3
**EOE**
') parseLog.

    self assert: revs size == 2

    "Created: / 13-11-2012 / 17:31:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_version_2_3_3

    | vsn |

    vsn := (HGCommandParser on: 'Mercurial Distributed SCM (version 2.3.2)
(see http://mercurial.selenic.com for more information)

Copyright (C) 2005-2012 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
') parseCommandVersion.

    self assert: vsn = #(2 3 2)

    "Created: / 19-11-2012 / 20:59:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

test_version_2_4

    | vsn |

    vsn := (HGCommandParser on: 'Mercurial Distributed SCM (version 2.4)
(see http://mercurial.selenic.com for more information)

Copyright (C) 2005-2012 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
') parseCommandVersion.

    self assert: vsn = #(2 4 nil)

    "Created: / 19-11-2012 / 21:00:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGCommandParserTests class methodsFor:'documentation'!

version_HG
    "Never, ever change this method. Ask JV or CG why"
    ^thisContext method mclass theNonMetaclass instVarNamed: #revision
!

version_SVN
    ^ '§Id::                                                                                                                        §'
! !