Skip to content

Commit

Permalink
Allows URL in tag
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
sanpii committed Mar 28, 2018
1 parent ba7a3dc commit 89ae258
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
image: "rust:latest"

lint:fmt:
before_script:
- rustup component add rustfmt-preview
script:
- cargo fmt
- test $(git ls-files --modified | wc -l) -eq 0 || (echo 'You have introduced some unformated code:'; git ls-files --modified | sed 's/^/* /'; echo 'Please run `cargo fmt` and amend your PR.'; exit 1)

test:debug:
script: cargo test

Expand Down
10 changes: 7 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn get_keywords(subject: &str) -> (String, BTreeMap<String, String>)
{
lazy_static! {
static ref REGEX: ::regex::Regex =
::regex::Regex::new(r" (?P<key>[^\s]+):(?P<value>[^\s^/]+)").unwrap();
::regex::Regex::new(r" (?P<key>[^\s]+?):(?P<value>[^\s]+)").unwrap();
}

let mut tags = BTreeMap::new();
Expand All @@ -115,9 +115,13 @@ fn get_keywords(subject: &str) -> (String, BTreeMap<String, String>)
let key = caps.name("key").unwrap().as_str();
let value = caps.name("value").unwrap().as_str();

tags.insert(key.to_owned(), value.to_owned());
if value.starts_with('/') {
format!(" {}:{}", key, value)
} else {
tags.insert(key.to_owned(), value.to_owned());

String::new()
String::new()
}
});

(new_subject.into_owned(), tags)
Expand Down
21 changes: 20 additions & 1 deletion tests/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extern crate todo_txt;

use ::std::collections::BTreeMap;

#[test]
fn simple_task()
{
Expand Down Expand Up @@ -195,7 +197,6 @@ fn hashtags()
#[test]
fn keywords()
{
use ::std::collections::BTreeMap;

let mut keywords = BTreeMap::new();
keywords.insert("key1".to_owned(), "2018-01-01".to_owned());
Expand Down Expand Up @@ -238,3 +239,21 @@ fn threshold()

assert_eq!(::todo_txt::parser::task(&line), Ok(task));
}

#[test]
fn url_in_tags()
{
let mut keywords = BTreeMap::new();
keywords.insert("url".to_owned(), "http://example.org".to_owned());

let line = "2018-03-26 test url:http://example.org".to_owned();
let task = ::todo_txt::Task {
subject: "test".to_owned(),
create_date: Some(::todo_txt::Date::from_ymd(2018, 3, 26)),
tags: keywords,

.. Default::default()
};

assert_eq!(::todo_txt::parser::task(&line), Ok(task));
}

0 comments on commit 89ae258

Please sign in to comment.