summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2020-08-22 14:14:05 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2020-08-22 14:14:05 (GMT)
commit42a34d459e99c9e366e626e134d3e75e74e1f191 (patch)
tree65e81238673688720cb767c89c47f23c22dca5aa /tests
parent5dfe6151b2c83fac63e73c24a45797c938c2fa5b (diff)
downloadtcl-42a34d459e99c9e366e626e134d3e75e74e1f191.zip
tcl-42a34d459e99c9e366e626e134d3e75e74e1f191.tar.gz
tcl-42a34d459e99c9e366e626e134d3e75e74e1f191.tar.bz2
Implementation of TIP 582: comments in expressions
Diffstat (limited to 'tests')
-rw-r--r--tests/compExpr.test36
-rw-r--r--tests/expr-old.test2
-rw-r--r--tests/expr.test34
-rw-r--r--tests/parseExpr.test8
4 files changed, 79 insertions, 1 deletions
diff --git a/tests/compExpr.test b/tests/compExpr.test
index 3b44af8..8803f17 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 003ee00..de10da0 100644
--- a/tests/expr-old.test
+++ b/tests/expr-old.test
@@ -522,7 +522,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 632f1c4..ef00464 100644
--- a/tests/expr.test
+++ b/tests/expr.test
@@ -7384,6 +7384,40 @@ 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
# cleanup
unset -nocomplain a
diff --git a/tests/parseExpr.test b/tests/parseExpr.test
index 47dbec5..8ca5fca 100644
--- a/tests/parseExpr.test
+++ b/tests/parseExpr.test
@@ -1073,6 +1073,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