Macros | Functions
parse_value_string_test.cc File Reference
#include "boost/test/unit_test.hpp"
#include "fhiclcpp/extended_value.h"
#include "fhiclcpp/parse.h"
#include <string>
#include <utility>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   (document test)
 

Functions

 BOOST_AUTO_TEST_CASE (symbols)
 
 BOOST_AUTO_TEST_CASE (numbers)
 
 BOOST_AUTO_TEST_CASE (everything_else)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (document test)

Definition at line 7 of file parse_value_string_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( symbols  )

Definition at line 49 of file parse_value_string_test.cc.

50 {
51  BOOST_CHECK(parse_as("@nil") == nil);
52  BOOST_CHECK(parse_as(" @nil") == nil);
53  BOOST_CHECK(parse_as(" @nil ") == nil);
54  BOOST_CHECK(parse_as(" true or false ") == failed);
55  BOOST_CHECK(parse_as(" TRUE or FALSE ") == failed);
56  BOOST_CHECK(parse_as("infinity") == "+infinity");
57  BOOST_CHECK(parse_as(" -infinity") == "-infinity");
58  BOOST_CHECK(parse_as("+ infinity") == failed);
59  BOOST_CHECK(parse_as("nil_") == dquoted("nil_"));
60 }
std::string dquoted(std::string const &s)
BOOST_AUTO_TEST_CASE ( numbers  )

Definition at line 62 of file parse_value_string_test.cc.

63 {
64  BOOST_CHECK(parse_as("0") == "0");
65  BOOST_CHECK(parse_as("000") == "0");
66  BOOST_CHECK(parse_as("123456") == "123456");
67  BOOST_CHECK(parse_as("1234567") == "1.234567e6");
68  BOOST_CHECK(parse_as("0.0") == "0");
69  BOOST_CHECK(parse_as("0.") == "0");
70 
71  BOOST_CHECK(parse_as("+0") == "0");
72  BOOST_CHECK(parse_as("+000") == "0");
73  BOOST_CHECK(parse_as("+123456") == "123456");
74  BOOST_CHECK(parse_as("+1234567") == "1.234567e6");
75  BOOST_CHECK(parse_as("-0") == "0");
76  BOOST_CHECK(parse_as("-000") == "0");
77  BOOST_CHECK(parse_as("-123456") == "-123456");
78  BOOST_CHECK(parse_as("-1234567") == "-1.234567e6");
79  BOOST_CHECK(parse_as("1.23e-4") == "1.23e-4");
80 
81  BOOST_CHECK(parse_as("+0.0E0") == "0");
82  BOOST_CHECK(parse_as("+00.") == "0");
83  BOOST_CHECK(parse_as("-0e99") == "0");
84  BOOST_CHECK(parse_as("-.00") == "0");
85  BOOST_CHECK(parse_as("+123456e0") == "123456");
86  BOOST_CHECK(parse_as("+1234567e-0") == "1.234567e6");
87 }
BOOST_AUTO_TEST_CASE ( everything_else  )

Definition at line 89 of file parse_value_string_test.cc.

90 {
91  BOOST_CHECK(parse_as("Hello") == dquoted("Hello"));
92  BOOST_CHECK(parse_as("_123") == dquoted("_123"));
93  BOOST_CHECK(parse_as("_123Aa_") == dquoted("_123Aa_"));
94  BOOST_CHECK(parse_as("X...") == failed);
95  BOOST_CHECK(parse_as("3a4B5c") == dquoted("3a4B5c"));
96  BOOST_CHECK(parse_as("0123Aa_") == dquoted("0123Aa_"));
97  BOOST_CHECK(parse_as("9...") == failed);
98  BOOST_CHECK(parse_as("nil") == dquoted("nil"));
99  BOOST_CHECK(parse_as(R"($\d+^)") == failed);
100 
101  BOOST_CHECK(parse_as(" ( 1 , 2.3 ) ") == "(1,2.3)");
102  BOOST_CHECK(parse_as(" ( infinity , -infinity ) ") ==
103  "(+infinity,-infinity)");
104  BOOST_CHECK(parse_as(dquoted("Hi, there!")) == dquoted("Hi, there!"));
105  BOOST_CHECK(parse_as(dquoted("\\t\\n")) == dquoted("\\t\\n"));
106  BOOST_CHECK(parse_as(squoted("Hi, there!")) == dquoted("Hi, there!"));
107  BOOST_CHECK(parse_as(squoted("\\t\\n")) == dquoted("\\\\t\\\\n"));
108  BOOST_CHECK(parse_as("infinityx") == dquoted("infinityx"));
109  BOOST_CHECK(parse_as(dquoted("Hi, \\\"Tom\\\"")) ==
110  dquoted("Hi, \\\"Tom\\\""));
111  BOOST_CHECK(parse_as(dquoted("@Nil")) == dquoted("@Nil"));
112 
113  BOOST_CHECK(parse_as(" [1,2.3] ") == "[1,2.3]");
114  BOOST_CHECK(parse_as(" [ 1 , 2.3 ] ") == "[1,2.3]");
115  BOOST_CHECK(parse_as(" [hello,there] ") ==
116  "[" + dquoted("hello") + "," + dquoted("there") + "]");
117  BOOST_CHECK(parse_as("[ hello,\nthere\t] ") ==
118  "[" + dquoted("hello") + "," + dquoted("there") + "]");
119  BOOST_CHECK(parse_as(" [ ] ") == "[]");
120 
121  BOOST_CHECK(parse_as("{ }") == "{}");
122  BOOST_CHECK(parse_as("{a : 1.2 }") == "{a:1.2}");
123  BOOST_CHECK(parse_as("{a : 1.2 b: hello}") ==
124  "{a:1.2 b:" + dquoted("hello") + "}");
125  BOOST_CHECK(parse_as("{a : 3 b: 7 a: @erase}") == "{b:7}");
126 }
std::string dquoted(std::string const &s)
std::string squoted(std::string const &s)