From 0be4bc46d10e8ee46c8ffabf4551915bf12b1611 Mon Sep 17 00:00:00 2001 From: "s.kamardin" Date: Tue, 12 Jan 2016 20:49:12 +0300 Subject: [PATCH] graphviz try --- glob_test.go | 8 ++++---- match/btree.go | 19 ++++++++++++++++++- match/match.go | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/glob_test.go b/glob_test.go index 1228a2b..df8e0ab 100644 --- a/glob_test.go +++ b/glob_test.go @@ -41,10 +41,10 @@ func TestCompilePattern(t *testing.T) { sep string exp match.Matcher }{ - // { - // pattern: "{*,def,abc[a-z]*}ghi", - // exp: match.Raw{"t"}, - // }, + { + pattern: "a?*", + exp: match.Raw{"t"}, + }, } { glob, err := Compile(test.pattern, test.sep) if err != nil { diff --git a/match/btree.go b/match/btree.go index 64d3420..efa6ebc 100644 --- a/match/btree.go +++ b/match/btree.go @@ -112,6 +112,23 @@ func (self BTree) Match(s string) bool { return false } +const tpl = ` +"%p"[label="%s"] +"%p"[label="%s"] +"%p"[label="%s"] +"%p"->"%p" +"%p"->"%p" +` + func (self BTree) String() string { - return fmt.Sprintf("[btree:%s<-%s->%s]", self.Left, self.Value, self.Right) + // return fmt.Sprintf("[btree:%s<-%s->%s]", self.Left, self.Value, self.Right) + + l, r := "nil", "nil" + if self.Left != nil { + l = self.Left.String() + } + if self.Right != nil { + r = self.Right.String() + } + return fmt.Sprintf(tpl, &self, self.Value, &l, l, &r, r, &self, &l, &self, &r) } diff --git a/match/match.go b/match/match.go index d685e5f..b22bc51 100644 --- a/match/match.go +++ b/match/match.go @@ -31,6 +31,7 @@ type Matcher interface { Match(string) bool Index(string) (int, []int) Len() int + String() string } type Matchers []Matcher