Commit 6b5962c2 authored by Rob Pike's avatar Rob Pike

test/chan/select5.go: update to new templates

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4911041
parent 7dce257a
...@@ -17,8 +17,8 @@ import ( ...@@ -17,8 +17,8 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"io" "io"
"old/template"
"os" "os"
"template"
) )
func main() { func main() {
...@@ -135,181 +135,180 @@ func main() { ...@@ -135,181 +135,180 @@ func main() {
} }
` `
func parse(s string) *template.Template { func parse(name, s string) *template.Template {
t := template.New(nil) t, err := template.New(name).Parse(s)
t.SetDelims("〈", "〉") if err != nil {
if err := t.Parse(s); err != nil { panic(fmt.Sprintf("%q: %s", name, err))
panic(s)
} }
return t return t
} }
var recv = parse(` var recv = parse("recv", `
〈# Send n, receive it one way or another into x, check that they match.〉 {{/* Send n, receive it one way or another into x, check that they match. */}}
c <- n c <- n
〈.section Maybe〉 {{with .Maybe}}
x = <-c x = <-c
〈.or〉 {{else}}
select { select {
〈# Blocking or non-blocking, before the receive.〉 {{/* Blocking or non-blocking, before the receive. */}}
〈# The compiler implements two-case select where one is default with custom code,〉 {{/* The compiler implements two-case select where one is default with custom code, */}}
〈# so test the default branch both before and after the send.〉 {{/* so test the default branch both before and after the send. */}}
〈.section MaybeDefault〉 {{with .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
〈.end〉 {{end}}
〈# Receive from c. Different cases are direct, indirect, :=, interface, and map assignment.〉 {{/* Receive from c. Different cases are direct, indirect, :=, interface, and map assignment. */}}
〈.section Maybe〉 {{with .Maybe}}
case x = <-c: case x = <-c:
〈.or〉〈.section Maybe〉 {{else}}{{with .Maybe}}
case *f(&x) = <-c: case *f(&x) = <-c:
〈.or〉〈.section Maybe〉 {{else}}{{with .Maybe}}
case y := <-c: case y := <-c:
x = y x = y
〈.or〉〈.section Maybe〉 {{else}}{{with .Maybe}}
case i = <-c: case i = <-c:
x = i.(int) x = i.(int)
〈.or〉 {{else}}
case m[13] = <-c: case m[13] = <-c:
x = m[13] x = m[13]
〈.end〉〈.end〉〈.end〉〈.end〉 {{end}}{{end}}{{end}}{{end}}
〈# Blocking or non-blocking again, after the receive.〉 {{/* Blocking or non-blocking again, after the receive. */}}
〈.section MaybeDefault〉 {{with .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
〈.end〉 {{end}}
〈# Dummy send, receive to keep compiler from optimizing select.〉 {{/* Dummy send, receive to keep compiler from optimizing select. */}}
〈.section Maybe〉 {{with .Maybe}}
case dummy <- 1: case dummy <- 1:
panic("dummy send") panic("dummy send")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case <-dummy: case <-dummy:
panic("dummy receive") panic("dummy receive")
〈.end〉 {{end}}
〈# Nil channel send, receive to keep compiler from optimizing select.〉 {{/* Nil channel send, receive to keep compiler from optimizing select. */}}
〈.section Maybe〉 {{with .Maybe}}
case nilch <- 1: case nilch <- 1:
panic("nilch send") panic("nilch send")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case <-nilch: case <-nilch:
panic("nilch recv") panic("nilch recv")
〈.end〉 {{end}}
} }
〈.end〉 {{end}}
if x != n { if x != n {
die(x) die(x)
} }
n++ n++
`) `)
var recvOrder = parse(` var recvOrder = parse("recvOrder", `
〈# Send n, receive it one way or another into x, check that they match.〉 {{/* Send n, receive it one way or another into x, check that they match. */}}
〈# Check order of operations along the way by calling functions that check〉 {{/* Check order of operations along the way by calling functions that check */}}
〈# that the argument sequence is strictly increasing.〉 {{/* that the argument sequence is strictly increasing. */}}
order = 0 order = 0
c <- n c <- n
〈.section Maybe〉 {{with .Maybe}}
〈# Outside of select, left-to-right rule applies.〉 {{/* Outside of select, left-to-right rule applies. */}}
〈# (Inside select, assignment waits until case is chosen,〉 {{/* (Inside select, assignment waits until case is chosen, */}}
〈# so right hand side happens before anything on left hand side.〉 {{/* so right hand side happens before anything on left hand side. */}}
*fp(&x, 1) = <-fc(c, 2) *fp(&x, 1) = <-fc(c, 2)
〈.or〉〈.section Maybe〉 {{else}}{{with .Maybe}}
m[fn(13, 1)] = <-fc(c, 2) m[fn(13, 1)] = <-fc(c, 2)
x = m[13] x = m[13]
〈.or〉 {{else}}
select { select {
〈# Blocking or non-blocking, before the receive.〉 {{/* Blocking or non-blocking, before the receive. */}}
〈# The compiler implements two-case select where one is default with custom code,〉 {{/* The compiler implements two-case select where one is default with custom code, */}}
〈# so test the default branch both before and after the send.〉 {{/* so test the default branch both before and after the send. */}}
〈.section MaybeDefault〉 {{with .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
〈.end〉 {{end}}
〈# Receive from c. Different cases are direct, indirect, :=, interface, and map assignment.〉 {{/* Receive from c. Different cases are direct, indirect, :=, interface, and map assignment. */}}
〈.section Maybe〉 {{with .Maybe}}
case *fp(&x, 100) = <-fc(c, 1): case *fp(&x, 100) = <-fc(c, 1):
〈.or〉〈.section Maybe〉 {{else}}{{with .Maybe}}
case y := <-fc(c, 1): case y := <-fc(c, 1):
x = y x = y
〈.or〉〈.section Maybe〉 {{else}}{{with .Maybe}}
case i = <-fc(c, 1): case i = <-fc(c, 1):
x = i.(int) x = i.(int)
〈.or〉 {{else}}
case m[fn(13, 100)] = <-fc(c, 1): case m[fn(13, 100)] = <-fc(c, 1):
x = m[13] x = m[13]
〈.end〉〈.end〉〈.end〉 {{end}}{{end}}{{end}}
〈# Blocking or non-blocking again, after the receive.〉 {{/* Blocking or non-blocking again, after the receive. */}}
〈.section MaybeDefault〉 {{with .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
〈.end〉 {{end}}
〈# Dummy send, receive to keep compiler from optimizing select.〉 {{/* Dummy send, receive to keep compiler from optimizing select. */}}
〈.section Maybe〉 {{with .Maybe}}
case fc(dummy, 2) <- fn(1, 3): case fc(dummy, 2) <- fn(1, 3):
panic("dummy send") panic("dummy send")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case <-fc(dummy, 4): case <-fc(dummy, 4):
panic("dummy receive") panic("dummy receive")
〈.end〉 {{end}}
〈# Nil channel send, receive to keep compiler from optimizing select.〉 {{/* Nil channel send, receive to keep compiler from optimizing select. */}}
〈.section Maybe〉 {{with .Maybe}}
case fc(nilch, 5) <- fn(1, 6): case fc(nilch, 5) <- fn(1, 6):
panic("nilch send") panic("nilch send")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case <-fc(nilch, 7): case <-fc(nilch, 7):
panic("nilch recv") panic("nilch recv")
〈.end〉 {{end}}
} }
〈.end〉〈.end〉 {{end}}{{end}}
if x != n { if x != n {
die(x) die(x)
} }
n++ n++
`) `)
var send = parse(` var send = parse("send", `
〈# Send n one way or another, receive it into x, check that they match.〉 {{/* Send n one way or another, receive it into x, check that they match. */}}
〈.section Maybe〉 {{with .Maybe}}
c <- n c <- n
〈.or〉 {{else}}
select { select {
〈# Blocking or non-blocking, before the receive (same reason as in recv).〉 {{/* Blocking or non-blocking, before the receive (same reason as in recv). */}}
〈.section MaybeDefault〉 {{with .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
〈.end〉 {{end}}
〈# Send c <- n. No real special cases here, because no values come back〉 {{/* Send c <- n. No real special cases here, because no values come back */}}
〈# from the send operation.〉 {{/* from the send operation. */}}
case c <- n: case c <- n:
〈# Blocking or non-blocking.〉 {{/* Blocking or non-blocking. */}}
〈.section MaybeDefault〉 {{with .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
〈.end〉 {{end}}
〈# Dummy send, receive to keep compiler from optimizing select.〉 {{/* Dummy send, receive to keep compiler from optimizing select. */}}
〈.section Maybe〉 {{with .Maybe}}
case dummy <- 1: case dummy <- 1:
panic("dummy send") panic("dummy send")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case <-dummy: case <-dummy:
panic("dummy receive") panic("dummy receive")
〈.end〉 {{end}}
〈# Nil channel send, receive to keep compiler from optimizing select.〉 {{/* Nil channel send, receive to keep compiler from optimizing select. */}}
〈.section Maybe〉 {{with .Maybe}}
case nilch <- 1: case nilch <- 1:
panic("nilch send") panic("nilch send")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case <-nilch: case <-nilch:
panic("nilch recv") panic("nilch recv")
〈.end〉 {{end}}
} }
〈.end〉 {{end}}
x = <-c x = <-c
if x != n { if x != n {
die(x) die(x)
...@@ -317,48 +316,48 @@ var send = parse(` ...@@ -317,48 +316,48 @@ var send = parse(`
n++ n++
`) `)
var sendOrder = parse(` var sendOrder = parse("sendOrder", `
〈# Send n one way or another, receive it into x, check that they match.〉 {{/* Send n one way or another, receive it into x, check that they match. */}}
〈# Check order of operations along the way by calling functions that check〉 {{/* Check order of operations along the way by calling functions that check */}}
〈# that the argument sequence is strictly increasing.〉 {{/* that the argument sequence is strictly increasing. */}}
order = 0 order = 0
〈.section Maybe〉 {{with .Maybe}}
fc(c, 1) <- fn(n, 2) fc(c, 1) <- fn(n, 2)
〈.or〉 {{else}}
select { select {
〈# Blocking or non-blocking, before the receive (same reason as in recv).〉 {{/* Blocking or non-blocking, before the receive (same reason as in recv). */}}
〈.section MaybeDefault〉 {{with .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
〈.end〉 {{end}}
〈# Send c <- n. No real special cases here, because no values come back〉 {{/* Send c <- n. No real special cases here, because no values come back */}}
〈# from the send operation.〉 {{/* from the send operation. */}}
case fc(c, 1) <- fn(n, 2): case fc(c, 1) <- fn(n, 2):
〈# Blocking or non-blocking.〉 {{/* Blocking or non-blocking. */}}
〈.section MaybeDefault〉 {{with .MaybeDefault}}
default: default:
panic("nonblock") panic("nonblock")
〈.end〉 {{end}}
〈# Dummy send, receive to keep compiler from optimizing select.〉 {{/* Dummy send, receive to keep compiler from optimizing select. */}}
〈.section Maybe〉 {{with .Maybe}}
case fc(dummy, 3) <- fn(1, 4): case fc(dummy, 3) <- fn(1, 4):
panic("dummy send") panic("dummy send")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case <-fc(dummy, 5): case <-fc(dummy, 5):
panic("dummy receive") panic("dummy receive")
〈.end〉 {{end}}
〈# Nil channel send, receive to keep compiler from optimizing select.〉 {{/* Nil channel send, receive to keep compiler from optimizing select. */}}
〈.section Maybe〉 {{with .Maybe}}
case fc(nilch, 6) <- fn(1, 7): case fc(nilch, 6) <- fn(1, 7):
panic("nilch send") panic("nilch send")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case <-fc(nilch, 8): case <-fc(nilch, 8):
panic("nilch recv") panic("nilch recv")
〈.end〉 {{end}}
} }
〈.end〉 {{end}}
x = <-c x = <-c
if x != n { if x != n {
die(x) die(x)
...@@ -366,49 +365,49 @@ var sendOrder = parse(` ...@@ -366,49 +365,49 @@ var sendOrder = parse(`
n++ n++
`) `)
var nonblock = parse(` var nonblock = parse("nonblock", `
x = n x = n
〈# Test various combinations of non-blocking operations.〉 {{/* Test various combinations of non-blocking operations. */}}
〈# Receive assignments must not edit or even attempt to compute the address of the lhs.〉 {{/* Receive assignments must not edit or even attempt to compute the address of the lhs. */}}
select { select {
〈.section MaybeDefault〉 {{with .MaybeDefault}}
default: default:
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case dummy <- 1: case dummy <- 1:
panic("dummy <- 1") panic("dummy <- 1")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case nilch <- 1: case nilch <- 1:
panic("nilch <- 1") panic("nilch <- 1")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case <-dummy: case <-dummy:
panic("<-dummy") panic("<-dummy")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case x = <-dummy: case x = <-dummy:
panic("<-dummy x") panic("<-dummy x")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case **(**int)(nil) = <-dummy: case **(**int)(nil) = <-dummy:
panic("<-dummy (and didn't crash saving result!)") panic("<-dummy (and didn't crash saving result!)")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case <-nilch: case <-nilch:
panic("<-nilch") panic("<-nilch")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case x = <-nilch: case x = <-nilch:
panic("<-nilch x") panic("<-nilch x")
〈.end〉 {{end}}
〈.section Maybe〉 {{with .Maybe}}
case **(**int)(nil) = <-nilch: case **(**int)(nil) = <-nilch:
panic("<-nilch (and didn't crash saving result!)") panic("<-nilch (and didn't crash saving result!)")
〈.end〉 {{end}}
〈.section MustDefault〉 {{with .MustDefault}}
default: default:
〈.end〉 {{end}}
} }
if x != n { if x != n {
die(x) die(x)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment