60 lines
2 KiB
C++
60 lines
2 KiB
C++
#include "mars/parse/value.h"
|
|
#include "test_main.h"
|
|
|
|
using namespace mars::parse;
|
|
|
|
TEST(classify_ints) {
|
|
CHECK(classify("7") == ScalarKind::Int);
|
|
CHECK(classify("+7") == ScalarKind::Int);
|
|
CHECK(classify("-0") == ScalarKind::Int);
|
|
CHECK(classify("007") == ScalarKind::Int);
|
|
CHECK_EQ(*as_int("-12"), -12);
|
|
CHECK_EQ(*as_int("007"), 7);
|
|
}
|
|
|
|
TEST(classify_floats) {
|
|
CHECK(classify(".5") == ScalarKind::Float);
|
|
CHECK(classify("-.8") == ScalarKind::Float);
|
|
CHECK(classify("7e+8") == ScalarKind::Float);
|
|
CHECK(classify("5.") == ScalarKind::Float);
|
|
CHECK(classify("1.5E-3") == ScalarKind::Float);
|
|
CHECK(classify("3e5") == ScalarKind::Float);
|
|
CHECK(*as_double(".5") == 0.5);
|
|
CHECK(*as_double("7e+8") == 7e8);
|
|
CHECK(*as_double("12") == 12.0); // Int shape is a valid double too
|
|
CHECK(!as_int(".5").has_value()); // but not the other way round
|
|
}
|
|
|
|
TEST(classify_text) {
|
|
CHECK(classify("") == ScalarKind::Text);
|
|
CHECK(classify(".") == ScalarKind::Text);
|
|
CHECK(classify("-") == ScalarKind::Text);
|
|
CHECK(classify("1e") == ScalarKind::Text);
|
|
CHECK(classify("e5") == ScalarKind::Text);
|
|
CHECK(classify("1.2.3") == ScalarKind::Text);
|
|
CHECK(classify("0x10") == ScalarKind::Text);
|
|
CHECK(classify("12abc") == ScalarKind::Text);
|
|
CHECK(classify("@WEAPON_X") == ScalarKind::Text);
|
|
CHECK(classify("inf") == ScalarKind::Text);
|
|
CHECK(classify("nan") == ScalarKind::Text);
|
|
CHECK(!as_double("abc").has_value());
|
|
}
|
|
|
|
TEST(classify_bools) {
|
|
CHECK(classify("true") == ScalarKind::Bool);
|
|
CHECK(classify("TRUE") == ScalarKind::Bool);
|
|
CHECK(classify("False") == ScalarKind::Bool);
|
|
CHECK(*as_bool("FALSE") == false);
|
|
CHECK(!as_bool("yes").has_value());
|
|
}
|
|
|
|
TEST(int_overflow_is_rejected) {
|
|
CHECK(!as_int("99999999999999999999").has_value());
|
|
}
|
|
|
|
TEST(iequals_is_ascii_only) {
|
|
CHECK(iequals("Requires", "REQUIRES"));
|
|
CHECK(!iequals("a", "ab"));
|
|
CHECK(iequals("\xe9", "\xe9"));
|
|
CHECK(!iequals("\xe9", "\xc9")); // cp1252 bytes are not folded
|
|
}
|