///////////////////////////////////////////////////////////////////////////
| 38 | |
| 39 | //////////////////////////////////////////////////////////////////////////////// |
| 40 | int TEST_NAME(int, char**) { |
| 41 | #ifdef PRODUCT_TASKWARRIOR |
| 42 | UnitTest t(1255); |
| 43 | #else |
| 44 | UnitTest t(1235); |
| 45 | #endif |
| 46 | |
| 47 | // Use same Datetime/Duraiton configuration as Context∴:staticInitialization. |
| 48 | Datetime::isoEnabled = true; |
| 49 | Datetime::standaloneDateEnabled = false; |
| 50 | Datetime::standaloneTimeEnabled = false; |
| 51 | Duration::standaloneSecondsEnabled = false; |
| 52 | |
| 53 | std::vector<std::pair<std::string, Lexer::Type>> tokens; |
| 54 | std::string token; |
| 55 | Lexer::Type type; |
| 56 | |
| 57 | // Feed in some attributes and types, so that the Lexer knows what a DOM |
| 58 | // reference is. |
| 59 | Lexer::attributes["due"] = "date"; |
| 60 | Lexer::attributes["tags"] = "string"; |
| 61 | Lexer::attributes["description"] = "string"; |
| 62 | |
| 63 | // static bool Lexer::isBoundary (int, int); |
| 64 | t.ok(Lexer::isBoundary(' ', 'a'), "' ' --> 'a' = isBoundary"); |
| 65 | t.ok(Lexer::isBoundary('a', ' '), "'a' --> ' ' = isBoundary"); |
| 66 | t.ok(Lexer::isBoundary(' ', '+'), "' ' --> '+' = isBoundary"); |
| 67 | t.ok(Lexer::isBoundary(' ', ','), "' ' --> ',' = isBoundary"); |
| 68 | t.notok(Lexer::isBoundary('3', '4'), "'3' --> '4' = isBoundary"); |
| 69 | t.ok(Lexer::isBoundary('(', '('), "'(' --> '(' = isBoundary"); |
| 70 | t.notok(Lexer::isBoundary('r', 'd'), "'r' --> 'd' = isBoundary"); |
| 71 | |
| 72 | // static bool Lexer::wasQuoted (const std::string&); |
| 73 | t.notok(Lexer::wasQuoted(""), "'' --> !wasQuoted"); |
| 74 | t.notok(Lexer::wasQuoted("foo"), "'foo' --> !wasQuoted"); |
| 75 | t.ok(Lexer::wasQuoted("a b"), "'a b' --> wasQuoted"); |
| 76 | t.ok(Lexer::wasQuoted("(a)"), "'(a)' --> wasQuoted"); |
| 77 | |
| 78 | // static bool Lexer::dequote (std::string&, const std::string& quotes = "'\""); |
| 79 | token = "foo"; |
| 80 | Lexer::dequote(token); |
| 81 | t.is(token, "foo", "dequote foo --> foo"); |
| 82 | |
| 83 | token = "'foo'"; |
| 84 | Lexer::dequote(token); |
| 85 | t.is(token, "foo", "dequote 'foo' --> foo"); |
| 86 | |
| 87 | token = "'o\\'clock'"; |
| 88 | Lexer::dequote(token); |
| 89 | t.is(token, "o\\'clock", "dequote 'o\\'clock' --> o\\'clock"); |
| 90 | |
| 91 | token = "abba"; |
| 92 | Lexer::dequote(token, "a"); |
| 93 | t.is(token, "bb", "dequote 'abba' (a) --> bb"); |
| 94 | |
| 95 | // Should result in no tokens. |
| 96 | Lexer l0(""); |
| 97 | t.notok(l0.token(token, type), "'' --> no tokens"); |