Compare commits
2 Commits
5615ab6d89
...
8ca887aa7d
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ca887aa7d | |||
| 4283af1968 |
@@ -65,6 +65,7 @@ func TestDatatypeRejectsAValueItsTypeRejects(t *testing.T) {
|
||||
{"a divisor that can be zero", `{"format":"{calc(a / b)}","a":"{int(1,9)}","b":"{int(0,9)}","datatype":"number"}`, "divides by b, which is not proven nonzero"},
|
||||
{"an overflow", `{"format":"{calc(a * a)}","a":"{digits(200)}","datatype":"number"}`, "is not proven within 1e300"},
|
||||
{"a division in an integer column", `{"format":"{calc(a / b)}","a":"{int(1,9)}","b":"{int(1,9)}","datatype":"integer"}`, "prints a number, not an integer"},
|
||||
{"a composed operand", `{"format":"{calc(n * 2)}","n":"{int(1,99)}.{digits(2)}","datatype":"number"}`, "{seq()}, {digits()} or {calc()}"},
|
||||
} {
|
||||
row := `{"format":"","col":` + c.column + `}`
|
||||
files := map[string]string{"row": row}
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ type builtin struct {
|
||||
// for a builtin that reads none.
|
||||
operands func(args []string) []string
|
||||
// number bounds the number a call prints and names the datatype its text is; nil
|
||||
// for a builtin that prints text.
|
||||
// for a builtin whose text is no number.
|
||||
number func(args []string) (proven, DataType)
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,9 @@ func (p *valueProof) template(t *template) proven {
|
||||
case t.fixed:
|
||||
return literalValue(t.lit)
|
||||
case len(t.ops) != 1:
|
||||
return unproven(fmt.Sprintf("%q is not one value; write one literal or one {int()}, {float()}, {seq()} or {calc()}, or read one", t.format))
|
||||
v := unproven(notOneValue(t.format, "{int()}, {float()}, {seq()} or {calc()}"))
|
||||
v.notNumber = notOneValue(t.format, "{int()}, {float()}, {seq()}, {digits()} or {calc()}")
|
||||
return v
|
||||
}
|
||||
body := t.format[1 : len(t.format)-1]
|
||||
name, args, isFunc := funcCall(body)
|
||||
@@ -227,6 +229,10 @@ func printing(token string, prints DataType, v proven) proven {
|
||||
return v
|
||||
}
|
||||
|
||||
func notOneValue(format, calls string) string {
|
||||
return fmt.Sprintf("%q is not one value; write one literal or one %s, or read one", format, calls)
|
||||
}
|
||||
|
||||
// unproven is a render no datatype and no calc can take, for why.
|
||||
func unproven(why string) proven {
|
||||
v := proven{notNumber: why}
|
||||
|
||||
Reference in New Issue
Block a user