Blame tests/upstream-test-suite/060_command_switch.tcl

Than Ngo b7bcaa
#// objective: tests processing of switch, only references/referencedby relations are relevant
Than Ngo b7bcaa
#// check: 060__command__switch_8tcl.xml
Than Ngo b7bcaa
#// config: REFERENCED_BY_RELATION = yes
Than Ngo b7bcaa
#// config: REFERENCES_RELATION = yes
Than Ngo b7bcaa
#// config: EXTRACT_ALL = yes
Than Ngo b7bcaa
#// config: INLINE_SOURCES = no
Than Ngo b7bcaa
Than Ngo b7bcaa
##
Than Ngo b7bcaa
# \brief should be reference by every proc below
Than Ngo b7bcaa
proc Invoked args {
Than Ngo b7bcaa
    puts "Procedure \"Invoked\" is invoked indeed. Ok."
Than Ngo b7bcaa
    return $args
Than Ngo b7bcaa
}
Than Ngo b7bcaa
##
Than Ngo b7bcaa
# \brief must not be reference by every proc below
Than Ngo b7bcaa
proc NotInvoked args {
Than Ngo b7bcaa
    puts "Procedure \"NotInvoked\" is invoked. Not Ok!"
Than Ngo b7bcaa
    return $args
Than Ngo b7bcaa
}
Than Ngo b7bcaa
#
Than Ngo b7bcaa
# check if call references work at all
Than Ngo b7bcaa
proc a args {
Than Ngo b7bcaa
    Invoked NotInvoked
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
#
Than Ngo b7bcaa
# switch command
Than Ngo b7bcaa
# switch ?options? string pattern body ?pattern body ...? 
Than Ngo b7bcaa
proc b args {
Than Ngo b7bcaa
    switch value NotInvoked {
Than Ngo b7bcaa
        } NotInvoked {
Than Ngo b7bcaa
        } default {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc c args {
Than Ngo b7bcaa
    switch value NotInvoked {
Than Ngo b7bcaa
        } [Invoked] {
Than Ngo b7bcaa
        } default {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc d args {
Than Ngo b7bcaa
    switch NotInvoked pattern {
Than Ngo b7bcaa
        } [Invoked] {
Than Ngo b7bcaa
        } default {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc e args {
Than Ngo b7bcaa
    switch [Invoked] pattern {
Than Ngo b7bcaa
        } NotInvoked {
Than Ngo b7bcaa
        } default {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc f args {
Than Ngo b7bcaa
    switch -exact value pattern {
Than Ngo b7bcaa
        } NotInvoked {
Than Ngo b7bcaa
        } default {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc g args {
Than Ngo b7bcaa
    switch -exact -- value pattern {
Than Ngo b7bcaa
        } NotInvoked {
Than Ngo b7bcaa
        } default {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc h args {
Than Ngo b7bcaa
    switch -exact -- -value pattern {
Than Ngo b7bcaa
        } NotInvoked {
Than Ngo b7bcaa
        } default {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
# switch ?options? string {pattern body ?pattern body ...?} 
Than Ngo b7bcaa
proc i args {
Than Ngo b7bcaa
    switch value {
Than Ngo b7bcaa
        NotInvoked {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        NotInvoked {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        default {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc j args {
Than Ngo b7bcaa
    switch vale {
Than Ngo b7bcaa
        NotInvoked {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        [NotInvoked] {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        default {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc k args {
Than Ngo b7bcaa
    switch NotInvoked {
Than Ngo b7bcaa
        [NotInvoked] {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        NotInvoked {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        default {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc l args {
Than Ngo b7bcaa
    switch [Invoked] {
Than Ngo b7bcaa
        pattern {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        NotInvoked {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        default {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc m args {
Than Ngo b7bcaa
    switch -exact value {
Than Ngo b7bcaa
        pattern {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        NotInvoked {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        default {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc n args {
Than Ngo b7bcaa
    switch -exact -- value {
Than Ngo b7bcaa
        pattern {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        NotInvoked {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        default {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc o args {
Than Ngo b7bcaa
    switch -exact -- -value {
Than Ngo b7bcaa
        pattern {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        NotInvoked {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        default {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc p args {
Than Ngo b7bcaa
    switch -exact -- inquotes {
Than Ngo b7bcaa
        "inquotes" {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        default {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc q args {
Than Ngo b7bcaa
    switch -exact -- "in quotes" {
Than Ngo b7bcaa
        "in quotes" {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        default {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc r args {
Than Ngo b7bcaa
    switch -exact -- inbraces {
Than Ngo b7bcaa
        {inbraces} {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        default {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
proc s args {
Than Ngo b7bcaa
    switch -exact -- {in braces} {
Than Ngo b7bcaa
        {in braces} {
Than Ngo b7bcaa
            Invoked
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
        default {
Than Ngo b7bcaa
        }
Than Ngo b7bcaa
    }
Than Ngo b7bcaa
    return
Than Ngo b7bcaa
}
Than Ngo b7bcaa
# wrong syntax
Than Ngo b7bcaa
#proc x args {
Than Ngo b7bcaa
#    catch {switch -exact -- [Invoked] pattern1 NotInvoked pattern2}
Than Ngo b7bcaa
#    return
Than Ngo b7bcaa
#}
Than Ngo b7bcaa
# The current version does not check the last argument beforehand.
Than Ngo b7bcaa
# Therefore, all script elements are evaluated as scripts before
Than Ngo b7bcaa
# the parser detects the dangling pattern. It throws a warning, at the very least.
Than Ngo b7bcaa
# Anyway, for working code the documentation will be correct.
Than Ngo b7bcaa
#proc y args {
Than Ngo b7bcaa
#    catch {switch -exact -- [Invoked] {
Than Ngo b7bcaa
#        pattern {
Than Ngo b7bcaa
#            NotInvoked
Than Ngo b7bcaa
#        }
Than Ngo b7bcaa
#        NotInvoked {
Than Ngo b7bcaa
#            NotInvoked
Than Ngo b7bcaa
#        }
Than Ngo b7bcaa
#        default {
Than Ngo b7bcaa
#            NotInvoked
Than Ngo b7bcaa
#        }
Than Ngo b7bcaa
#        pattern
Than Ngo b7bcaa
#    }}
Than Ngo b7bcaa
#    return
Than Ngo b7bcaa
#}
Than Ngo b7bcaa
#
Than Ngo b7bcaa
# call all single letter procs
Than Ngo b7bcaa
# let tcl check what is called and what is not called
Than Ngo b7bcaa
foreach p [info procs ?] {
Than Ngo b7bcaa
    puts "Check procedure \"$p\""
Than Ngo b7bcaa
    $p
Than Ngo b7bcaa
}
Than Ngo b7bcaa
exit
Than Ngo b7bcaa