return true;
case "nil":
return false;
+ case "testing.T":
+ s.Write(io.StringBytes("testing.T"));
+ return true;
}
panic("unreachable");
return false;
func TestCustomFormatters(t *testing.T) {
fmap0 := FormatterMap{ "/": formatter };
fmap1 := FormatterMap{ "int": formatter, "blank": formatter, "nil": formatter };
+ fmap2 := FormatterMap{ "testing.T": formatter };
f := parse(t, `int=`, fmap0);
verify(t, f, ``, 1, 2, 3);
f = parse(t, `float=@:nil`, fmap1);
verify(t, f, ``, 0.0, 1.0, 2.0);
+ f = parse(t, `testing "testing"; ptr=*`, fmap2);
+ verify(t, f, `testing.T`, t);
+
// TODO needs more tests
}
func remap(p *parser, name string) string {
i := strings.Index(name, ".");
if i >= 0 {
- packageName := name[0 : i];
- typeName := name[i : len(name)];
+ packageName, suffix := name[0 : i], name[i : len(name)];
// lookup package
if importPath, found := p.packs[packageName]; found {
- name = importPath + "." + typeName;
+ name = importPath + suffix;
} else {
var invalidPos token.Position;
p.Error(invalidPos, "package not declared: " + packageName);