# -*- tcl -*-
# Graph tests - assignment (=)
# Copyright (c) 2006 Andreas Kupries <andreas_kupries@users.sourceforge.net>
# All rights reserved.
# RCS: @(#) $Id: assign.test,v 1.2 2007/04/12 03:01:54 andreas_kupries Exp $

# Syntax: graph = GRAPH

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

test graph-${impl}-${setimpl}-assign-1.0 {assign, wrong#args, missing} {
    SETUP
    catch {mygraph =} result
    mygraph destroy
    set result
} [tmWrong = source 0]

test graph-${impl}-${setimpl}-assign-1.1 {assign, wrong#args, too many} {
    SETUP
    catch {mygraph = foo bar} result
    mygraph destroy
    set result
} [tmTooMany = source]

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

test graph-${impl}-${setimpl}-assign-2.0 {assign, bad src command} {
    SETUP
    catch {mygraph = foo} result
    mygraph destroy
    set result
} {invalid command name "foo"}

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

test graph-${impl}-${setimpl}-assign-3.0 {assign, direct} {
    set serial {%3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}

    SETUP
    SETUP bgraph

    mygraph deserialize $serial

    set result [validate_serial bgraph $serial]
    bgraph = mygraph
    lappend result [validate_serial bgraph $serial]

    mygraph destroy
    bgraph  destroy
    set result
} {attr/graph/data-mismatch ok}

test graph-${impl}-${setimpl}-assign-3.1 {assign, deserial/serial} {
    set serial {%3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}

    SETUP
    SETUP bgraph
    proc mywrap {args} {uplevel #0 [linsert $args 0 mygraph]}

    mygraph deserialize $serial

    set result [validate_serial bgraph $serial]
    bgraph = mywrap
    lappend result [validate_serial bgraph $serial]

    mygraph destroy
    bgraph  destroy
    rename mywrap {}
    set result
} {attr/graph/data-mismatch ok}

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