aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/text/template/exec_test.go
AgeCommit message (Collapse)Author
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.
2014-09-03text/template: 0xef is an integer, not a floating-point value.Rob Pike
The discriminator in the execution engine was stupid. Add a test to the parse package too. The problem wasn't there but the particular case ('e' in a hex integer) was not covered. Fixes #8622. LGTM=ruiu R=golang-codereviews, ruiu CC=golang-codereviews https://golang.org/cl/133530043
2014-02-14text/template: don't panic when function call evaluates a nil pointerRob Pike
Catch the error instead and return it to the user. Before this fix, the template package panicked. Now you get: template: bug11:1:14: executing "bug11" at <.PS>: dereference of nil pointer of type *string Extended example at http://play.golang.org/p/uP6pCW3qKT Fixes #7333. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/64150043
2013-09-04text/template: allow eq to take more than two argumentsRob Pike
Based on an old suggestion by rsc, it compares the second and following arguments to the first. Unfortunately the code cannot be as pretty as rsc's original because it doesn't require identical types. R=golang-dev, dsymonds, adg CC=golang-dev https://golang.org/cl/13509046
2013-08-28text/template: allow {{else if ... }} to simplify if chainsRob Pike
The method is simple: the parser just parses {{if A}}a{{else if B}}b{{end}} to the same tree that would be produced by {{if A}}a{{else}}{{if B}}b{{end}}{{end}} Thus no changes are required in text/template itself or in html/template, only in text/template/parse. Fixes #6085 R=golang-dev, adg CC=golang-dev https://golang.org/cl/13327043
2013-08-27text/template: make the escapers for HTML etc. handle pointers correctlyRob Pike
Apply the same rules for argument evaluation and indirection that are used by the regular evaluator. Fixes #5802 R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/13257043
2013-08-21text/template: implement comparison of basic typesRob Pike
Add eq, lt, etc. to allow one to do simple comparisons. It's basic types only (booleans, integers, unsigned integers, floats, complex, string) because that's easy, easy to define, and covers the great majority of useful cases, while leaving open the possibility of a more sweeping definition later. {{if eq .X .Y}}X and Y are equal{{else}}X and Y are unequal{{end}} R=golang-dev, adg CC=golang-dev https://golang.org/cl/13091045
2013-08-13text/template: Make function call builtin handle nil errors correctlyElias Naur
The call builtin unconditionally tries to convert a second return value from a function to the error type. This fails in case nil is returned, effectively making call useless for functions returning two values. This CL adds a nil check for the second return value, and adds a test. Note that for regular function and method calls the nil error case is handled correctly and is verified by a test. R=r CC=golang-dev https://golang.org/cl/12804043
2013-07-31text/template: fix type of ComplexZero in testRob Pike
Was stupidly float64; should be complex128. The tests still pass. Fixes #5649. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12107044
2013-03-27text/template: fix bug in evaluating a chain starting with a function.Rob Pike
R=golang-dev, alberto.garcia.hierro CC=golang-dev https://golang.org/cl/7861046
2013-03-06text/template: improve error reporting for executing an empty templateRob Pike
Fixes #4522. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/7502044
2012-10-07text/template: fix nil crash on TemplatesRob Pike
Fixes #3872. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6612060
2012-10-03text/template: better error messages during execution,Rob Pike
They now show the correct name, the byte offset on the line, and context for the failed evaluation. Before: template: three:7: error calling index: index out of range: 5 After: template: top:7:20: executing "three" at <index "hi" $>: error calling index: index out of range: 5 Here top is the template that was parsed to create the set, and the error appears with the action starting at byte 20 of line 7 of "top", inside the template called "three", evaluating the expression <index "hi" $>. Also fix a bug in index: it didn't work on strings. Ouch. Also fix bug in error for index: was showing type of index not slice. The real previous error was: template: three:7: error calling index: can't index item of type int The html/template package's errors can be improved by building on this; I'll do that in a separate pass. Extends the API for text/template/parse but only by addition of a field and method. The old API still works. Fixes #3188. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/6576058
2012-09-24text/template: allow .Field access to parenthesized expressionsRob Pike
Change the grammar so that field access is a proper operator. This introduces a new node, ChainNode, into the public (but actually internal) API of text/template/parse. For compatibility, we only use the new node type for the specific construct, which was not parseable before. Therefore this should be backward-compatible. Before, .X.Y was a token in the lexer; this CL breaks it out into .Y applied to .X. But for compatibility we mush them back together before delivering. One day we might remove that hack; it's the simple TODO in parse.go/operand. This change also provides grammatical distinction between f and (f) which might permit function values later, but not now. Fixes #3999. R=golang-dev, dsymonds, gri, rsc, mikesamuel CC=golang-dev https://golang.org/cl/6494119
2012-08-24text/template: allow grouping of pipelines using parenthesesRob Pike
Based on work by Russ Cox. From his CL: This is generally useful but especially helpful when trying to use the built-in boolean operators. It lets you write: {{if not (f 1)}} foo {{end}} {{if and (f 1) (g 2)}} bar {{end}} {{if or (f 1) (g 2)}} quux {{end}} instead of {{if f 1 | not}} foo {{end}} {{if f 1}}{{if g 2}} bar {{end}}{{end}} {{$do := 0}}{{if f 1}}{{$do := 1}}{{else if g 2}}{{$do := 1}}{{end}}{{if $do}} quux {{end}} The result can be a bit LISPy but the benefit in expressiveness and readability for such a small change justifies it. I believe no changes are required to html/template. Fixes #3276. R=golang-dev, adg, rogpeppe, minux.ma CC=golang-dev https://golang.org/cl/6482056
2012-08-08text/template: add 'nil' as a keyword in the languageRob Pike
The keyword reprents an untyped nil and is useful for passing nil values to methods and functions. The nil will be promoted to the appropriate type when used; if a type cannot be assigned, an error results. R=rsc, dsymonds CC=golang-dev https://golang.org/cl/6459056
2012-07-23text/template: fix bug in map indexingRob Pike
If the key is not present, return value of the type of the element not the type of the key. Also fix a test that should have caught this case. Fixes #3850. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/6405078
2012-05-22text/template: exec should accept interface value as valid.Ugorji Nwoke
Currently, if you pass some data to a template as an interface (e.g. interface{}) and extract that value that value as a parameter for a function, it fails, saying wrong type. This is because it is only looking at the interface type, not the interface content. This CL uses the underlying content as the parameter to the func. Fixes #3642. R=golang-dev, r, r CC=golang-dev https://golang.org/cl/6218052
2012-04-23text/template: detect unexported fields betterRob Pike
Moves the error detection back into execution, where it used to be, and improves the error message. Rolls back most of 6009048, which broke lower-case keys in maps. If it weren't for maps we could detect this at compile time rather than execution time. Fixes #3542. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/6098051
2012-04-03text/template: pipelined arg was not typecheckedRob Pike
Without this fix, an erroneous template causes a panic; should be caught safely. The bug did not affect correct templates. Fixes #3267. R=golang-dev, dsymonds, rsc CC=golang-dev https://golang.org/cl/5900065
2012-03-14text/template: variables do not take argumentsRob Pike
R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/5821044
2012-03-04text/template: one more test caseRob Pike
Missed a case for variadic functions with too few arguments. The code passes, and with the right error, but might as well record the test case. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5732050
2012-03-03text/template: clean up function valuesRob Pike
The recent addition of automatic function invocation generated some troublesome ambiguities. Restore the previous behavior and compensate by providing a "call" builtin to make it easy to do what the automatic invocation did, but in a clear and explicit manner. Fixes #3140. At least for now. R=golang-dev, dsymonds, r CC=golang-dev https://golang.org/cl/5720065
2012-02-15text/template: evaluate function fieldsRob Pike
Just an oversight they didn't work and easy to address. Fixes #3025. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/5656059
2012-02-14text/template: drop reference to os.EPERM in the testRob Pike
R=golang-dev, gri CC=golang-dev https://golang.org/cl/5654077
2012-01-13template: for range on a map, sort the keys if feasible.Rob Pike
Fixes #2696. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5543055
2011-12-18text/template: fix handing of nil arguments to functionsGustavo Niemeyer
R=golang-dev, r CC=golang-dev https://golang.org/cl/5494070
2011-11-26text/template: rename the method Template.Template to Template.LookupRob Pike
Calling it Template makes it clumsy to embed the type, which html/template depends on. R=golang-dev, gri CC=golang-dev https://golang.org/cl/5432079
2011-11-23text/template: new, simpler APIRob Pike
The Set type is gone. Instead, templates are automatically associated by being parsed together; nested definitions implicitly create associations. Only associated templates can invoke one another. This approach dramatically reduces the breadth of the construction API. For now, html/template is deleted from src/pkg/Makefile, so this can be checked in. Nothing in the tree depends on it. It will be updated next. R=dsymonds, adg, rsc, r, gri, mikesamuel, nigeltao CC=golang-dev https://golang.org/cl/5415060
2011-11-17text/template: refactor set parsingRob Pike
Parse {{define}} blocks during template parsing rather than separately as a set-specific thing. This cleans up set parse significantly, and enables the next step, if we want, to unify the API for templates and sets. Other than an argument change to parse.Parse, which is in effect an internal function and unused by client code, there is no API change and no spec change yet. R=golang-dev, rsc, r CC=golang-dev https://golang.org/cl/5393049
2011-11-04template: format error with pointer receiver.David Symonds
This is a continuation of 982d70c6d5d6. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5348042
2011-11-04template: format errorsRuss Cox
R=golang-dev, r CC=golang-dev https://golang.org/cl/5340043
2011-11-03os,text,unicode: renamingsRob Pike
This is Go 1 package renaming CL #4. This one merely moves the source; the import strings will be changed after the next weekly release. This one moves pieces into os, text, and unicode. exec -> os/exec scanner -> text/scanner tabwriter -> text/tabwriter template -> text/template template/parse -> text/template/parse utf16 -> unicode/utf16 utf8 -> unicode/utf8 This should be the last of the source-rearranging CLs. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5331066