aboutsummaryrefslogtreecommitdiff
path: root/tests/next-word/driver.cxx
blob: 4ebe1a5234a89194e13bdd07008e7bb3a292dc04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// file      : tests/next-word/driver.cxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#include <vector>
#include <string>
//#include <iostream>

#include <libbutl/utility.hxx>

#undef NDEBUG
#include <cassert>

using namespace std;
using namespace butl;

using strings = vector<string>;

static strings
parse_lines (const string& s)
{
  strings r;
  for (size_t b (0), e (0), m (0), n (s.size ());
       next_word (s, n, b, e, m, '\n', '\r'), b != n; )
  {
    //cerr << "'" << string (s, b, e - b) << "'" << endl;
    r.push_back (string (s, b, e - b));
  }
  return r;
}

int
main ()
{
  assert ((parse_lines("") == strings {}));
  assert ((parse_lines("a") == strings {"a"}));
  assert ((parse_lines("\n") == strings {"", ""}));
  assert ((parse_lines("\n\n") == strings {"", "", ""}));
  assert ((parse_lines("\n\n\n") == strings {"", "", "", ""}));
  assert ((parse_lines("\na") == strings {"", "a"}));
  assert ((parse_lines("\n\na") == strings {"", "", "a"}));
  assert ((parse_lines("a\n") == strings {"a", ""}));
  assert ((parse_lines("a\n\n") == strings {"a", "", ""}));
  assert ((parse_lines("a\nb") == strings {"a", "b"}));
  assert ((parse_lines("a\n\nb") == strings {"a", "", "b"}));
  assert ((parse_lines("\na\nb\n") == strings {"", "a", "b", ""}));
}