diff options
| author | Quey-Liang Kao <s101062801@m101.nthu.edu.tw> | 2017-01-26 08:47:54 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-26 08:47:54 -0600 |
| commit | 4ca186caf6b6261c785028f7634b3c4eebd45578 (patch) | |
| tree | 5f7beaed61bd161a2d3b593c7f9136bf18fa889c | |
| parent | bfd33a9904daac273ff2b708d02c738be276b8c7 (diff) | |
| parent | 50d0119567d2dcae7729bf4e7a841702ba9171d0 (diff) | |
Merge pull request #30 from NonerKao/master
Support UTF-8 strings as contexts and projects
| -rw-r--r-- | todolist/formatter.go | 4 | ||||
| -rw-r--r-- | todolist/parser.go | 11 | ||||
| -rw-r--r-- | todolist/parser_test.go | 11 |
3 files changed, 16 insertions, 10 deletions
diff --git a/todolist/formatter.go b/todolist/formatter.go index db4aa4b..43d9b1e 100644 --- a/todolist/formatter.go +++ b/todolist/formatter.go @@ -103,8 +103,8 @@ func (f *Formatter) formatSubject(subject string) string { magenta := color.New(color.FgMagenta).SprintFunc() splitted := strings.Split(subject, " ") - projectRegex, _ := regexp.Compile(`\+\w+`) - contextRegex, _ := regexp.Compile(`\@\w+`) + projectRegex, _ := regexp.Compile(`\+[\p{L}\d_]+`) + contextRegex, _ := regexp.Compile(`\@[\p{L}\d_]+`) coloredWords := []string{} diff --git a/todolist/parser.go b/todolist/parser.go index 3ad3aae..6cf1967 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -40,23 +40,24 @@ func (p *Parser) Subject(input string) string { } func (p *Parser) ExpandProject(input string) string { - r, _ := regexp.Compile(`(ex|expand) +\d+ +\+\w+[^:]`) - newProject := r.FindString(input) - if len(newProject) == 0 { + r, _ := regexp.Compile(`(ex|expand) +\d+ +\+[\p{L}\d_]+:`) + pattern := r.FindString(input) + if len(pattern) == 0 { return "" } + newProject := pattern[0 : len(pattern)-1] project := strings.Split(newProject, " ") return project[len(project)-1] } func (p *Parser) Projects(input string) []string { - r, _ := regexp.Compile(`\+\w+`) + r, _ := regexp.Compile(`\+[\p{L}\d_]+`) return p.matchWords(input, r) } func (p *Parser) Contexts(input string) []string { - r, err := regexp.Compile(`\@\w+`) + r, err := regexp.Compile(`\@[\p{L}\d_]+`) if err != nil { fmt.Println("regex error", err) } diff --git a/todolist/parser_test.go b/todolist/parser_test.go index 15307cc..791958c 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -37,13 +37,15 @@ func TestParseExpandProjects(t *testing.T) { assert.Equal("", wrongFormat2) wrongFormat3 := parser.ExpandProject("ex 116 meeting figures, slides, coffee, suger") assert.Equal("", wrongFormat3) + wrongFormat4 := parser.ExpandProject("ex 117 +重要な會議: 図, コーヒー, 砂糖") + assert.Equal("+重要な會議", wrongFormat4) } func TestParseProjects(t *testing.T) { parser := &Parser{} - todo := parser.ParseNewTodo("do this thing +proj1 +proj2 due tomorrow") - if len(todo.Projects) != 2 { - t.Error("Expected Projects length to be 2") + todo := parser.ParseNewTodo("do this thing +proj1 +proj2 +專案3 due tomorrow") + if len(todo.Projects) != 3 { + t.Error("Expected Projects length to be 3") } if todo.Projects[0] != "proj1" { t.Error("todo.Projects[0] should equal 'proj1' but got", todo.Projects[0]) @@ -51,6 +53,9 @@ func TestParseProjects(t *testing.T) { if todo.Projects[1] != "proj2" { t.Error("todo.Projects[1] should equal 'proj2' but got", todo.Projects[1]) } + if todo.Projects[2] != "專案3" { + t.Error("todo.Projects[2] should equal '專案3' but got", todo.Projects[2]) + } } func TestParseContexts(t *testing.T) { |
