# -*- tcl -*-
# Graph tests - graph/arc/node lappend (attribute lappend)
# Copyright (c) 2006 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
# RCS: @(#) $Id: lappend.test,v 1.3 2008/03/07 06:51:39 andreas_kupries Exp $

# Syntax: graph      lappend      KEY VALUE
# Syntax: graph arc  lappend ARC  KEY VALUE
# Syntax: graph node lappend NODE KEY VALUE

# -------------------------------------------------------------------------

foreach {e ex stem mp mk} {
    arc   Arc   {mygraph arc}  {arc }  x
    node  Node  {mygraph node} {node } x
    graph Graph {mygraph}      {}      {}
} {
    AttrSetup

    # -------------------------------------------------------------------------
    # Wrong # args: Missing, Too many

    test graph-${impl}-${setimpl}-${e}-lappend-1.0 "$e lappend, wrong#args, missing" {
	SETUP
	catch {CMD lappend} msg
	mygraph destroy
	set msg
    } [tmWrongA "${mp}lappend" "${mp}key value" 0] ; # {}

    test graph-${impl}-${setimpl}-${e}-lappend-1.1 "$e lappend, wrong#args, missing" {
	SETUP
	catch {CMD lappend a} msg
	mygraph destroy
	set msg
    } [tmWrongA "${mp}lappend" "${mp}key value" 1] ; # {}

    test graph-${impl}-${setimpl}-${e}-lappend-1.2 "$e lappend, wrong#args, missing" !graph {
	SETUP
	catch {CMD lappend a b} msg
	mygraph destroy
	set msg
    } [tmWrongA "${mp}lappend" "${mp}key value" 2] ; # {}

    test graph-${impl}-${setimpl}-${e}-lappend-1.3 "$e lappend, wrong#args, too many" {
	SETUP
	catch {CMD lappend a b c d} msg
	mygraph destroy
	set msg
    } [tmTooManyA "${mp}lappend" "${mp}key value"] ; # {}

    # -------------------------------------------------------------------------
    # Logical arguments checks and failures

    test graph-${impl}-${setimpl}-${e}-lappend-2.0 "$e lappend, missing $e" !graph {
	SETUP
	catch {Lappend$ex data foo} msg
	mygraph destroy
	set msg
    } [Missing$ex $MY x] ; # {}

    # -------------------------------------------------------------------------
    # Ok arguments.

    test graph-${impl}-${setimpl}-${e}-lappend-3.0 "$e lappend, no attribute, created" {
	SETUP
	$ex
	set     result {}
	lappend result [Keyexists$ex data]
	lappend result [Lappend$ex   data bar]
	lappend result [Keyexists$ex data]
	lappend result [Get$ex       data]
	mygraph destroy
	set result
    } {0 bar 1 bar} ; # {}

    test graph-${impl}-${setimpl}-${e}-lappend-3.1 "$e lappend, existing attribute, appending" {
	SETUP
	$ex
	set     result {}
	lappend result [SetW$ex    data foo]
	lappend result [Lappend$ex data bar]
	lappend result [Get$ex     data]
	mygraph destroy
	set result
    } {foo {foo bar} {foo bar}} ; # {}
}

# -------------------------------------------------------------------------
