File: test_prefix_chars.cpp

package info (click to toggle)
libargparse 3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 896 kB
  • sloc: cpp: 11,319; python: 8; makefile: 4; sh: 3
file content (45 lines) | stat: -rw-r--r-- 1,447 bytes parent folder | download | duplicates (5)
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
#ifdef WITH_MODULE
import argparse;
#else
#include <argparse/argparse.hpp>
#endif
#include <cmath>
#include <doctest.hpp>

using doctest::test_suite;

TEST_CASE("Parse with custom prefix chars" * test_suite("prefix_chars")) {
  argparse::ArgumentParser program("test");
  program.set_prefix_chars("-+");
  program.add_argument("+f");
  program.add_argument("++bar");
  program.parse_args({"test", "+f", "X", "++bar", "Y"});
  REQUIRE(program.get("+f") == "X");
  REQUIRE(program.get("++bar") == "Y");
}

TEST_CASE("Parse with custom Windows-style prefix chars" *
          test_suite("prefix_chars")) {
  argparse::ArgumentParser program("dir");
  program.set_prefix_chars("/");
  program.add_argument("/A").nargs(1);
  program.add_argument("/B").flag();
  program.add_argument("/C").flag();
  program.parse_args({"dir", "/A", "D", "/B", "/C"});
  REQUIRE(program.get("/A") == "D");
  REQUIRE(program.get<bool>("/B") == true);
}

TEST_CASE("Parse with custom Windows-style prefix chars and assign chars" *
          test_suite("prefix_chars")) {
  argparse::ArgumentParser program("dir");
  program.set_prefix_chars("/");
  program.set_assign_chars(":=");
  program.add_argument("/A").nargs(1);
  program.add_argument("/B").nargs(1);
  program.add_argument("/C").flag();
  program.parse_args({"dir", "/A:D", "/B=Boo", "/C"});
  REQUIRE(program.get("/A") == "D");
  REQUIRE(program.get("/B") == "Boo");
  REQUIRE(program.get<bool>("/C") == true);
}