Go Back |
Previous Test: Test 14
Test 15
The changed lines are in bold.
| tfc-part2.test (174 lines, 3993 bytes) |
package require tcltest
namespace import ::tcltest::*
source tfc-part2.tcl
saveState
test thatCellsAreEmptyByDefault-1.1 \
{test that cells are not empty by default} {} {
set sheet [Sheet::new]
list [$sheet get A1] [$sheet get ZX347]
} {{} {}}
restoreState
test thatTextCellsAreStored-1.1 \
{test that text cells are stored} {} {
set sheet [Sheet::new]
set theCell A21
$sheet put $theCell {A string}
lappend results [$sheet get $theCell]
$sheet put $theCell {A different string}
lappend results [$sheet get $theCell]
$sheet put $theCell {}
lappend results [$sheet get $theCell]
set results
} {{A string} {A different string} {}}
restoreState
test thatManyCellsExist-1.1 \
{test that many cells exist} {} {
set sheet [Sheet::new]
$sheet put A1 First
$sheet put X27 Second
$sheet put ZX901 Third
lappend results [$sheet get A1]
lappend results [$sheet get X27]
lappend results [$sheet get ZX901]
$sheet put A1 Fourth
lappend results [$sheet get A1]
lappend results [$sheet get X27]
lappend results [$sheet get ZX901]
set results
} {First Second Third Fourth Second Third}
restoreState
test thatNumericCellsAreIdentifiedAndStored-1.1 \
{test that numeric cells are identified and stored} {} {
set sheet [Sheet::new]
set theCell A21
$sheet put $theCell X99
lappend results [$sheet get $theCell]
$sheet put $theCell 14
lappend results [$sheet get $theCell]
$sheet put $theCell { 99 X}
lappend results [$sheet get $theCell]
$sheet put $theCell { 1234 }
lappend results [$sheet get $theCell]
$sheet put $theCell { }
lappend results [$sheet get $theCell]
set results
} {X99 14 { 99 X} 1234 { }}
restoreState
test thatWeHaveAccessToCellLiteralValuesForEditing-1.1 \
{test that we have access to cell literal values for editing} {} {
set sheet [Sheet::new]
set theCell A21
$sheet put $theCell {Some string}
lappend results [$sheet getLiteral $theCell]
$sheet put $theCell { 1234 }
lappend results [$sheet getLiteral $theCell]
$sheet put $theCell =7
lappend results [$sheet getLiteral $theCell]
} {{Some string} { 1234 } =7}
restoreState
test formulaSpec-1.1 \
{test formula spec} {} {
set sheet [Sheet::new]
$sheet put B1 { =7}
lappend results [$sheet get B1]
lappend results [$sheet getLiteral B1]
} {{ =7} { =7}}
restoreState
test constantFormula-1.1 \
{test constant formula} {} {
set sheet [Sheet::new]
$sheet put A1 =7
lappend results [$sheet getLiteral A1]
lappend results [$sheet get A1]
} {=7 7}
restoreState
test parentheses-1.1 \
{test parenthesis} {} {
set sheet [Sheet::new]
$sheet put A1 =(7)
lappend results [$sheet get A1]
} {7}
restoreState
test deepParentheses-1.1 \
{test deep parenthesis} {} {
set sheet [Sheet::new]
$sheet put A1 =((((10))))
lappend results [$sheet get A1]
} {10}
restoreState
test multiply-1.1 \
{test multiply} {} {
set sheet [Sheet::new]
$sheet put A1 =2*3*4
lappend results [$sheet get A1]
} {24}
restoreState
test add-1.1 \
{test add} {} {
set sheet [Sheet::new]
$sheet put A1 =71+2+3
lappend results [$sheet get A1]
} {76}
restoreState
test precedence-1.1 \
{test precedence} {} {
set sheet [Sheet::new]
$sheet put A1 =7+2*3
lappend results [$sheet get A1]
} {13}
restoreState
test fullExpression-1.1 \
{test full expression} {} {
set sheet [Sheet::new]
$sheet put A1 =7*(2+3)*((((2+1))))
lappend results [$sheet get A1]
} {105}
restoreState
test simpleFormulaError-1.1 \
{test simple formula error} {} {
set sheet [Sheet::new]
$sheet put A1 =7*
lappend results [$sheet get A1]
} {#Error}
restoreState
test parenthesisError-1.1 \
{test parenthesis error} {} {
set sheet [Sheet::new]
$sheet put A1 =(((((7))
lappend results [$sheet get A1]
} {#Error}
cleanupTests
| tfc-part2.tcl (69 lines, 1628 bytes) |
namespace eval Sheet {
variable count
set count 0
proc new {} {
variable count
incr count
namespace eval [namespace current]::$count {
proc get {key} {
variable cells
if {[info exists cells($key)]} {
if {[string match = [string index $cells($key) 0]]} {
if {[catch {expr [string range $cells($key) 1 end]} msg]} {
return #Error
} else {
return $msg
}
} elseif {[string is integer $cells($key)]} {
return [string trim $cells($key)]
} else {
return $cells($key)
}
}
}
proc put {key value} {
variable cells
set cells($key) $value
}
proc getLiteral {key} {
variable cells
if {[info exists cells($key)]} {
return $cells($key)
}
}
}
proc [namespace current]::$count {args} {
variable count
set procName [namespace current]::$count
set command [lindex $args 0]
switch -exact $command {
get {
${procName}::$command [lindex $args 1]
}
put {
${procName}::$command [lindex $args 1] [lindex $args 2]
}
getLiteral {
${procName}::$command [lindex $args 1]
}
default {
if {[llength $args] == 0} {
error "wrong # args: should be \"$procName option ?arg arg ...?"
} else {
error "bad option \"$command\": must be get, getLiteral, or put"
}
}
}
}
return [namespace current]::$count
}
}