# The file tests the expr command file.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1998 by Moses DeJong
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# SCCS: @(#) ExprCmd.test 1.38 97/11/13 18:50:09

# Note: This test file must be sourced from the parent directory
#       or else the defs file may not be properly loaded.

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest
    namespace import -force ::tcltest::*
}

test ExprCmd-1.1 {cmdProc} {
    list [catch {expr} msg] $msg
} {1 {wrong # args: should be "expr arg ?arg ...?"}}

test ExprCmd-1.2 {cmdProc} {
    expr {1 == "1"}
} {1}

test ExprCmd-1.3 {cmdProc} {
    expr {"1" == 1}
} {1}

test ExprCmd-1.3 {cmdProc} {
    expr {0 == "0"}
} {1}

test ExprCmd-1.4 {cmdProc} {
    expr {"0" == 0}
} {1}

test ExprCmd-1.5 {cmdProc} {
    expr {"1" == "1"}
} {1}

test ExprCmd-1.6 {cmdProc} {
    expr {"" == "1"}
} {0}

test ExprCmd-1.7 {cmdProc} {
    expr {"1" == ""}
} {0}

test ExprCmd-1.8 {cmdProc} {
    expr {"0" == "1"}
} {0}

test ExprCmd-1.9 {cmdProc} {
    expr {"" == "0"}
} {0}

test ExprCmd-1.10 {cmdProc} {
    expr {"0" == ""}
} {0}

test ExprCmd-1.11 {cmdProc} {
    expr {"" == 0}
} {0}

test ExprCmd-1.12 {cmdProc} {
    expr {0 == ""}
} {0}

test ExprCmd-1.13 {cmdProc} {
    expr {1 == "1" && "" == "0"}
} {0}

test ExprCmd-1.14 {cmdProc} {
    expr {1 == "1" && "0" == ""}
} {0}

test ExprCmd-1.15 {cmdProc} {
    expr {0 == {}}
} {0}

test ExprCmd-1.16 {cmdProc} {
    expr {0 == []}
} {0}

test ExprCmd-1.17 {cmdProc} {
    list [catch {expr {0 == "}} err] $err
} {1 {missing "}}

test ExprCmd-1.18 {cmdProc} {
    list [catch {expr {0 == "4.56}} err] $err
} {1 {missing "}}

test ExprCmd-1.19 {cmdProc} {
    list [catch {expr {0 == "[set i 0]}} err] $err
} {1 {missing "}}

test ExprCmd-1.20 {cmdProc} {
    list [catch {expr {0 == "$}} err] $err
} {1 {missing "}}

test ExprCmd-1.21 {cmdProc} {
    list [catch {expr {0 == "\0}} err] $err
} {1 {missing "}}









test ExprCmd-1.22 {cmdProc} {
    expr {0 == "0.0"}
} 1

test ExprCmd-1.23 {cmdProc} {
    expr {0 == " 0.0"}
} 1

test ExprCmd-1.24 {cmdProc} {
    expr {0 == "0.0 "}
} 1

test ExprCmd-1.25 {cmdProc} {
    expr {0 == " 0.0 "}
} 1

test ExprCmd-1.26 {cmdProc} {
    expr {0 == "  0.0  "}
} 1

test ExprCmd-1.27 {cmdProc} {
    expr {1 == "1.0"}
} 1

test ExprCmd-1.28 {cmdProc} {
expr {1 == " 1.0"}
} 1

test ExprCmd-1.29 {cmdProc} {
    expr {1 == "1.0 "}
} 1

test ExprCmd-1.30 {cmdProc} {
    expr {1 == " 1.0 "}
} 1

test ExprCmd-1.31 {cmdProc} {
    expr {1 == "  1.0  "}
} 1

test ExprCmd-1.32 {cmdProc} {
    expr {1 == "0x1"}
} 1

test ExprCmd-1.33 {cmdProc} {
    expr {1 == " 0x1"}
} 1

test ExprCmd-1.34 {cmdProc} {
    expr {1 == "0x1 "}
} 1

test ExprCmd-1.35 {cmdProc} {
    expr {1 == " 0x1 "}
} 1

test ExprCmd-1.36 {cmdProc} {
    expr {1 == "  0x1  "}
} 1

test ExprCmd-1.37 {cmdProc} {
    expr {1 == "1"}
} 1

test ExprCmd-1.38 {cmdProc} {
    expr {1 == " 1"}
} 1

test ExprCmd-1.39 {cmdProc} {
    expr {1 == "1 "}
} 1

test ExprCmd-1.40 {cmdProc} {
    expr {1 == " 1 "}
} 1

test ExprCmd-1.41 {cmdProc} {
    expr {1 == "  1  "}
} 1

test ExprCmd-1.42 {cmdProc} {
    expr "1" == "1 "
} 1

test ExprCmd-1.43 {cmdProc} {
    expr {1} == {1 }
} 1

test ExprCmd-1.44 {cmdProc} {
    expr {"1" == "1 "}
} 1

test ExprCmd-1.45 {cmdProc} {
    expr {"1" == "   1 -"}
} 0

test ExprCmd-1.46 {cmdProc} {
    expr {"1   " == " 1     ^"}
} 0

test ExprCmd-1.47 {cmdProc} {
    expr {"  \
               2   " == 2}
} 1

test ExprCmd-1.48 {cmdProc} {
    expr {"  \n 2 " == 2}
} 1

test ExprCmd-1.49 {cmdProc} {
    expr {" 2 "
       == 2}
} 1

test ExprCmd-1.50 {cmdProc} {
    expr {" 2 2 " == 2}
} 0

test ExprCmd-1.51 {cmdProc} {
    list [catch {
	expr " 2 2 " == 2
    } err] $err
} {1 {syntax error in expression " 2 2  == 2"}}

test ExprCmd-1.52 {cmdProc} {
    list [catch {
        expr {2.0 == 2}
    } err] $err
} {0 1}

test ExprCmd-1.53 {cmdProc} {
    list [catch {
        expr {"2.0" == 2}
    } err] $err
} {0 1}

test ExprCmd-1.54 {cmdProc} {
    set str "   2.0  "
    list [catch {
        expr {$str == 2}
    } err] $err
} {0 1}

test ExprCmd-1.55 {cmdProc} {
    set str "   2.0  "
    list [catch {
        expr {"$str" == 2}
    } err] $err
} {0 1}

test ExprCmd-1.56 {parseBraces} {
    list [catch {
        expr {1 == [}
    } err] $err
} {1 {missing close-bracket}}

test ExprCmd-1.57 {parseBraces} {
    list [catch {
        expr {1 == [hi}
    } err] $err
} {1 {missing close-bracket}}

test ExprCmd-1.58 {parseBraces} {
    set i 0
    list [catch {
        expr {1 == [[set i 1]}
    } err] $i $err [unset i]
} {1 0 {missing close-bracket} {}}

test ExprCmd-1.59 {parseCurleys} {
    set cmd "expr \{1 == \{\}"
    list [catch {
        eval $cmd
    } err] $err [unset cmd]
} {1 {missing close-brace} {}}

test ExprCmd-1.60 {parseCurleys} {
    set cmd "expr \{1 == \{str\}"
    list [catch {
        eval $cmd
    } err] $err [unset cmd]
} {1 {missing close-brace} {}}

test ExprCmd-1.61 {parseCurleys} {
    set cmd "expr \{1 == \{"
    list [catch {
        eval $cmd
    } err] $err [unset cmd]
} {1 {missing close-brace} {}}















# test series 2 will check for error status of
# expr when dealing with input that might look
# like an int or a double but could be invalid




test ExprCmd-2.1 {cmdProc} {
    list [catch {
        expr {111111111111111111111111111111111111 == 2}
    } err] $err
} {1 {integer value too large to represent}}

test ExprCmd-2.2 {cmdProc} {
    list [catch {
        expr "  111111111111111111111111111111111111   " == 2
    } err] $err
} {1 {integer value too large to represent}}

test ExprCmd-2.3 {cmdProc} {
    list [catch {
        expr {11111,1111111111,111111111,111111111 == 2}
    } err] $err
} {1 {syntax error in expression "11111,1111111111,111111111,111111111 == 2"}}

test ExprCmd-2.4 {cmdProc} {
    list [catch {
        expr {111111111111111,111111111111111111111 == 2}
    } err] $err
} {1 {integer value too large to represent}}

test ExprCmd-2.5 {cmdProc} {
    list [catch {
        expr {"111111111111111111,111111111111111111" == 2}
    } err] $err
} {0 0}

test ExprCmd-2.6 {cmdProc} {
    list [catch {
        expr {"  111111111111111111,111111111111111111   " == 2}
    } err] $err
} {0 0}

test ExprCmd-2.7 {cmdProc} {
    list [catch {
        expr {"111111111111111111111111111111111111" == 2}
    } err] $err
} {0 0}

test ExprCmd-2.8 {cmdProc} {
    list [catch {
    expr {{111111111111111111111111111111111111} == 2}
    } err] $err
} {0 0}

test ExprCmd-2.9 {cmdProc} {
    list [catch {
    expr {" 111111111111111111111111111111111111 " == 2}
    } err] $err
} {0 0}

test ExprCmd-2.10 {cmdProc} {
    set str 111111111111111111111111111111111111
    list [catch {
        expr {$str == 2}
    } err] $err
} {0 0}

test ExprCmd-2.11 {cmdProc} {
    set str 111111111111111111111111111111111111
    list [catch {
        expr {"$str" == 2}
    } err] $err
} {0 0}


test ExprCmd-2.12 {cmdProc} {
    list [catch {
        expr {11111111+111111111+1111111111+11111111111 == 2}
    } err] $err
} {1 {integer value too large to represent}}

test ExprCmd-2.13 {cmdProc} {
    list [catch {
        expr {1111111+11111111+11111111+1111111 == 2}
    } err] $err
} {0 0}

test ExprCmd-2.14 {cmdProc} {
    list [catch {
        expr {"1111111+11111111+11111111+1111111" == 2}
    } err] $err
} {0 0}

test ExprCmd-2.15 {cmdProc} {
    list [catch {
        expr {"111111111111111111+111111111111111111" == 2}
    } err] $err
} {0 0}

test ExprCmd-2.16 {cmdProc} {
    list [catch {
        expr {"111111111111111111,111111111111111111" == 2}
    } err] $err
} {0 0}





test ExprCmd-2.17 {cmdProc} {
    list [catch {
        expr {1000 == 1.0e3}
    } err] $err
} {0 1}

test ExprCmd-2.18 {cmdProc} {
    list [catch {
        expr {1000 == "1.0e3"}
    } err] $err
} {0 1}

test ExprCmd-2.19 {cmdProc} {
    list [catch {
        expr {1000 == " 1.0e3"}
    } err] $err
} {0 1}

test ExprCmd-2.20 {cmdProc} {
    list [catch {
        expr {1000 == "1.0e3 "}
    } err] $err
} {0 1}

test ExprCmd-2.21 {cmdProc} {
    list [catch {
        expr {1000 == " 1.0e3 "}
    } err] $err
} {0 1}



test ExprCmd-2.22 {cmdProc} {
    list [catch {
        expr {0 == 1.0e1000}
    } err] $err
} {1 {floating-point value too large to represent}}


test ExprCmd-2.23 {cmdProc} {
    list [catch {
        expr {1 == 1.0x1000}
    } err] $err
} {1 {syntax error in expression "1 == 1.0x1000"}}



test ExprCmd-2.24 {cmdProc} {
    list [catch {
        expr {0 == "1.0e1000"}
    } err] $err
} {0 0}


test ExprCmd-2.25 {cmdProc} {
    list [catch {
        expr {0 == " 1.0e1000"}
    } err] $err
} {0 0}


test ExprCmd-2.26 {cmdProc} {
    list [catch {
        expr {0 == "1.0e1000 "}
    } err] $err
} {0 0}


test ExprCmd-2.27 {cmdProc} {
    list [catch {
        expr {0 == "  1.0e100000000 "}
    } err] $err
} {0 0}

test ExprCmd-2.28 {cmdProc} {
    list [catch {
        expr {0 == {1.0e100000000}}
    } err] $err
} {0 0}





test ExprCmd-2.29 {cmdProc} {
    list [catch {
        expr {0 == "  1.5e100000000-438959345345  "}
    } err] $err
} {0 0}

test ExprCmd-2.30 {cmdProc} {
    list [catch {
        expr {0 == "  1.5e1000,546,  "}
    } err] $err
} {0 0}

test ExprCmd-2.31 {cmdProc} {
    list [catch {
        expr {0 == "  1.5e1000.-438959345345  "}
    } err] $err
} {0 0}




