diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2020-11-08 17:21:09 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2020-11-08 17:21:09 (GMT) |
commit | 40b3d4d5dd32bfe69a1f7771c6aa470265aa06bf (patch) | |
tree | 52d58782baa2eebc5da6fa970beeffc04d03f4d4 /tests | |
parent | d60bc321ce3c20557744e9e4ac1d5ae45f0d7ee3 (diff) | |
parent | b7efdfe9bc03114b633073ed9d4423e4f88582c5 (diff) | |
download | tcl-40b3d4d5dd32bfe69a1f7771c6aa470265aa06bf.zip tcl-40b3d4d5dd32bfe69a1f7771c6aa470265aa06bf.tar.gz tcl-40b3d4d5dd32bfe69a1f7771c6aa470265aa06bf.tar.bz2 |
TIP 582: Comments in Expressions
Diffstat (limited to 'tests')
-rw-r--r-- | tests/compExpr.test | 36 | ||||
-rw-r--r-- | tests/expr-old.test | 2 | ||||
-rw-r--r-- | tests/expr.test | 61 | ||||
-rw-r--r-- | tests/parseExpr.test | 8 |
4 files changed, 106 insertions, 1 deletions
diff --git a/tests/compExpr.test b/tests/compExpr.test index 35d7588..4ef155b 100644 --- a/tests/compExpr.test +++ b/tests/compExpr.test @@ -371,10 +371,46 @@ test compExpr-7.2 {[Bug 1869989]: expr parser memleak} -constraints memory -setu unset end i tmp rename getbytes {} } -result 0 + +proc extract {opcodes descriptor} { + set instructions [dict values [dict get $descriptor instructions]] + return [lmap i $instructions { + if {[lindex $i 0] in $opcodes} {string cat $i} else continue + }] +} + +test compExpr-8.1 {TIP 582: expression comments} -setup {} -body { + extract {loadStk add} [tcl::unsupported::getbytecode script {expr { + $abc + # + $def + + $ghi + }}] +} -result {loadStk loadStk add} +test compExpr-8.2 {TIP 582: expression comments} -setup {} -body { + extract {loadStk add} [tcl::unsupported::getbytecode script {expr { + $abc + # + $def + # + $ghi }}] +} -result loadStk +test compExpr-8.3 {TIP 582: expression comments} -setup {} -body { + extract {loadStk add} [tcl::unsupported::getbytecode script {expr { + $abc + # + $def\ + + $ghi + }}] +} -result loadStk +test compExpr-8.4 {TIP 582: expression comments} -setup {} -body { + extract {loadStk add} [tcl::unsupported::getbytecode script {expr { + $abc + # + $def\\ + + $ghi + }}] +} -result {loadStk loadStk add} # cleanup catch {unset a} catch {unset b} +catch {rename extract ""} ::tcltest::cleanupTests return diff --git a/tests/expr-old.test b/tests/expr-old.test index 914530e..327faa2 100644 --- a/tests/expr-old.test +++ b/tests/expr-old.test @@ -524,7 +524,7 @@ test expr-old-26.10b {error conditions} ieeeFloatingPoint { list [catch {expr 2.0/0.0} msg] $msg } {0 Inf} test expr-old-26.11 {error conditions} -body { - expr 2# + expr 2` } -returnCodes error -match glob -result * test expr-old-26.12 {error conditions} -body { expr a.b diff --git a/tests/expr.test b/tests/expr.test index 5e00841..da5a23d 100644 --- a/tests/expr.test +++ b/tests/expr.test @@ -7384,6 +7384,67 @@ foreach v1 $values r1 $results { } } unset -nocomplain values results ctr + +test expr-62.1 {TIP 582: comments} -body { + expr {1 # + 2} +} -result 1 +test expr-62.2 {TIP 582: comments} -body { + expr "1 #\n+ 2" +} -result 3 +test expr-62.3 {TIP 582: comments} -setup { + set ctr 0 +} -body { + expr { + # This is a demonstration of a comment + 1 + 2 + 3 + # and another comment + + 4 + 5 + # + [incr ctr] + + [incr ctr] + } +} -result 16 +# Buggy because line breaks aren't tracked inside expressions at all +test expr-62.4 {TIP 582: comments don't hide line breaks} -setup { + proc getline {} { + dict get [info frame -1] line + } + set base [getline] +} -constraints knownBug -body { + expr { + 0 + # a comment + + [getline] - $base + } +} -cleanup { + rename getline "" +} -result 5 +test expr-62.5 {TIP 582: comments don't splice tokens} { + set a False + expr {$a#don't splice +ne#don't splice +false} +} 1 +test expr-62.6 {TIP 582: comments don't splice tokens} { + expr {0x2#don't splice +ne#don't splice +2} +} 1 +test expr-62.7 {TIP 582: comments can go inside function calls} { + expr {max(1,# comment + 2)} +} 2 +test expr-62.8 {TIP 582: comments can go inside function calls} { + expr {max(1# comment + ,2)} +} 2 +test expr-62.9 {TIP 582: comments can go inside function calls} { + expr {max(# comment + 1,2)} +} 2 +test expr-62.10 {TIP 582: comments can go inside function calls} { + expr {max# comment + (1,2)} +} 2 # cleanup unset -nocomplain a diff --git a/tests/parseExpr.test b/tests/parseExpr.test index 8b5e429..735dace 100644 --- a/tests/parseExpr.test +++ b/tests/parseExpr.test @@ -1075,6 +1075,14 @@ test parseExpr-22.21 {Bug d2ffcca163} -constraints testexprparser -body { testexprparser in\u0433(0) -1 } -returnCodes error -match glob -result {missing operand*} +test parseExpr-23.1 {TIP 582: comments} -constraints testexprparser -body { + testexprparser "7 # * 8 " -1 +} -result {- {} 0 subexpr 7 1 text 7 0 {}} +test parseExpr-23.2 {TIP 582: comments} -constraints testexprparser -body { + testexprparser "7 #\n* 8 " -1 +} -result {- {} 0 subexpr {7 # +*} 5 operator # 0 subexpr 7 1 text 7 0 subexpr * 1 text * 0 {}} + # cleanup cleanupTests return |